Classes | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
gnsstk::ConfDataReader Class Reference

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 167 of file ConfDataReader.hpp.

#include <ConfDataReader.hpp>

Inheritance diagram for gnsstk::ConfDataReader:
Inheritance graph
[legend]

Classes

struct  variableData
 A structure used to store variable's data. More...
 

Public Member Functions

virtual ConfDataReaderclear (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)
 
ConfDataReadersetFallback2Default (bool fallback)
 
ConfDataReadersetIssueException (bool issueEx)
 
virtual ~ConfDataReader ()
 Destructor. More...
 
- Public Member Functions inherited from gnsstk::FFTextStream
 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...
 
- Public Member Functions inherited from gnsstk::FFStream
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, variableMapconfMap
 Define 'confMap' type. More...
 
typedef std::map< std::string, variableDatavariableMap
 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 Public Member Functions inherited from gnsstk::FFStream
static bool isFFStream (std::istream &i)
 Check if the input stream is the kind of RinexObsStream. More...
 
- Public Attributes inherited from gnsstk::FFTextStream
unsigned int lineNumber
 
- Public Attributes inherited from gnsstk::FFStream
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...
 
- Protected Member Functions inherited from gnsstk::FFTextStream
virtual void tryFFStreamGet (FFData &rec)
 
virtual void tryFFStreamPut (const FFData &rec)
 

Member Typedef Documentation

◆ confMap

typedef std::map<std::string, variableMap> gnsstk::ConfDataReader::confMap
private

Define 'confMap' type.

Definition at line 477 of file ConfDataReader.hpp.

◆ variableMap

typedef std::map<std::string, variableData> gnsstk::ConfDataReader::variableMap
private

Define 'variableMap' type.

Definition at line 474 of file ConfDataReader.hpp.

Constructor & Destructor Documentation

◆ ConfDataReader() [1/3]

gnsstk::ConfDataReader::ConfDataReader ( )
inline

Default constructor.

Definition at line 172 of file ConfDataReader.hpp.

◆ ConfDataReader() [2/3]

gnsstk::ConfDataReader::ConfDataReader ( const char *  file)
inline

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

Parameters
fileConfiguration data file to read

Definition at line 182 of file ConfDataReader.hpp.

◆ ConfDataReader() [3/3]

gnsstk::ConfDataReader::ConfDataReader ( const std::string &  file)
inline

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

Parameters
fileConfiguration data file to read

Definition at line 194 of file ConfDataReader.hpp.

◆ ~ConfDataReader()

virtual gnsstk::ConfDataReader::~ConfDataReader ( )
inlinevirtual

Destructor.

Definition at line 445 of file ConfDataReader.hpp.

Member Function Documentation

◆ checkName()

bool gnsstk::ConfDataReader::checkName ( std::string  name)
privatevirtual

Method to check if the given parameter name is properly formed.

Parameters
nameName to the checked.

Definition at line 866 of file ConfDataReader.cpp.

◆ clear()

virtual ConfDataReader& gnsstk::ConfDataReader::clear ( void  )
inlinevirtual

Method to clear the stored variables.

Definition at line 409 of file ConfDataReader.hpp.

◆ fetchListValue()

string gnsstk::ConfDataReader::fetchListValue ( std::string  variableList,
std::string  section = "DEFAULT",
std::string  defaultVal = "" 
)
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
variableListVariable list name.
sectionSection the variable list belongs to.
Exceptions
ConfigurationException
Warning
This method will MODIFY the original content of 'variableList'.

Definition at line 440 of file ConfDataReader.cpp.

◆ fetchListValueAsBoolean()

bool gnsstk::ConfDataReader::fetchListValueAsBoolean ( std::string  variableList,
std::string  section = "DEFAULT",
bool  defaultVal = false 
)
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
variableListVariable list name.
sectionSection the variable list belongs to.
Exceptions
ConfigurationException
Warning
This method will MODIFY the original content of 'variableList'.
If variable list is empty, it will return FALSE.

Definition at line 487 of file ConfDataReader.cpp.

◆ fetchListValueAsDouble()

virtual double gnsstk::ConfDataReader::fetchListValueAsDouble ( std::string  variableList,
std::string  section = "DEFAULT",
double  defaultVal = 0.0 
)
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.

Parameters
variableListVariable list name.
sectionSection the variable list belongs to.
Exceptions
ConfigurationException
Warning
This method will MODIFY the original content of 'variableList'.

Definition at line 291 of file ConfDataReader.hpp.

◆ fetchListValueAsInt()

virtual int gnsstk::ConfDataReader::fetchListValueAsInt ( std::string  variableList,
std::string  section = "DEFAULT",
int  defaultVal = 0 
)
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.

Parameters
variableListVariable list name.
sectionSection the variable list belongs to.
Exceptions
ConfigurationException
Warning
This method will MODIFY the original content of 'variableList'.

Definition at line 312 of file ConfDataReader.hpp.

◆ getEachSection()

string gnsstk::ConfDataReader::getEachSection ( void  )
virtual

Method to get the name of each section in order.

Definition at line 836 of file ConfDataReader.cpp.

◆ getFallback2Default()

virtual bool gnsstk::ConfDataReader::getFallback2Default ( void  ) const
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.

◆ getIssueException()

virtual bool gnsstk::ConfDataReader::getIssueException ( void  ) const
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.

