OpenLB 1.7
Loading...
Searching...
No Matches
Public Member Functions | List of all members
olb::CLIreader Class Reference

Very simple CLI argument parser. More...

#include <cliReader.h>

+ Collaboration diagram for olb::CLIreader:

Public Member Functions

 CLIreader (int &argc, char **argv)
 
bool contains (const std::string &name) const
 Returns true iff name is specified.
 
std::string operator[] (const std::string &name) const
 Returns value of token after name (i.e. by convention the value assigned to name)
 
template<typename TYPE >
TYPE getValueOrFallback (const std::string &name, TYPE fallback) const
 Return value of name as TYPE or fallback if not provided.
 

Detailed Description

Very simple CLI argument parser.

Definition at line 34 of file cliReader.h.

Constructor & Destructor Documentation

◆ CLIreader()

olb::CLIreader::CLIreader ( int & argc,
char ** argv )
inline

Definition at line 39 of file cliReader.h.

39 {
40 for (int i=1; i < argc; ++i) {
41 _tokens.emplace_back(argv[i]);
42 }
43 }

Member Function Documentation

◆ contains()

bool olb::CLIreader::contains ( const std::string & name) const
inline

Returns true iff name is specified.

Definition at line 46 of file cliReader.h.

46 {
47 return std::find(_tokens.begin(), _tokens.end(), name) != _tokens.end();
48 }
+ Here is the caller graph for this function:

◆ getValueOrFallback()

template<typename TYPE >
TYPE olb::CLIreader::getValueOrFallback ( const std::string & name,
TYPE fallback ) const
inline

Return value of name as TYPE or fallback if not provided.

Definition at line 62 of file cliReader.h.

62 {
63 if (contains(name)) {
64 const std::string str = operator[](name);
65 TYPE value{};
66 std::from_chars(str.data(), str.data() + str.size(), value);
67 return value;
68 } else {
69 return fallback;
70 }
71 }
std::string operator[](const std::string &name) const
Returns value of token after name (i.e. by convention the value assigned to name)
Definition cliReader.h:51
bool contains(const std::string &name) const
Returns true iff name is specified.
Definition cliReader.h:46
typename std::integral_constant< TYPE, VALUE >::type value
Identity type to wrap non-type template arguments.
Definition meta.h:96

References contains(), and operator[]().

+ Here is the call graph for this function:

◆ operator[]()

std::string olb::CLIreader::operator[] ( const std::string & name) const
inline

Returns value of token after name (i.e. by convention the value assigned to name)

Definition at line 51 of file cliReader.h.

51 {
52 auto iter = std::find(_tokens.begin(), _tokens.end(), name);
53 if (iter != _tokens.end() && ++iter != _tokens.end()){
54 return *iter;
55 } else {
56 return std::string{};
57 }
58 }
+ Here is the caller graph for this function:

The documentation for this class was generated from the following file: