libpnicore
Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | Friends
pni::core::configuration Class Reference

configuration class More...

#include <configuration.hpp>

Public Member Functions

 configuration ()
 default constructor
 
 configuration (const configuration &c)=delete
 copy constructor - deleted
 
 configuration (configuration &&c)
 move constructor
 
 ~configuration ()
 destructor
 
const popts::options_description & visible_options () const
 get visible options More...
 
const popts::options_description & hidden_options () const
 get hidden options More...
 
const
popts::positional_options_description & 
arguments () const
 get arguments More...
 
const popts::variables_map & map () const
 get variables map More...
 
bool has_option (const string &name) const
 check if option is there More...
 
template<typename T >
value (const string &name) const
 return the value of an option More...
 
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 More...
 
template<typename T >
void add_argument (const config_argument< T > &arg)
 add argument More...
 

Protected Member Functions

std::ostream & print (std::ostream &o) const
 print options More...
 

Private Member Functions

template<typename T >
string default_value_string (const T &v)
 get default value string More...
 
template<typename T >
string default_value_string (const std::vector< T > &v)
 get default value string More...
 

Private Attributes

popts::variables_map _vmap
 stores the program options
 
popts::options_description _visible_opts
 options visible in the help
 
popts::options_description _hidden_opts
 options hidden in the help output
 
popts::positional_options_description _oargs
 positional arguments description
 

Friends

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

Detailed Description

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

Member Function Documentation

template<typename T >
void pni::core::configuration::add_argument ( const config_argument< T > &  arg)
inline

Adds an argument to the configuration.

Parameters
argargument
void pni::core::configuration::add_option ( const config_option< bool > &  opt,
bool  visible = true 
)

Overloaded version of the add_option template member for bool variables.

Parameters
optboolean configuration option
visiblevisibility flag
const popts::positional_options_description& pni::core::configuration::arguments ( ) const
inline

Return reference to the arguments of the configuration.

Returns
return positional options description
template<typename T >
string pni::core::configuration::default_value_string ( const T &  v)
inlineprivate

Converts the default value provided by an option to its string representation.

Template Parameters
Tdata type of the default value
Parameters
vdefault value
Returns
string representation of v
template<typename T >
string pni::core::configuration::default_value_string ( const std::vector< T > &  v)
inlineprivate

Overloaded version if the option allows multiple values via a std::pointer. In this case the first element is used as a default value. An exception is thrown wenn the default container is an empty container.

Exceptions
index_errorif the vector is empty
Template Parameters
Telement type of the vector
Parameters
vinstance of the vector
Returns
string representation of the first element
bool pni::core::configuration::has_option ( const string name) const

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

Parameters
namelong name of the option
Returns
true if option exists
const popts::options_description& pni::core::configuration::hidden_options ( ) const
inline
Returns
return hidden options description
const popts::variables_map& pni::core::configuration::map ( ) const
inline

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

Returns
reference to the variables map
std::ostream& pni::core::configuration::print ( std::ostream &  o) const
protected

Append options string representation to an output stream. Only the visible options are appended to the output stream.

Parameters
oreference to the output stream
Returns
reference to output stream
template<typename T >
T pni::core::configuration::value ( const string name) const
inline

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.

Template Parameters
Treturn type of the method
Exceptions
cli_option_errorif option is not present and has no default value
Parameters
namelong name of the option
Returns
value of the option as instance of type T
const popts::options_description& pni::core::configuration::visible_options ( ) const
inline
Returns
return the visible options

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