Configuration API

cli_args

class cli_args

class managing CLI options

This class is used to hold CLI options in a form convineant for the program_options class. The intention of this class is to act as a exception save container for custom built command line options that are generated from a container of strings. The content of this string is than presented in way that the program options class can parse it.

std::list<std::string> strlist;

......code omitted .....

cli_args args(strlist);
program_config config;

......setup of config is omitted ....

config.parse(args.argc(),const_cast<char**>(args.argv()));
! Instances of cli_args are first class objects and do memory management by themselfe.

Public Functions

template <typename CTYPE>
cli_args(const CTYPE &str_cont)

constructor

~cli_args()

destructor

const char **argv() const

get the argument values

int argc() const

get the number of arguments

config_argument

template <typename T>
class config_argument : public pni::core::config_option<T>

class describing a program argument

Class holds all the information required for a command line arguments. Arguments have at least a long name which can later be used to identify the argument in the program configuration. However, this name never shows up in the help list.

Command line arguments are identified by there position in the total argument list. If this position is -1 then all the values from a current starting position to the end of the argument list belong to this argument.

Template Parameters
  • T: type of the argument

Public Functions

config_argument()

default constructor

config_argument(const string &lname, int pos, T *exref = nullptr)

constructor

Parameters
  • lname: long name of the option
  • pos: position of the argument
  • exref: optional external reference

config_argument(const string &lname, int pos, T default_value, T *exref = nullptr)

constructor

Parameters
  • lname: long name of the option
  • pos: position of the argument
  • default_value: the default value to use for this option
  • exref: external reference

~config_argument()

destructor

int position() const

get short name

config_option

template <typename T>
class config_option

class describing a program option

Class holds all the information required for a command line option. Each command line option has at least a long name. The short name, a single letter, can be left empty. In addition every option is associated with a value the user has to pass. The only exception from this rule are Bool options. Such options are only considered as flags without taking any argument.

Template Parameters
  • T: data type of the option

Subclassed by pni::core::config_argument< T >

Public Functions

config_option()

default constructor

config_option(const string &lname, const string &sname, const string &description, T *exref = nullptr)

constructor

Parameters
  • lname: long name of the option
  • sname: short name (single letter) of the option
  • description: doc string of the option
  • exref: optional external reference

config_option(const string &lname, const string &sname, const string &description, T default_value, T *exref = nullptr)

constructor

Parameters
  • lname: long name of the option
  • sname: short name (single letter) of the option
  • description: doc string of the option
  • default_value: the default value to use for this option
  • exref: external reference

virtual ~config_option()

destructor

string long_name() const

get long name

string short_name() const

get short name

string description() const

get description

T default_value() const

get default value

const T *external_reference() const

get external refernce

bool has_default() const

check if option has a default value

configuration

class configuration

configuration class

This class holds the configuration of a program or library that has been extracted from various sources.

Public Functions

configuration()

default constructor

configuration(const configuration &c)

copy constructor - deleted

configuration(configuration &&c)

move constructor

~configuration()

destructor

const popts::options_description &visible_options() const

get visible options

Return
return the visible options

const popts::options_description &hidden_options() const

get hidden options

Return
return hidden options description

const popts::positional_options_description &arguments() const

get arguments

Return reference to the arguments of the configuration.

Return
return positional options description

const popts::variables_map &map() const

get variables map

Return a const reference to the configuration variables map stored in the configuration class.

Return
reference to the variables map

bool has_option(const string &name) const

check if option is there

Return true if a particular option has been passed by the user. If the option is present true is returned otherwise false.

Return
true if option exists
Parameters
  • name: long name of the option

template <typename T>
T value(const string &name) const

return the value of an option

Template method returning the value of an option as instance of type T. If the option was created with a default value this value will be returned. If the option was created without default value an exception will be thrown.

Return
value of the option as instance of type T
Template Parameters
  • T: return type of the method
Exceptions
Parameters
  • name: long name of the option

template <typename T>
void add_option(const config_option<T> &opt, bool visible = true)

add a program option

void add_option(const config_option<bool> &opt, bool visible = true)

add an boolean option

Overloaded version of the add_option template member for bool variables.

Parameters
  • opt: boolean configuration option
  • visible: visibility flag

template <typename T>
void add_argument(const config_argument<T> &arg)

add argument

Adds an argument to the configuration.

Parameters
  • arg: argument

Friends

