This is a class to parse and manage configuration data files.
A typical way to use this class follows:
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:
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 167 of file ConfDataReader.hpp.
#include <ConfDataReader.hpp>
Classes | |
struct | variableData |
A structure used to store variable's data. More... | |
Public Member Functions | |
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... | |
Private Types | |
typedef std::map< std::string, variableMap > | confMap |
Define 'confMap' type. More... | |
typedef std::map< std::string, variableData > | variableMap |
Define 'variableMap' type. More... | |
Private Member Functions | |
virtual bool | checkName (std::string name) |
virtual void | loadData (void) |
Private Attributes | |
confMap | confData |
Map holding the configuration information. More... | |
bool | fallback2Default |
bool | issueException |
confMap::const_iterator | itCurrentSection |
Iterator pointing to the current section. More... | |
Additional Inherited Members | |
![]() | |
static bool | isFFStream (std::istream &i) |
Check if the input stream is the kind of RinexObsStream. More... | |
![]() | |
unsigned int | lineNumber |
![]() | |
std::string | filename |
file name More... | |
FFStreamError | mostRecentException |
This stores the most recently thrown exception. More... | |
unsigned int | recordNumber |
keeps track of the number of records read More... | |
![]() | |
virtual void | tryFFStreamGet (FFData &rec) |
virtual void | tryFFStreamPut (const FFData &rec) |
|
private |
Define 'confMap' type.
Definition at line 477 of file ConfDataReader.hpp.
|
private |
Define 'variableMap' type.
Definition at line 474 of file ConfDataReader.hpp.
|
inline |
Default constructor.
Definition at line 172 of file ConfDataReader.hpp.
|
inline |
Common constructor. It will always open 'file' for read and will configuration data in one pass.
file | Configuration data file to read |
Definition at line 182 of file ConfDataReader.hpp.
|
inline |
Common constructor. It will always open 'fn' for read and will configuration data in one pass.
file | Configuration data file to read |
Definition at line 194 of file ConfDataReader.hpp.
|
inlinevirtual |
Destructor.
Definition at line 445 of file ConfDataReader.hpp.
|
privatevirtual |
Method to check if the given parameter name is properly formed.
name | Name to the checked. |
Definition at line 866 of file ConfDataReader.cpp.
|
inlinevirtual |
Method to clear the stored variables.
Definition at line 409 of file ConfDataReader.hpp.
|
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.
variableList | Variable list name. |
section | Section the variable list belongs to. |
ConfigurationException |
Definition at line 440 of file ConfDataReader.cpp.
|
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.
variableList | Variable list name. |
section | Section the variable list belongs to. |
ConfigurationException |
Definition at line 487 of file ConfDataReader.cpp.
|
inlinevirtual |
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.
variableList | Variable list name. |
section | Section the variable list belongs to. |
ConfigurationException |
Definition at line 291 of file ConfDataReader.hpp.
|
inlinevirtual |
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.
variableList | Variable list name. |
section | Section the variable list belongs to. |
ConfigurationException |
Definition at line 312 of file ConfDataReader.hpp.
|
virtual |
Method to get the name of each section in order.
Definition at line 836 of file ConfDataReader.cpp.
|
inlinevirtual |
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 394 of file ConfDataReader.hpp.
|
inlinevirtual |
Method to get whether an exception will be issued when requesting an invalid variable (or section), or not.
Definition at line 377 of file ConfDataReader.hpp.
|
inlinevirtual |
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.
variableList | Variable list name. |
section | Section the variable list belongs to. |
ConfigurationException |
Definition at line 349 of file ConfDataReader.hpp.
|
virtual |
Method to get the value of a given variable as a string
variable | Variable name. |
section | Section the variable belongs to. |
ConfigurationException |
Definition at line 268 of file ConfDataReader.cpp.
|
virtual |
Method to get the value of a given variable as a boolean
variable | Variable name. |
section | Section the variable belongs to. |
ConfigurationException |
Definition at line 357 of file ConfDataReader.cpp.
|
inlinevirtual |
Method to get the value of a given variable as a double
variable | Variable name. |
section | Section the variable belongs to. |
ConfigurationException |
Definition at line 227 of file ConfDataReader.hpp.
|
inlinevirtual |
Method to get the value of a given variable as an integer
variable | Variable name. |
section | Section the variable belongs to. |
ConfigurationException |
Definition at line 242 of file ConfDataReader.hpp.
|
virtual |
Method to get the description of a given value
variable | Variable name. |
section | Section the variable belongs to. |
ConfigurationException |
Definition at line 639 of file ConfDataReader.cpp.
|
virtual |
Method to get the description of a given variable
variable | Variable name. |
section | Section the variable belongs to. |
ConfigurationException |
Definition at line 554 of file ConfDataReader.cpp.
|
virtual |
Method to check if a given section/variable pair exists.
variable | Variable name. |
section | Section the variable belongs to. |
ConfigurationException |
Definition at line 724 of file ConfDataReader.cpp.
|
privatevirtual |
Method to store conf data in this class' data map
ConfigurationException |
Definition at line 52 of file ConfDataReader.cpp.
|
virtual |
Method to open AND load configuration data file.
Definition at line 821 of file ConfDataReader.cpp.
|
inlinevirtual |
Method to open AND load configuration data file.
Definition at line 206 of file ConfDataReader.hpp.
|
inlinevirtual |
Operator to get the value of a given variable as a string
variable | Variable name. |
section | Section the variable belongs to. |
ConfigurationException |
Definition at line 439 of file ConfDataReader.hpp.
|
inlinevirtual |
Method to reset the iterator traversing section names. This method is intended to be used complementing method 'getEachSection()'.
Definition at line 419 of file ConfDataReader.hpp.
|
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'.
fallback | Whether we will fallback to 'DEFAULT' or not |
Definition at line 404 of file ConfDataReader.hpp.
|
inline |
Method to set whether an exception will be issued when requesting an invalid variable (or section), or not.
issueEx | Whether an exception will be issued or not |
Definition at line 387 of file ConfDataReader.hpp.
|
private |
Map holding the configuration information.
Definition at line 482 of file ConfDataReader.hpp.
|
private |
This boolean field determines if when a variable doesn't exist in a given section, it will also be looked for in 'DEFAULT'
Definition at line 458 of file ConfDataReader.hpp.
|
private |
This boolean field determines whether an exception will be issued when requesting an invalid variable (or section), or not
Definition at line 453 of file ConfDataReader.hpp.
|
private |
Iterator pointing to the current section.
Definition at line 486 of file ConfDataReader.hpp.