Input command line argument parser.
More...
#include <io.h>
|
| InputParser (int &argc, char **argv) |
| Constructor.
|
|
const std::string & | getCmdOption (const std::string &option) const |
| Get value of argument specified by key.
|
|
bool | cmdOptionExists (const std::string &option) const |
| Check if argument exists.
|
|
|
std::vector< std::string > | tokens |
| Tokens.
|
|
Input command line argument parser.
source - https://stackoverflow.com/a/868894
- Author
- iain
Definition at line 355 of file io.h.
◆ InputParser()
util::io::InputParser::InputParser |
( |
int & |
argc, |
|
|
char ** |
argv |
|
) |
| |
|
inline |
Constructor.
- Parameters
-
argc | Number of arguments |
argv | Strings |
Definition at line 362 of file io.h.
362 {
363 for (int i = 1; i < argc; ++i)
364 this->
tokens.push_back(std::string(argv[i]));
365 }
References tokens.
◆ cmdOptionExists()
bool util::io::InputParser::cmdOptionExists |
( |
const std::string & |
option | ) |
const |
|
inline |
Check if argument exists.
- Parameters
-
- Returns
- bool True if argument exists
Definition at line 387 of file io.h.
387 {
388 return std::find(this->
tokens.begin(), this->tokens.end(), option) != this->
tokens.end();
389 }
References tokens.
Referenced by main().
◆ getCmdOption()
const std::string & util::io::InputParser::getCmdOption |
( |
const std::string & |
option | ) |
const |
|
inline |
Get value of argument specified by key.
- Parameters
-
- Returns
- string Value of argument
Definition at line 372 of file io.h.
372 {
373 std::vector<std::string>::const_iterator itr;
374 itr = std::find(this->
tokens.begin(), this->tokens.end(), option);
375 if (itr != this->
tokens.end() && ++itr != this->tokens.end())
376 return *itr;
377
378 static const std::string empty_string("");
379 return empty_string;
380 }
References tokens.
Referenced by main().
◆ tokens
std::vector<std::string> util::io::InputParser::tokens |
|
private |
The documentation for this class was generated from the following file:
- /home/user/project/src/util/io.h