AceSmartSoft API Documentation
Public Member Functions | List of all members
SmartACE::SmartIniParameter Class Reference

Ini-parameter management. More...

#include <smartIniParameter.hh>

Public Member Functions

 SmartIniParameter ()
 Constructor. More...
 
virtual ~SmartIniParameter ()
 Destructor. More...
 
void addEntry (std::string prefix, std::string name, const std::string &value)
 Appends an entry to the ini-parameter list. More...
 
void addCommandLineArgs (const int &argc, char *const *argv, const std::string &default_prefix="component", const int &skip_args=1)
 Appends command line arguments to the ini-parameter list. More...
 
void addEnv (const std::string &prefix, const std::string &env)
 Appends environment variable to the ini-parameter list. More...
 
void addFile (const std::string &filename)
 Appends the contents of a ini-parameter file to the ini-parameter list. More...
 
bool searchFile (const std::string &filename, std::ifstream &filestream)
 This method searches for the file using different search strategies and if found returns the filestream. More...
 
bool tryAddFileFromArgs (const int &argc, char *const *argv, const std::string &long_opt="filename", const char &short_opt=-1)
 This is a wrapper for addFile(argc,argv,argname,false) without throwing an exception if no argument given. More...
 
void addFile (int argc, char *const *argv, const std::string &argname, bool allow_stdin=true)
 Append the contents of an ini-parameter file to the ini-parameter list. More...
 
void addFile (std::istream &is)
 Append the contents of an ini-parameter file to the ini-parameter list. More...
 
void print (void)
 print all currently known parameters with their values More...
 
bool checkIfParameterExists (const std::string &prefix, const std::string &parameter)
 Search for an optional parameter in ini-file. More...
 
std::map< std::string, std::string > getAllParametersFromGroup (const std::string &prefix)
 Get all parameter pairs (key,value) for a given parameter group. More...
 
std::map< std::string, std::list< std::string > > getAllParameterListsFromGroup (const std::string &prefix)
 
double getDouble (std::string prefix, std::string parameter) const
 Retrieve double casted value of ini-parameter name. More...
 
std::list< double > getDoubleList (std::string prefix, std::string parameter) const
 
template<class Float >
bool getDouble (const std::string &prefix, const std::string &parameter, Float &d) const
 Retrieve double casted value of ini-parameter name. More...
 
template<class Float >
bool getDoubleList (const std::string &prefix, const std::string &parameter, std::list< Float > &d) const
 
int getInteger (std::string prefix, std::string parameter) const
 Retrieve int casted value of ini-parameter name. More...
 
std::list< int > getIntegerList (std::string prefix, std::string parameter) const
 
template<class Integer >
bool getInteger (const std::string &prefix, const std::string &parameter, Integer &i) const
 Retrieve int casted value of ini-parameter name. More...
 
template<class Integer >
bool getIntegerList (const std::string &prefix, const std::string &parameter, std::list< Integer > &i) const
 
bool getBoolean (std::string prefix, std::string parameter) const
 Retrieve truth value of ini-parameter name. More...
 
std::list< bool > getBooleanList (std::string prefix, std::string parameter) const
 
bool getBoolean (const std::string &prefix, const std::string &parameter, bool &b) const
 Retrieve truth value of ini-parameter name. More...
 
bool getBooleanList (const std::string &prefix, const std::string &parameter, std::list< bool > &b) const
 
std::string getString (std::string prefix, std::string parameter) const
 Retrieve string value of ini-parameter name. More...
 
std::list< std::string > getStringList (std::string prefix, std::string parameter) const
 
bool getString (const std::string &prefix, const std::string &parameter, std::string &s) const
 Retrieve string value of ini-parameter name. More...
 
bool getStringList (const std::string &prefix, const std::string &parameter, std::list< std::string > &s) const
 
std::map< std::pair< std::string, std::string >, std::list< std::string > >::const_iterator begin ()
 
std::map< std::pair< std::string, std::string >, std::list< std::string > >::const_iterator end ()
 

Detailed Description

Ini-parameter management.

Supports storage of IniParameters in separate ini-parameter files. Ini-parameter files can be read by this class which then provides simple access to all kinds of ini-parameters. Ini-parameters can also be extracted from environment variables or be defined by command line arguments.

The prefix is used to group ini-parameters and can also be set to the empty string. An ini-parameter therefore is always referenced by its prefix and its name.

Prefix and ini-parameter name are case insensitive !

Demonstrated in seventh example

Constructor & Destructor Documentation

◆ SmartIniParameter()

SmartACE::SmartIniParameter::SmartIniParameter ( )

Constructor.

◆ ~SmartIniParameter()

virtual SmartACE::SmartIniParameter::~SmartIniParameter ( )
virtual

