#include <ConfDataReader.hpp>
Inheritance diagram for ConfDataReader:


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. | |
| ConfDataReader & | setIssueException (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'. | |
| ConfDataReader & | setFallback2Default (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 ConfDataReader & | clear (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. | |
|
|
Default constructor.
Definition at line 161 of file ConfDataReader.hpp. |
|
|
Common constructor. It will always open 'file' for read and will configuration data in one pass.
Definition at line 171 of file ConfDataReader.hpp. |
|
|
Common constructor. It will always open 'fn' for read and will configuration data in one pass.
Definition at line 183 of file ConfDataReader.hpp. |
|
|
Destructor.
Definition at line 446 of file ConfDataReader.hpp. |
|
|
Method to clear the stored variables.
Definition at line 408 of file ConfDataReader.hpp. |
|
||||||||||||||||
|
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.
Definition at line 432 of file ConfDataReader.cpp. References GPSTK_RETHROW, gpstk::StringUtils::strip(), and gpstk::StringUtils::upperCase(). |
|
||||||||||||||||
|
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.
Definition at line 480 of file ConfDataReader.cpp. References GPSTK_RETHROW, GPSTK_THROW, and gpstk::StringUtils::upperCase(). |
|
||||||||||||||||
|
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.
Definition at line 284 of file ConfDataReader.hpp. References gpstk::StringUtils::asDouble(). |
|
||||||||||||||||
|
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.
Definition at line 306 of file ConfDataReader.hpp. References gpstk::StringUtils::asInt(). |
|
|
Method to get the name of each section in order.
Definition at line 833 of file ConfDataReader.cpp. Referenced by ConfData::load(). |
|
|
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. |
|
|
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. |
|
||||||||||||
|
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.
Definition at line 345 of file ConfDataReader.hpp. References gpstk::StringUtils::numWords(). |
|
||||||||||||||||
|
Method to get the value of a given variable as a string.
Definition at line 258 of file ConfDataReader.cpp. References GPSTK_RETHROW, and gpstk::StringUtils::upperCase(). Referenced by ConfData::load(). |
|
||||||||||||||||
|
Method to get the value of a given variable as a boolean.
Definition at line 348 of file ConfDataReader.cpp. References GPSTK_RETHROW, GPSTK_THROW, and gpstk::StringUtils::upperCase(). |
|
||||||||||||||||
|
Method to get the value of a given variable as a double.
Definition at line 216 of file ConfDataReader.hpp. References gpstk::StringUtils::asDouble(). |
|
||||||||||||||||
|
Method to get the value of a given variable as an integer.
Definition at line 232 of file ConfDataReader.hpp. References gpstk::StringUtils::asInt(). |
|
||||||||||||
|
Method to get the description of a given value.
Definition at line 634 of file ConfDataReader.cpp. References GPSTK_RETHROW, and gpstk::StringUtils::upperCase(). Referenced by ConfData::load(). |
|
||||||||||||
|
Method to get the description of a given variable.
Definition at line 548 of file ConfDataReader.cpp. References GPSTK_RETHROW, and gpstk::StringUtils::upperCase(). Referenced by ConfData::load(). |
|
||||||||||||
|
Method to check if a given section/variable pair exists.
Definition at line 720 of file ConfDataReader.cpp. References GPSTK_THROW, and gpstk::StringUtils::upperCase(). |
|
|
Method to open AND load configuration data file.
Definition at line 194 of file ConfDataReader.hpp. |
|
|
Method to open AND load configuration data file.
Definition at line 818 of file ConfDataReader.cpp. Referenced by ConfData::load(). |
|
||||||||||||
|
Operator to get the value of a given variable as a string.
Definition at line 439 of file ConfDataReader.hpp. |
|
|
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. |
|
|
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'.
Definition at line 403 of file ConfDataReader.hpp. Referenced by ConfData::load(). |
|
|
Method to set whether an exception will be issued when requesting an invalid variable (or section), or not.
Definition at line 386 of file ConfDataReader.hpp. |
1.3.9.1