ConfDataReader Class Reference
[Formatted file I/O]

#include <ConfDataReader.hpp>

Inheritance diagram for ConfDataReader:

Inheritance graph
[legend]
Collaboration diagram for ConfDataReader:

Collaboration graph
[legend]
List of all members.

Detailed Description

This is a class to parse and manage configuration data files.

A typical way to use this class follows:

      // Declare a ConfDataReader object
   ConfDataReader confRead;

      // Open and parse configuration file
   confRead.open("configuration.txt");

      // Read variable 'name' from section 'ONSA' using '()' operator
   string rxName( confRead("name", "ONSA') );

      // Get default tolerance from default section "DEFAULT"
   double tolerance;
   tolerance = confRead.getValueAsDouble("tolerance");

      // Print "baseline" description, value and units
   cout << confRead.getVariableDescription("baseline") << endl;
   cout << confRead.getValueAsDouble("baseline")       << endl;
   cout << confRead.getValueDescription("baseline")    << endl;

      // Read if receiver "BELL" will be treated as a reference rx
   bool bellRef( confRead.getValueAsBoolean("reference", "BELL") );

ConfDataReader class provides powerful objects to read and manage configuration data files. They support multiple sections, variable descriptions, and value descriptions (such as units).

An example of configuration file follows:

 # This is a configuration file, and this is a comment line
 ; This is also a comment line

 # The general format is:
 ; variableName, variableComment = value, valueComment

 # 'variableComment' and 'valueComment' are optional

 # So far, there is no section declared, so the following couple of
 # variables are stored in section "DEFAULT"

 baseline, baseline between receivers = 13.434510, kilometers
 tolerance, allowed difference between time stamps = 1.5, secs
 reportExceptions = TRUE    ; Recover this with 'getValueAsBoolean()'

 # Declare a section
 [ONSA]

 name, 4-char station name = ONSA

 staX, X station coordinate = 3370658.5419, meters
 staY, Y station coordinate =  711877.1496, meters
 staZ, Z station coordinate = 5349786.9542, meters

 antennaType : AOAD/M_B   # Note that you can use ':' instead of '='


 [BELL]
 reference = TRUE


 [ROVER]
 speed = 0.223 , m/s


 [ONSA]   ; you may reuse a previous section and add new variables
          ; without problems (but with different names!!!)

 sampling, sampling period = 30, s

The configuration file follows the following format:

By default, values are returned as std::string's, but there are methods available to get them as booleans, integers and doubles. Comments are always returned as std::string's.

This class is very strict and throws a 'ConfigurationException' exception when trying to access variables that don't exist in the configuration file. This default behaviour may be changed with the 'setIssueException()' method.

The format of the Variable/Value pairs is inspired in the options file used in the GNSSTk project.

Definition at line 156 of file ConfDataReader.hpp.

Public Member Functions

 ConfDataReader ()
 Default constructor.
 ConfDataReader (const char *file)
 Common constructor.
 ConfDataReader (const std::string &file)
 Common constructor.
virtual void open (const char *fn)
 Method to open AND load configuration data file.
virtual void open (const std::string &fn)
 Method to open AND load configuration data file.
virtual std::string getValue (std::string variable, std::string section="DEFAULT", std::string defaultVal="") throw (ConfigurationException)
 Method to get the value of a given variable as a string.
virtual double getValueAsDouble (std::string variable, std::string section="DEFAULT", double defaultVal=0.0) throw (ConfigurationException)
 Method to get the value of a given variable as a double.
virtual int getValueAsInt (std::string variable, std::string section="DEFAULT", int defaultVal=0) throw (ConfigurationException)
 Method to get the value of a given variable as an integer.
virtual bool getValueAsBoolean (std::string variable, std::string section="DEFAULT", bool defaultVal=false) throw (ConfigurationException)
 Method to get the value of a given variable as a boolean.
virtual std::string fetchListValue (std::string variableList, std::string section="DEFAULT", std::string defaultVal="") throw (ConfigurationException)
 Method to fetch (as string) the first value of a given variable list.
virtual double fetchListValueAsDouble (std::string variableList, std::string section="DEFAULT", double defaultVal=0.0) throw (ConfigurationException)
 Method to fetch (as double) the first value of a given variable list.
virtual int fetchListValueAsInt (std::string variableList, std::string section="DEFAULT", int defaultVal=0) throw (ConfigurationException)
 Method to fetch (as integer) the first value of a given variable list.
virtual bool fetchListValueAsBoolean (std::string variableList, std::string section="DEFAULT", bool defaultVal=false) throw (ConfigurationException)
 Method to fetch (as boolean) the first value of a given variable list.
virtual int getNumItem (std::string variableList, std::string section="DEFAULT") throw (ConfigurationException)
 Method to get the number of items in a given variable list.
virtual std::string getVariableDescription (std::string variable, std::string section="DEFAULT") throw (ConfigurationException)
 Method to get the description of a given variable.
virtual std::string getValueDescription (std::string variable, std::string section="DEFAULT") throw (ConfigurationException)
 Method to get the description of a given value.
virtual bool getIssueException (void) const
 Method to get whether an exception will be issued when requesting an invalid variable (or section), or not.
ConfDataReadersetIssueException (bool issueEx)
 Method to set whether an exception will be issued when requesting an invalid variable (or section), or not.
virtual bool getFallback2Default (void) const
 Method to get whether when a variable is looked for in a given section and not found, it will also be looked for in 'DEFAULT'.
ConfDataReadersetFallback2Default (bool fallback)
 Method to set whether when a variable is looked for in a given section and not found, it will also be looked for in 'DEFAULT'.
virtual ConfDataReaderclear (void)
 Method to clear the stored variables.
virtual std::string getEachSection (void)
 Method to get the name of each section in order.
virtual void resetSection (void)
 Method to reset the iterator traversing section names.
virtual bool ifExist (std::string variable, std::string section="DEFAULT") throw (ConfigurationException)
 Method to check if a given section/variable pair exists.
virtual std::string operator() (std::string variable, std::string section="DEFAULT") throw (ConfigurationException)
 Operator to get the value of a given variable as a string.
virtual ~ConfDataReader ()
 Destructor.


Constructor & Destructor Documentation

ConfDataReader  )  [inline]
 

Default constructor.

Definition at line 161 of file ConfDataReader.hpp.

ConfDataReader const char *  file  )  [inline]
 