Destructor.

Member Function Documentation

◆ addCommandLineArgs()

void SmartACE::SmartIniParameter::addCommandLineArgs ( const int &  argc,
char *const *  argv,
const std::string &  default_prefix = "component",
const int &  skip_args = 1 
)

Appends command line arguments to the ini-parameter list.

If same entry already exists overwrite it with the new value. Format of command line ini-parameter: -parameter=value

◆ addEntry()

void SmartACE::SmartIniParameter::addEntry ( std::string  prefix,
std::string  name,
const std::string &  value 
)

Appends an entry to the ini-parameter list.

If same entry already exists overwrite it with the new value.

◆ addEnv()

void SmartACE::SmartIniParameter::addEnv ( const std::string &  prefix,
const std::string &  env 
)

Appends environment variable to the ini-parameter list.

Parameters
prefixprefix of ini-parameter name (prefix.name)
envis the name of the environment variable.

If same entry already exists overwrite it with the new value. Throw exception if environment variable unknown.

◆ addFile() [1/3]

void SmartACE::SmartIniParameter::addFile ( const std::string &  filename)

Appends the contents of a ini-parameter file to the ini-parameter list.

Entries which already exist are replaced by the new values. Throw exception if something went wrong (file does not exist or contains syntax errors).

Looks first in the current directory and then in $SMART_ROOT/etc

The file extension normally used for ini-parameter files is "ini". There is no maximum length per line, newlines may be escaped to concatenate successive lines. The syntax is as follows:

--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--
[smartsoft]
# -------------------------------------
# laser server parameter
# -------------------------------------
# laser device
[laser]
type SICK LMS200
use Yes
baudrate 57600 # 1200/9600/19200/38400/57600
parity NONE
data 8
device /dev/cua2 # /dev/cur2 /dev/cua2
interval 0.167 # poll interval in seconds
--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--

ALL ENTRIES ARE CASE INSENSITIVE !

The first line always contains the identification which is "[smartsoft]". For compatibility reasons we also accept "[bParamFile]" and "[smartParamFile]".

The first string in the line is the parameter name. Everything else following is the value excluding any comment. Comments are invoked by a "#" and end with the line.

Square brackets invoke the next group. If ini-parameters are defined before any group is named, then their group name is simply "" (empty group name).

Truth values can be defined in many different formats:

  • true : yes | y | true | t | + | 1 | on
  • false : no | n | false | f | - | 0 | off

◆ addFile() [2/3]

void SmartACE::SmartIniParameter::addFile ( int  argc,
char *const *  argv,
const std::string &  argname,
bool  allow_stdin = true 
)

Append the contents of an ini-parameter file to the ini-parameter list.

The name of the ini-parameter file is not directly given, but extracted from the argument list. So you can start multiple instances of the same program each with a different ini-parameter set.

The command line arguments are given by argc and argv and the string argname gives the name of the argument which contains the actual filename.

If allow_stdin is true (default) and the value of argument argname is "stdin", the method will read the configuration data from stdin.

Author
Boris Kluge kluge.nosp@m.@faw.nosp@m..uni-.nosp@m.ulm..nosp@m.de

◆ addFile() [3/3]

void SmartACE::SmartIniParameter::addFile ( std::istream &  is)

Append the contents of an ini-parameter file to the ini-parameter list.

The stream is assumed to be connected to a ini-parameter file.

◆ begin()

std::map<std::pair<std::string,std::string>, std::list<std::string> >::const_iterator SmartACE::SmartIniParameter::begin ( )

return the begin Iterator from our map.

subject to change without notice.

◆ checkIfParameterExists()

bool SmartACE::SmartIniParameter::checkIfParameterExists ( const std::string &  prefix,
const std::string &  parameter 
)

Search for an optional parameter in ini-file.

If the parameter could be found, then "true", otherwise "false", is returned. If parameter is not found, no exception is thrown, which makes it easier to check for existence of an optional parameter in the ini-file.

◆ end()

std::map<std::pair<std::string,std::string>, std::list<std::string> >::const_iterator SmartACE::SmartIniParameter::end ( )

return the end Iterator from our map.

subject to change without notice.

◆ getAllParameterListsFromGroup()

std::map<std::string, std::list<std::string> > SmartACE::SmartIniParameter::getAllParameterListsFromGroup ( const std::string &  prefix)

◆ getAllParametersFromGroup()

std::map<std::string,std::string> SmartACE::SmartIniParameter::getAllParametersFromGroup ( const std::string &  prefix)

Get all parameter pairs (key,value) for a given parameter group.

Iterates through all parameters and returns all (key,value) pairs that match the prefix (parameter group).