◆ getNumItem()

virtual int gnsstk::ConfDataReader::getNumItem ( std::string  variableList,
std::string  section = "DEFAULT" 
)
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.

Parameters
variableListVariable list name.
sectionSection the variable list belongs to.
Exceptions
ConfigurationException

Definition at line 349 of file ConfDataReader.hpp.

◆ getValue()

string gnsstk::ConfDataReader::getValue ( std::string  variable,
std::string  section = "DEFAULT",
std::string  defaultVal = "" 
)
virtual

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

Parameters
variableVariable name.
sectionSection the variable belongs to.
Exceptions
ConfigurationException

Definition at line 268 of file ConfDataReader.cpp.

◆ getValueAsBoolean()

bool gnsstk::ConfDataReader::getValueAsBoolean ( std::string  variable,
std::string  section = "DEFAULT",
bool  defaultVal = false 
)
virtual

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

Parameters
variableVariable name.
sectionSection the variable belongs to.
Exceptions
ConfigurationException

Definition at line 357 of file ConfDataReader.cpp.

◆ getValueAsDouble()

virtual double gnsstk::ConfDataReader::getValueAsDouble ( std::string  variable,
std::string  section = "DEFAULT",
double  defaultVal = 0.0 
)
inlinevirtual

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

Parameters
variableVariable name.
sectionSection the variable belongs to.
Exceptions
ConfigurationException

Definition at line 227 of file ConfDataReader.hpp.

◆ getValueAsInt()

virtual int gnsstk::ConfDataReader::getValueAsInt ( std::string  variable,
std::string  section = "DEFAULT",
int  defaultVal = 0 
)
inlinevirtual

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

Parameters
variableVariable name.
sectionSection the variable belongs to.
Exceptions
ConfigurationException

Definition at line 242 of file ConfDataReader.hpp.

◆ getValueDescription()

string gnsstk::ConfDataReader::getValueDescription ( std::string  variable,
std::string  section = "DEFAULT" 
)
virtual

Method to get the description of a given value

Parameters
variableVariable name.
sectionSection the variable belongs to.
Exceptions
ConfigurationException

Definition at line 639 of file ConfDataReader.cpp.

◆ getVariableDescription()

string gnsstk::ConfDataReader::getVariableDescription ( std::string  variable,
std::string  section = "DEFAULT" 
)
virtual

Method to get the description of a given variable

Parameters
variableVariable name.
sectionSection the variable belongs to.
Exceptions
ConfigurationException

Definition at line 554 of file ConfDataReader.cpp.

◆ ifExist()

bool gnsstk::ConfDataReader::ifExist ( std::string  variable,
std::string  section = "DEFAULT" 
)
virtual

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

Parameters
variableVariable name.
sectionSection the variable belongs to.
Exceptions
ConfigurationException

Definition at line 724 of file ConfDataReader.cpp.

◆ loadData()

void gnsstk::ConfDataReader::loadData ( void  )
privatevirtual

Method to store conf data in this class' data map

Exceptions
ConfigurationException

Definition at line 52 of file ConfDataReader.cpp.

◆ open() [1/2]

void gnsstk::ConfDataReader::open ( const char *  fn)
virtual

Method to open AND load configuration data file.

Definition at line 821 of file ConfDataReader.cpp.

◆ open() [2/2]

virtual void gnsstk::ConfDataReader::open ( const std::string &  fn)
inlinevirtual

Method to open AND load configuration data file.

Definition at line 206 of file ConfDataReader.hpp.

◆ operator()()

virtual std::string gnsstk::ConfDataReader::operator() ( std::string  variable,
std::string  section = "DEFAULT" 
)
inlinevirtual

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

Parameters
variableVariable name.
sectionSection the variable belongs to.
Exceptions
ConfigurationException

Definition at line 439 of file ConfDataReader.hpp.

◆ resetSection()

virtual void gnsstk::ConfDataReader::resetSection ( void  )
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.

◆ setFallback2Default()

ConfDataReader& gnsstk::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
fallbackWhether we will fallback to 'DEFAULT' or not

Definition at line 404 of file ConfDataReader.hpp.

◆ setIssueException()

ConfDataReader& gnsstk::ConfDataReader::setIssueException ( bool  issueEx)
inline

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

Parameters
issueExWhether an exception will be issued or not

Definition at line 387 of file ConfDataReader.hpp.

Member Data Documentation

◆ confData

confMap gnsstk::ConfDataReader::confData
private

Map holding the configuration information.

Definition at line 482 of file ConfDataReader.hpp.

◆ fallback2Default

bool gnsstk::ConfDataReader::fallback2Default
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.

◆ issueException

bool gnsstk::ConfDataReader::issueException
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.

◆ itCurrentSection

confMap::const_iterator gnsstk::ConfDataReader::itCurrentSection
private

Iterator pointing to the current section.

Definition at line 486 of file ConfDataReader.hpp.


The documentation for this class was generated from the following files:
gnsstk::TrackingCode::Y
@ Y
Encrypted legacy GPS precise code.
example4.time
time
Definition: example4.py:103
gnsstk::ConfDataReader::ConfDataReader
ConfDataReader()
Default constructor.
Definition: ConfDataReader.hpp:172


gnsstk
Author(s):
autogenerated on Wed Oct 25 2023 02:40:44