Common constructor.

It will always open 'file' for read and will configuration data in one pass.

Parameters:
file Configuration data file to read

Definition at line 171 of file ConfDataReader.hpp.

ConfDataReader const std::string &  file  )  [inline]
 

Common constructor.

It will always open 'fn' for read and will configuration data in one pass.

Parameters:
file Configuration data file to read

Definition at line 183 of file ConfDataReader.hpp.

virtual ~ConfDataReader  )  [inline, virtual]
 

Destructor.

Definition at line 446 of file ConfDataReader.hpp.


Member Function Documentation

virtual ConfDataReader& clear void   )  [inline, virtual]
 

Method to clear the stored variables.

Definition at line 408 of file ConfDataReader.hpp.

string fetchListValue std::string  variableList,
std::string  section = "DEFAULT",
std::string  defaultVal = ""
throw (ConfigurationException) [virtual]
 

Method to fetch (as string) the first value of a given variable list.

In this context, a variable list is the same as a variable but it is composed of several parts (words), separated by spaces.

Parameters:
variableList Variable list name.
section Section the variable list belongs to.
Warning:
This method will MODIFY the original content of 'variableList'.

Definition at line 432 of file ConfDataReader.cpp.

References GPSTK_RETHROW, gpstk::StringUtils::strip(), and gpstk::StringUtils::upperCase().

bool fetchListValueAsBoolean std::string  variableList,
std::string  section = "DEFAULT",
bool  defaultVal = false
throw (ConfigurationException) [virtual]
 

Method to fetch (as boolean) the first value of a given variable list.

In this context, a variable list is the same as a variable but it is composed of several parts (words), separated by spaces.

Parameters:
variableList Variable list name.
section Section the variable list belongs to.
Warning:
This method will MODIFY the original content of 'variableList'.

If variable list is empty, it will return FALSE.

Definition at line 480 of file ConfDataReader.cpp.

References GPSTK_RETHROW, GPSTK_THROW, and gpstk::StringUtils::upperCase().

virtual double fetchListValueAsDouble std::string  variableList,
std::string  section = "DEFAULT",
double  defaultVal = 0.0
throw (ConfigurationException) [inline, virtual]
 

Method to fetch (as double) the first value of a given variable list.

In this context, a variable list is the same as a variable but it is composed of several parts (words), separated by spaces.

Parameters:
variableList Variable list name.
section Section the variable list belongs to.
Warning:
This method will MODIFY the original content of 'variableList'.

Definition at line 284 of file ConfDataReader.hpp.

References gpstk::StringUtils::asDouble().

virtual int fetchListValueAsInt std::string  variableList,
std::string  section = "DEFAULT",
int  defaultVal = 0
throw (ConfigurationException) [inline, virtual]
 

Method to fetch (as integer) the first value of a given variable list.

In this context, a variable list is the same as a variable but it is composed of several parts (words), separated by spaces.

Parameters:
variableList Variable list name.
section Section the variable list belongs to.
Warning:
This method will MODIFY the original content of 'variableList'.

Definition at line 306 of file ConfDataReader.hpp.

References gpstk::StringUtils::asInt().

string getEachSection void   )  [virtual]
 

Method to get the name of each section in order.

Definition at line 833 of file ConfDataReader.cpp.

Referenced by ConfData::load().

virtual bool getFallback2Default void   )  const [inline, virtual]
 

Method to get whether when a variable is looked for in a given section and not found, it will also be looked for in 'DEFAULT'.

Definition at line 393 of file ConfDataReader.hpp.

virtual bool getIssueException void   )  const [inline, virtual]
 