◆ getBoolean() [1/2]

bool SmartACE::SmartIniParameter::getBoolean ( std::string  prefix,
std::string  parameter 
) const

Retrieve truth value of ini-parameter name.

throw "IniParameterError" if ini-parameter not known or conversion fails

◆ getBoolean() [2/2]

bool SmartACE::SmartIniParameter::getBoolean ( const std::string &  prefix,
const std::string &  parameter,
bool &  b 
) const

Retrieve truth value of ini-parameter name.

leave b alone and return false, if ini-parameter not known or conversion fails

◆ getBooleanList() [1/2]

std::list<bool> SmartACE::SmartIniParameter::getBooleanList ( std::string  prefix,
std::string  parameter 
) const

◆ getBooleanList() [2/2]

bool SmartACE::SmartIniParameter::getBooleanList ( const std::string &  prefix,
const std::string &  parameter,
std::list< bool > &  b 
) const

◆ getDouble() [1/2]

double SmartACE::SmartIniParameter::getDouble ( std::string  prefix,
std::string  parameter 
) const

Retrieve double casted value of ini-parameter name.

throw "IniParameterError" if ini-parameter not known or conversion fails

◆ getDouble() [2/2]

template<class Float >
bool SmartACE::SmartIniParameter::getDouble ( const std::string &  prefix,
const std::string &  parameter,
Float &  d 
) const
inline

Retrieve double casted value of ini-parameter name.

leave d alone and return false, if ini-parameter not known or conversion fails

◆ getDoubleList() [1/2]

std::list<double> SmartACE::SmartIniParameter::getDoubleList ( std::string  prefix,
std::string  parameter 
) const

◆ getDoubleList() [2/2]

template<class Float >
bool SmartACE::SmartIniParameter::getDoubleList ( const std::string &  prefix,
const std::string &  parameter,
std::list< Float > &  d 
) const
inline

◆ getInteger() [1/2]

int SmartACE::SmartIniParameter::getInteger ( std::string  prefix,
std::string  parameter 
) const

Retrieve int casted value of ini-parameter name.

throw "IniParameterError" if ini-parameter not known or conversion fails

◆ getInteger() [2/2]

template<class Integer >
bool SmartACE::SmartIniParameter::getInteger ( const std::string &  prefix,
const std::string &  parameter,
Integer &  i 
) const
inline

Retrieve int casted value of ini-parameter name.

leave i alone and return false, if ini-parameter not known or conversion fails

◆ getIntegerList() [1/2]

std::list<int> SmartACE::SmartIniParameter::getIntegerList ( std::string  prefix,
std::string  parameter 
) const

◆ getIntegerList() [2/2]

template<class Integer >
bool SmartACE::SmartIniParameter::getIntegerList ( const std::string &  prefix,
const std::string &  parameter,
std::list< Integer > &  i 
) const
inline

◆ getString() [1/2]

std::string SmartACE::SmartIniParameter::getString ( std::string  prefix,
std::string  parameter 
) const

Retrieve string value of ini-parameter name.

throw "IniParameterError" if parameter not known

◆ getString() [2/2]

bool SmartACE::SmartIniParameter::getString ( const std::string &  prefix,
const std::string &  parameter,
std::string &  s 
) const

Retrieve string value of ini-parameter name.

leave s alone and return false if ini-parameter not known

◆ getStringList() [1/2]

std::list<std::string> SmartACE::SmartIniParameter::getStringList ( std::string  prefix,
std::string  parameter 
) const

◆ getStringList() [2/2]

bool SmartACE::SmartIniParameter::getStringList ( const std::string &  prefix,
const std::string &  parameter,
std::list< std::string > &  s 
) const

◆ print()

void SmartACE::SmartIniParameter::print ( void  )

print all currently known parameters with their values

◆ searchFile()

bool SmartACE::SmartIniParameter::searchFile ( const std::string &  filename,
std::ifstream &  filestream 
)

This method searches for the file using different search strategies and if found returns the filestream.

Parameters
filenameThe file name to search for
filestreamThe filestream pointing to the content of the found file
Returns
true if the filename was found
false if the filename was not found (no exception is used here and filestream.open() is false in this case)

◆ tryAddFileFromArgs()

bool SmartACE::SmartIniParameter::tryAddFileFromArgs ( const int &  argc,
char *const *  argv,
const std::string &  long_opt = "filename",
const char &  short_opt = -1 
)

This is a wrapper for addFile(argc,argv,argname,false) without throwing an exception if no argument given.

This method checks whether the argv vector contains the long_opt and/or short_opt parameter. If not found a 'false' is returned without throwing an exception. If found the method addFile(argc,argv,argument_name,false) is called and if this succeeds 'true' is returned.


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