libpnicore
Data Structures | Functions
Configuration classes

Data Structures

class  pni::core::cli_args
 class managing CLI options More...
 
class  pni::core::config_argument< T >
 class describing a program argument More...
 
class  pni::core::config_option< T >
 class describing a program option More...
 
class  pni::core::configuration
 configuration class More...
 

Functions

std::ostream & pni::core::operator<< (std::ostream &ostr, const cli_args &args)
 cli_args output operator More...
 
std::vector< string > pni::core::cliargs2vector (int argc, char **argv)
 store cli options in vector More...
 
std::vector< string > pni::core::parse (configuration &c, const std::vector< string > &args, bool unregistered=false)
 read configuration from vector More...
 
void pni::core::parse (configuration &c, const string &fname)
 read config from a file More...
 

Detailed Description

Utility classes for program configuration.

Function Documentation

std::vector<string> pni::core::cliargs2vector ( int  argc,
char **  argv 
)

This function stores CLI options and arguments in a vector.

Parameters
argcnumber of arguments
argvargument values
Returns
vector with arguments and options
std::ostream& pni::core::operator<< ( std::ostream &  ostr,
const cli_args &  args 
)

Write an instance of cli_args to an output stream.

Parameters
ostrreference to output stream
argsreference to arguments
Returns
reference to output stream
std::vector<string> pni::core::parse ( configuration &  c,
const std::vector< string > &  args,
bool  unregistered = false 
)

This function parses CLI options an arguments from a vector. Unlike the original pointer approach the vector must not contain the program name (usually passed as the first argument to a program). A utilty function can be used to convert the defautl CLI argument pointer to a vector

int main(int argc,char **argv)
{
......
std::vector<string> args = cliargs2vector(argc,argv);
configuration config;
......
parse(config,args);
......
}

!

Parameters
creference to the configuration to be parsed
argscommand line arguments in a vector
unregisteredflag to allow unregistered options
Returns
a vector with uncrecognized options
void pni::core::parse ( configuration &  c,
const string &  fname 
)

Function to read configuration from a configuration file.

Parameters
creference to the configuration object
fnamename of the configuration file