Method to get whether an exception will be issued when requesting an invalid variable (or section), or not.

Definition at line 376 of file ConfDataReader.hpp.

virtual int getNumItem std::string  variableList,
std::string  section = "DEFAULT"
throw (ConfigurationException) [inline, virtual]
 

Method to get the number of items in a given variable list.

In this context, a variable list is the same as a variable but it is composed of several parts (words), separated by spaces.

Parameters:
variableList Variable list name.
section Section the variable list belongs to.

Definition at line 345 of file ConfDataReader.hpp.

References gpstk::StringUtils::numWords().

string getValue std::string  variable,
std::string  section = "DEFAULT",
std::string  defaultVal = ""
throw (ConfigurationException) [virtual]
 

Method to get the value of a given variable as a string.

Parameters:
variable Variable name.
section Section the variable belongs to.

Definition at line 258 of file ConfDataReader.cpp.

References GPSTK_RETHROW, and gpstk::StringUtils::upperCase().

Referenced by ConfData::load().

bool getValueAsBoolean std::string  variable,
std::string  section = "DEFAULT",
bool  defaultVal = false
throw (ConfigurationException) [virtual]
 

Method to get the value of a given variable as a boolean.

Parameters:
variable Variable name.
section Section the variable belongs to.

Definition at line 348 of file ConfDataReader.cpp.

References GPSTK_RETHROW, GPSTK_THROW, and gpstk::StringUtils::upperCase().

virtual double getValueAsDouble std::string  variable,
std::string  section = "DEFAULT",
double  defaultVal = 0.0
throw (ConfigurationException) [inline, virtual]
 

Method to get the value of a given variable as a double.

Parameters:
variable Variable name.
section Section the variable belongs to.

Definition at line 216 of file ConfDataReader.hpp.

References gpstk::StringUtils::asDouble().

virtual int getValueAsInt std::string  variable,
std::string  section = "DEFAULT",
int  defaultVal = 0
throw (ConfigurationException) [inline, virtual]
 

Method to get the value of a given variable as an integer.

Parameters:
variable Variable name.
section Section the variable belongs to.

Definition at line 232 of file ConfDataReader.hpp.

References gpstk::StringUtils::asInt().

string getValueDescription std::string  variable,
std::string  section = "DEFAULT"
throw (ConfigurationException) [virtual]
 

Method to get the description of a given value.

Parameters:
variable Variable name.
section Section the variable belongs to.

Definition at line 634 of file ConfDataReader.cpp.

References GPSTK_RETHROW, and gpstk::StringUtils::upperCase().

Referenced by ConfData::load().

string getVariableDescription std::string  variable,
std::string  section = "DEFAULT"
throw (ConfigurationException) [virtual]
 

Method to get the description of a given variable.

Parameters:
variable Variable name.
section Section the variable belongs to.

Definition at line 548 of file ConfDataReader.cpp.

References GPSTK_RETHROW, and gpstk::StringUtils::upperCase().

Referenced by ConfData::load().

bool ifExist std::string  variable,
std::string  section = "DEFAULT"
throw (ConfigurationException) [virtual]
 

Method to check if a given section/variable pair exists.

Parameters:
variable Variable name.
section Section the variable belongs to.

Definition at line 720 of file ConfDataReader.cpp.

References GPSTK_THROW, and gpstk::StringUtils::upperCase().

virtual void open const std::string &  fn  )  [inline, virtual]
 

Method to open AND load configuration data file.

Definition at line 194 of file ConfDataReader.hpp.

void open const char *  fn  )  [virtual]
 

Method to open AND load configuration data file.

Definition at line 818 of file ConfDataReader.cpp.

Referenced by ConfData::load().

virtual std::string operator() std::string  variable,
std::string  section = "DEFAULT"
throw (ConfigurationException) [inline, virtual]
 

Operator to get the value of a given variable as a string.

Parameters:
variable Variable name.
section Section the variable belongs to.

Definition at line 439 of file ConfDataReader.hpp.

virtual void resetSection void   )  [inline, virtual]
 

Method to reset the iterator traversing section names.

This method is intended to be used complementing method 'getEachSection()'.

Definition at line 418 of file ConfDataReader.hpp.

ConfDataReader& setFallback2Default bool  fallback  )  [inline]
 

Method to set whether when a variable is looked for in a given section and not found, it will also be looked for in 'DEFAULT'.

Parameters:
fallback Whether we will fallback to 'DEFAULT' or not

Definition at line 403 of file ConfDataReader.hpp.

Referenced by ConfData::load().

ConfDataReader& setIssueException bool  issueEx  )  [inline]
 

Method to set whether an exception will be issued when requesting an invalid variable (or section), or not.

Parameters:
issueEx Whether an exception will be issued or not

Definition at line 386 of file ConfDataReader.hpp.


The documentation for this class was generated from the following files:
Generated on Wed May 22 03:31:53 2013 for GPS ToolKit Software Library by  doxygen 1.3.9.1