DUNE: Uniform Navigational Environment  2017.01.0
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.

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.
std::string DUNE::Parsers::Config::get ( const std::string &  section,
const std::string &  option 
)
inline

Retrieve the value of an option in a given section.

Parameters
sectionsection.
optionoption.
Returns
option value.

Referenced by DUNE::Control::BasicAutopilot::BasicAutopilot(), DUNE::Daemon::consume(), DUNE::Daemon::Daemon(), DUNE::Tasks::Task::loadConfig(), DUNE::Tasks::Manager::Manager(), DUNE::Power::Model::Model(), Transports::Radio::Task::onRequestActivation(), Simulators::Environment::Task::onResourceInitialization(), Transports::Seatrac::Task::onResourceInitialization(), Sensors::MLBL::Task::onResourceInitialization(), Transports::Radio::Task::onResourceInitialization(), Sensors::MLBLTracker::Task::onUpdateParameters(), DUNE::Parsers::PlanConfigParser::parse(), DUNE::Parsers::PlanConfigParser::parseActions(), DUNE::Parsers::PlanConfigParser::parseAngle(), DUNE::Parsers::PlanConfigParser::parseCoordinate(), DUNE::Parsers::PlanConfigParser::parseDuration(), DUNE::Parsers::PlanConfigParser::parseSpeed(), DUNE::Parsers::PlanConfigParser::parseTimeout(), DUNE::Parsers::PlanConfigParser::parseZ(), DUNE::Parsers::PlanConfigParser::parseZUnits(), DUNE::Control::PathController::PathController(), DUNE::Math::Matrix::readFromConfig(), Transports::CommManager::Task::sendViaSms(), DUNE::Plans::SpeedModel::SpeedModel(), Plan::Generator::Task::Task(), Monitors::FuelLevel::Task::Task(), Monitors::Medium::Task::Task(), Supervisors::AUV::Assist::Task::Task(), Control::AUV::Allocator::Task::Task(), Control::AUV::Speed::Task::Task(), Monitors::OperationalLimits::Task::Task(), Plan::Engine::Task::Task(), and Control::AUV::Attitude::Task::Task().

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.
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)
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 DUNE::Tasks::Manager::Manager().

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().

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().

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.
Collaboration diagram for DUNE::Parsers::Config:
Collaboration graph