This is a class to parse and manage configuration data files.
A typical way to use this class follows:
confRead.open("configuration.txt");
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:
- Anything after a '#' or a ';' is a comment
- Blank lines are ignored.
- No line may have more than 255 characters.
- Variable and section names are ALWAYS converted to uppercase.
- Variable and section names MUST start with a letter, and must only contain a mix of letters, numbers, dashes (-) and underscores (_).
- Section names must be enclosed in brackets ([]).
- The Variable/Value pairs are separated by either '=' or ':'.
- You may add comments to variables and values. Use a comma to separate such comments.
- If you use the same variable name within a given section, only the last value will be used. Remember that names are ALWAYS converted to uppercase.
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 167 of file ConfDataReader.hpp.
|
virtual ConfDataReader & | clear (void) |
| Method to clear the stored variables. More...
|
|
| ConfDataReader () |
| Default constructor. More...
|
|
| ConfDataReader (const char *file) |
|
| ConfDataReader (const std::string &file) |
|
virtual std::string | fetchListValue (std::string variableList, std::string section="DEFAULT", std::string defaultVal="") |
|
virtual bool | fetchListValueAsBoolean (std::string variableList, std::string section="DEFAULT", bool defaultVal=false) |
|
virtual double | fetchListValueAsDouble (std::string variableList, std::string section="DEFAULT", double defaultVal=0.0) |
|
virtual int | fetchListValueAsInt (std::string variableList, std::string section="DEFAULT", int defaultVal=0) |
|
virtual std::string | getEachSection (void) |
| Method to get the name of each section in order. More...
|
|
virtual bool | getFallback2Default (void) const |
|
virtual bool | getIssueException (void) const |
|
virtual int | getNumItem (std::string variableList, std::string section="DEFAULT") |
|
virtual std::string | getValue (std::string variable, std::string section="DEFAULT", std::string defaultVal="") |
|
virtual bool | getValueAsBoolean (std::string variable, std::string section="DEFAULT", bool defaultVal=false) |
|
virtual double | getValueAsDouble (std::string variable, std::string section="DEFAULT", double defaultVal=0.0) |
|
virtual int | getValueAsInt (std::string variable, std::string section="DEFAULT", int defaultVal=0) |
|
virtual std::string | getValueDescription (std::string variable, std::string section="DEFAULT") |
|
virtual std::string | getVariableDescription (std::string variable, std::string section="DEFAULT") |
|
virtual bool | ifExist (std::string variable, std::string section="DEFAULT") |
|
virtual void | open (const char *fn) |
| Method to open AND load configuration data file. More...
|
|
virtual void | open (const std::string &fn) |
| Method to open AND load configuration data file. More...
|
|
virtual std::string | operator() (std::string variable, std::string section="DEFAULT") |
|
virtual void | resetSection (void) |
|
ConfDataReader & | setFallback2Default (bool fallback) |
|
ConfDataReader & | setIssueException (bool issueEx) |
|
virtual | ~ConfDataReader () |
| Destructor. More...
|
|
| FFTextStream () |
| Default constructor. More...
|
|
| FFTextStream (const char *fn, std::ios::openmode mode=std::ios::in) |
|
| FFTextStream (const std::string &fn, std::ios::openmode mode=std::ios::in) |
|
void | formattedGetLine (std::string &line, const bool expectEOF=false) |
|
virtual void | open (const char *fn, std::ios::openmode mode) |
| Overrides open to reset the line number. More...
|
|
virtual void | open (const std::string &fn, std::ios::openmode mode) |
| Overrides open to reset the line number. More...
|
|
virtual | ~FFTextStream () |
| Destructor. More...
|
|
void | conditionalThrow (void) |
|
void | dumpState (std::ostream &s=std::cout) const |
| A function to help debug FFStreams. More...
|
|
| FFStream () |
| Default constructor, initialize internal data. More...
|
|
| FFStream (const char *fn, std::ios::openmode mode=std::ios::in) |
|
| FFStream (const std::string &fn, std::ios::openmode mode=std::ios::in) |
|
virtual | ~FFStream () |
| Virtual destructor, close the stream etc. More...
|
|