PeriDEM 0.3.0
PeriDEM -- Peridynamics-based high-fidelity model for granular media
Loading...
Searching...
No Matches
util::io::InputParser Class Reference

Input command line argument parser. More...

#include <inputParser.h>

Collaboration diagram for util::io::InputParser:

Public Member Functions

 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.
 

Private Attributes

std::vector< std::string > tokens
 Tokens.
 

Detailed Description

Input command line argument parser.

source - https://stackoverflow.com/a/868894

Author
iain

Definition at line 28 of file inputParser.h.

Constructor & Destructor Documentation

◆ InputParser()

util::io::InputParser::InputParser ( int &  argc,
char **  argv 
)
inline

Constructor.

Parameters
argcNumber of arguments
argvStrings

Definition at line 35 of file inputParser.h.

35 {
36 for (int i = 1; i < argc; ++i)
37 this->tokens.push_back(std::string(argv[i]));
38 }
std::vector< std::string > tokens
Tokens.
Definition inputParser.h:66

References tokens.

Member Function Documentation

◆ cmdOptionExists()

bool util::io::InputParser::cmdOptionExists ( const std::string &  option) const
inline

Check if argument exists.

Parameters
optionArgument name/key
Returns
bool True if argument exists

Definition at line 60 of file inputParser.h.

60 {
61 return std::find(this->tokens.begin(), this->tokens.end(), option) != this->tokens.end();
62 }

References tokens.

Referenced by anonymous_namespace{main.cpp}::buildInputJson(), and main().

Here is the caller graph for this function:

◆ getCmdOption()

const std::string & util::io::InputParser::getCmdOption ( const std::string &  option) const
inline

Get value of argument specified by key.

Parameters
optionArgument name/key
Returns
string Value of argument

Definition at line 45 of file inputParser.h.

45 {
46 std::vector<std::string>::const_iterator itr;
47 itr = std::find(this->tokens.begin(), this->tokens.end(), option);
48 if (itr != this->tokens.end() && ++itr != this->tokens.end())
49 return *itr;
50
51 static const std::string empty_string("");
52 return empty_string;
53 }

References tokens.

Referenced by anonymous_namespace{main.cpp}::buildInputJson(), and main().

Here is the caller graph for this function:

Field Documentation

◆ tokens

std::vector<std::string> util::io::InputParser::tokens
private

Tokens.

Definition at line 66 of file inputParser.h.

Referenced by cmdOptionExists(), getCmdOption(), and InputParser().


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