PNICORE_EXPORT std::ostream &operator<<(std::ostream &o, const configuration &c)

output operator

Functions

Warning

doxygenfunction: Unable to resolve multiple matches for function “operator<<” with arguments (std::ostream &, const cli_args &) in doxygen xml output for project “pnicore” from directory: /home/jkotan/sources/libpnicore-build/doc/api_doc/xml. Potential matches:

- PNICORE_EXPORT std::ostream &pni::core::operator<<(std::ostream&, const bool_t&)
- PNICORE_EXPORT std::ostream &pni::core::operator<<(std::ostream&, const exception_record&)
- PNICORE_EXPORT std::ostream &pni::core::operator<<(std::ostream&, const none&)
- PNICORE_EXPORT std::ostream &pni::core::operator<<(std::ostream&, const slice&)
- PNICORE_EXPORT std::ostream &pni::core::operator<<(std::ostream&, const type_id_t&)
- std::ostream &pni::core::operator<<(std::ostream&, const array_selection&)
- std::ostream &pni::core::operator<<(std::ostream&, const benchmark_result&)
- std::ostream &pni::core::operator<<(std::ostream&, const cli_args&)
- std::ostream &pni::core::operator<<(std::ostream&, const cli_argument_error&)
- std::ostream &pni::core::operator<<(std::ostream&, const cli_error&)
- std::ostream &pni::core::operator<<(std::ostream&, const cli_help_request&)
- std::ostream &pni::core::operator<<(std::ostream&, const cli_option_error&)
- std::ostream &pni::core::operator<<(std::ostream&, const configuration&)
- std::ostream &pni::core::operator<<(std::ostream&, const exception&)
- std::ostream &pni::core::operator<<(std::ostream&, const file_error&)
- std::ostream &pni::core::operator<<(std::ostream&, const index_error&)
- std::ostream &pni::core::operator<<(std::ostream&, const iterator_error&)
- std::ostream &pni::core::operator<<(std::ostream&, const key_error&)
- std::ostream &pni::core::operator<<(std::ostream&, const memory_allocation_error&)
- std::ostream &pni::core::operator<<(std::ostream&, const memory_not_allocated_error&)
- std::ostream &pni::core::operator<<(std::ostream&, const not_implemented_error&)
- std::ostream &pni::core::operator<<(std::ostream&, const range_error&)
- std::ostream &pni::core::operator<<(std::ostream&, const shape_mismatch_error&)
- std::ostream &pni::core::operator<<(std::ostream&, const size_mismatch_error&)
- std::ostream &pni::core::operator<<(std::ostream&, const type_error&)
- std::ostream &pni::core::operator<<(std::ostream&, const value_error&)
- template <typename ATYPE>
  std::ostream &pni::core::operator<<(std::ostream&, const array_view<ATYPE>&)
- template <typename NTYPE>
  std::ostream &pni::core::operator<<(std::ostream&, const binary_t<NTYPE>&)
- template <typename STORAGE, typename IMAP, typename IPA>
  std::ostream &pni::core::operator<<(std::ostream&, const mdarray<STORAGE, IMAP, IPA>&)
- template <typename T>
  std::ostream &pni::core::operator<<(std::ostream&, const scalar<T>&)
std::vector<string> PNICORE_EXPORT pni::core::cliargs2vector(int argc, char **argv)

store cli options in vector

This function stores CLI options and arguments in a vector.

Return
vector with arguments and options
Parameters
  • argc: number of arguments
  • argv: argument values

Warning

doxygenfunction: Unable to resolve multiple matches for function “pni::core::parse” with arguments (configuration &, const std::vector< string > &, bool) in doxygen xml output for project “pnicore” from directory: /home/jkotan/sources/libpnicore-build/doc/api_doc/xml. Potential matches:

- std::vector<string> PNICORE_EXPORT pni::core::parse(configuration&, const std::vector<string>&, bool)
- void PNICORE_EXPORT pni::core::parse(configuration&, const string&)

Warning

doxygenfunction: Unable to resolve multiple matches for function “pni::core::parse” with arguments (configuration &, const string &) in doxygen xml output for project “pnicore” from directory: /home/jkotan/sources/libpnicore-build/doc/api_doc/xml. Potential matches:

- std::vector<string> PNICORE_EXPORT pni::core::parse(configuration&, const std::vector<string>&, bool)
- void PNICORE_EXPORT pni::core::parse(configuration&, const string&)