OpenM++ runtime library (libopenm)
openm::ArgReader Struct Reference

arguments reader to get runtime arguments from command line and ini-file. More...

#include <argReader.h>

Public Member Functions

 ArgReader (void)
 initialize empty list of run arguments.
 
 ArgReader (int argc, char **argv, const size_t i_keyArrSize, const char **i_keyArr, const size_t i_shortArrSize=0, const pair< const char *, const char * > *i_shortPairArr=nullptr)
 initialize run arguments from command line and ini-file. More...
 
 ~ArgReader (void) noexcept
 cleanup argument holder resources
 
bool isOptionExist (const char *i_key) const noexcept
 return true if option with this key exist.
 
string strOption (const char *i_key, const string &i_default="") const noexcept
 return string value by key or default value if not found.
 
bool boolOption (const char *i_key) const noexcept
 return boolean value by key or false if not found or value not "yes", "1", "true" (case insensitive).
 
int boolOptionToInt (const char *i_key) const noexcept
 return 1 if key found and value is one of: "yes", "1", "true" or empty value, return 0 if key found and value is one of: "no", "0", "false", return -1 if key not found, return -2 otherwise.
 
int intOption (const char *i_key, int i_default) const noexcept
 return int value by key or default if not found or can not be converted to int.
 
long long longOption (const char *i_key, long long i_default) const noexcept
 return long value by key or default if not found or can not be converted to long.
 
double doubleOption (const char *i_key, double i_default) const noexcept
 return double value by key or default if not found or can not be converted to double.
 
void parseCommandLine (int argc, char **argv, bool i_isThrowUnknown, bool i_isStoreUnknown, const size_t i_keyArrSize, const char **i_keyArr, const size_t i_shortArrSize=0, const pair< const char *, const char * > *i_shortPairArr=nullptr, const size_t i_prefixSize=0, const char **i_prefixArr=nullptr, const size_t i_suffixSize=0, const char **i_suffixArr=nullptr)
 get run options from command line, ie: number of cases. More...
 
void loadIniFile (const char *i_filePath, const size_t i_keyArrSize, const char **i_keyArr, bool i_isStoreUnknown=false, const size_t i_sectionToMergeSize=0, const char **i_sectionToMergeArr=nullptr, const size_t i_multiKeySize=0, const char **i_multiKeyArr=nullptr)
 read ini-file and merge command line arguments. More...
 
void adjustLogSettings (int argc, char **argv)
 adjust log file settings, ie: make default log file path if required.
 

Public Attributes

NoCaseMap args
 arguments as key-value string pairs with case-neutral search
 

Detailed Description

arguments reader to get runtime arguments from command line and ini-file.

Constructor & Destructor Documentation

◆ ArgReader()

ArgReader::ArgReader ( int  argc,
char **  argv,
const size_t  i_keyArrSize,
const char **  i_keyArr,
const size_t  i_shortArrSize = 0,
const pair< const char *, const char * > *  i_shortPairArr = nullptr 
)

initialize run arguments from command line and ini-file.

Parameters
[in]argcnumber of command line arguments
[in]argvarray of command line arguments
[in]i_keyArrSizesize of i_keyArr, must be positive
[in]i_keyArrarray of allowed keys: full key names
[in]i_shortArrSizesize of i_shortPairArr, can be zero
[in]i_shortPairArrarray of short and full key names to remap from short to full name

Member Function Documentation

◆ loadIniFile()

void ArgReader::loadIniFile ( const char *  i_filePath,
const size_t  i_keyArrSize,
const char **  i_keyArr,
bool  i_isStoreUnknown = false,
const size_t  i_sectionToMergeSize = 0,
const char **  i_sectionToMergeArr = nullptr,
const size_t  i_multiKeySize = 0,
const char **  i_multiKeyArr = nullptr 
)

read ini-file and merge command line arguments.

read ini-file and merge with command line arguments.

Parameters
[in]i_filePathpath to ini-file
[in]i_keyArrSizesize of i_keyArr, must be positive
[in]i_keyArrarray of allowed keys: full key names
[in]i_isStoreUnknownif true then store unknown key values
[in]i_sectionToMergeSizenumber of section names to merge
[in]i_sectionToMergeArrif not NULL then merge section from ini-file, ex: "Parameter" or "SubValue"
[in]i_multiKeySizesize of i_multiKeyArr array
[in]i_multiKeyArrarray of keys which can be used in any sections, ex: "EN.RunDescription"

◆ parseCommandLine()

void ArgReader::parseCommandLine ( int  argc,
char **  argv,
bool  i_isThrowUnknown,
bool  i_isStoreUnknown,
const size_t  i_keyArrSize,
const char **  i_keyArr,
const size_t  i_shortArrSize = 0,
const pair< const char *, const char * > *  i_shortPairArr = nullptr,
const size_t  i_prefixSize = 0,
const char **  i_prefixArr = nullptr,
const size_t  i_suffixSize = 0,
const char **  i_suffixArr = nullptr 
)

get run options from command line, ie: number of cases.


Parameters
[in]argcnumber of command line arguments
[in]argvarray of command line arguments
[in]i_isThrowUnknownif true then throw exception when key is unknown (except i_prefixToCopy below)
[in]i_isStoreUnknownif true then store unknown key values (always stored i_prefixToCopy below)
[in]i_keyArrSizesize of i_keyArr, must be positive
[in]i_keyArrarray of allowed keys: full key names
[in]i_shortArrSizesize of i_shortPairArr, can be zero
[in]i_shortPairArrarray of short and full key names to remap from short to full name
[in]i_prefixSizesize of options "prefix." array to be allowed
[in]i_prefixArrallow options started from "prefix." i.e.: "Parameter." or "SubValue."
[in]i_suffixSizesize of options ".suffix" array to be allowed
[in]i_suffixArrallow options ended with ".suffix" i.e.: "EN.RunDescription"

The documentation for this struct was generated from the following files: