PeriDEM 0.2.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 <io.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 355 of file io.h.

Constructor & Destructor Documentation

◆ InputParser()

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

Constructor.

Parameters
argcNumber of arguments
argvStrings

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 }
std::vector< std::string > tokens
Tokens.
Definition io.h:393

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 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().

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 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().

Here is the caller graph for this function:

Field Documentation

◆ tokens

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

Tokens.

Definition at line 393 of file io.h.

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


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