DUNE: Uniform Navigational Environment  2019.02.1
DUNE::Parsers::Config Class Reference

Detailed Description

Microsoft Windows INI configuration file parser.

The configuration file format consists of sections, led by a "[section]" header and followed by "option = value" entries, with continuations in the style of RFC 822. Note that leading and trailing whitespaces are removed from values. Character case in "option" identifiers is discarded. Lines beginning with "#" or ";" are ignored and may be used to provide comments.

Public Member Functions

 Config (void)
 
 Config (const char *fname)
 
void parseFile (const char *fname)
 
void set (const std::string &section, const std::string &option, const std::string &value)
 
std::string get (const std::string &section, const std::string &option)
 
void setSection (const std::string &section, const std::map< std::string, std::string > &map)
 
std::map< std::string, std::string > getSection (const std::string &section)
 
template<typename Type >
void get (const std::string &sec, const std::string &opt, const std::string &def, Type &var)
 
template<typename T >
bool getList (const std::string &section, const std::string &option, T *dest, unsigned int size)
 
void writeToFile (const char *file)
 
std::vector< std::string > files (void)
 
std::vector< std::string > sections (void)
 
std::vector< std::string > options (const std::string &section)
 

Friends

DUNE_DLL_SYM std::ostream & operator<< (std::ostream &os, const Config &cfg)
 

Constructor & Destructor Documentation

DUNE::Parsers::Config::Config ( void  )
inline

Default constructor.

References parseFile().

Referenced by files().

DUNE::Parsers::Config::Config ( const char *  fname)

Create the parser and parse a configuration file.

Parameters
fnamename of the configuration file to parse.

References parseFile().

Member Function Documentation

std::vector<std::string> DUNE::Parsers::Config::files ( void  )
inline

Retrieve the file option of the parsed configuration file.

Returns
parsed file option.

References Config(), operator<<, options(), and sections().

template<typename Type >
void DUNE::Parsers::Config::get ( const std::string &  sec,
const std::string &  opt,
const std::string &  def,
Type &  var 
)
inline

Retrieve the value of an option in a given section and perform type conversion.

Parameters
secsection.
optoption.
defdefault value.
vardestination variable.

References DUNE::castLexical(), and DUNE::Utils::String.

template<typename T >
bool DUNE::Parsers::Config::getList ( const std::string &  section,
const std::string &  option,
T *  dest,
unsigned int  size 
)
inline

Retrieve the list of strings separated by commas of an option in a given section, performing type conversion.

Parameters
sectionsection.
optionoption.
destdestination array.
sizeexpected number of strings.
Returns
true if the number of strings is equal to the argument size, false otherwise.

References writeToFile().

std::map<std::string, std::string> DUNE::Parsers::Config::getSection ( const std::string &  section)
inline

Retrieve the option map of a given section.

Parameters
[in]sectionsection name.
Returns
map of <option, value>.

Referenced by DUNE::Tasks::Task::loadConfig().

std::vector< std::string > DUNE::Parsers::Config::options ( const std::string &  section)

Retrieve all the options under the given section.

Parameters
sectionsection of interest.
Returns
list of options under the given section.

Referenced by DUNE::Daemon::Daemon(), files(), and DUNE::Parsers::PlanConfigParser::parseActions().

void DUNE::Parsers::Config::parseFile ( const char *  fname)

Parse a configuration file.

Parameters
fnamename of the configuration file to parse.

References DUNE::System::Error::getLastMessage().

Referenced by Config(), and DUNE::Daemon::Daemon().

std::vector< std::string > DUNE::Parsers::Config::sections ( void  )

Retrieve all the available sections.

Returns
list of all sections.

Referenced by files(), DUNE::Tasks::Manager::Manager(), and DUNE::Parsers::operator<<().

void DUNE::Parsers::Config::set ( const std::string &  section,
const std::string &  option,
const std::string &  value 
)
inline

Set a configuration parameter.

Parameters
sectionsection.
optionoption.
valuevalue for option.

Referenced by DUNE::Daemon::consume(), and DUNE::Tasks::Task::onSetEntityParameters().

void DUNE::Parsers::Config::setSection ( const std::string &  section,
const std::map< std::string, std::string > &  map 
)
inline

Set the option map of a given section.

Parameters
[in]sectionsection name.
[in]mapmap of <option, value>.
void DUNE::Parsers::Config::writeToFile ( const char *  file)

Writes the current configuration to a file.

Parameters
fileoutput file option.

Referenced by DUNE::Daemon::consume(), and getList().

Friends And Related Function Documentation

DUNE_DLL_SYM std::ostream& operator<< ( std::ostream &  os,
const Config cfg 
)
friend

Write the current configuration to a stream.

Parameters
[in]osoutput stream.
[in]cfgConfig instance.

Referenced by files().

Collaboration diagram for DUNE::Parsers::Config:
Collaboration graph