LTI-Lib latest version v1.9 - last update 10 Apr 2010

lti::configFileHandler Class Reference

Write and read config files, similar to windows ini files. More...

#include <ltiConfigFileHandler.h>

Inheritance diagram for lti::configFileHandler:
Inheritance graph
[legend]
Collaboration diagram for lti::configFileHandler:
Collaboration graph
[legend]

List of all members.

Classes

class  parameters
 the parameters for the class configFileHandler More...

Public Member Functions

 configFileHandler ()
 configFileHandler (const configFileHandler &other)
virtual ~configFileHandler ()
virtual const char * getTypeName () const
configFileHandlercopy (const configFileHandler &other)
configFileHandleroperator= (const configFileHandler &other)
virtual functorclone () const
const parametersgetParameters () const
bool apply ()
bool loadFile ()
bool loadFile (const std::string &fileName)
bool saveFile () const
bool saveFile (const std::string &fileName) const
Reading Values

Use these methods to obtain a desired value.

If request is not available "value" variable will be left unaltered and false will be returned



bool getValue (const std::string &section, const std::string &key, std::string &value, std::string &comment) const
bool getValue (const std::string &section, const std::string &key, std::string &value) const
bool getValue (const std::string &section, const std::string &key, bool &value, std::string &comment) const
bool getValue (const std::string &section, const std::string &key, bool &value) const
bool getValue (const std::string &section, const std::string &key, double &value, std::string &comment) const
bool getValue (const std::string &section, const std::string &key, double &value) const
bool getValue (const std::string &section, const std::string &key, float &value, std::string &comment) const
bool getValue (const std::string &section, const std::string &key, float &value) const
bool getValue (const std::string &section, const std::string &key, int &value, std::string &comment) const
bool getValue (const std::string &section, const std::string &key, int &value) const
bool getValue (const std::string &section, const std::string &key, unsigned int &value, std::string &comment) const
bool getValue (const std::string &section, const std::string &key, unsigned int &value) const
std::list< std::string > getKeys (std::string section) const
Setting Values

Use one of these methods to set entries (section,key,value,comment).

You can also use these to set comments:

  • global if((section=="") && (key==""))
  • section if((section!="") && (key==""))

In case of errors the status string is set and false returned.



bool setValue (const std::string &section, const std::string &key="", const std::string &value="", const std::string &comment="")
bool setValue (const std::string &section, const std::string &key="", const char *value="", const std::string &comment="")
bool setValue (const std::string &section, const std::string &key="", const bool &value=false, const std::string &comment="")
bool setValue (const std::string &section, const std::string &key="", const double &value=0.0, const std::string &comment="")
bool setValue (const std::string &section, const std::string &key="", const float &value=0.0f, const std::string &comment="")
bool setValue (const std::string &section, const std::string &key="", const int &value=0, const std::string &comment="")
bool setValue (const std::string &section, const std::string &key="", const unsigned int &value=0, const std::string &comment="")
Manipulation

Use these methods to manipulate the dictionary



void sortSections ()
bool deleteSection (const std::string &section="")
bool deleteKey (const std::string &section, const std::string &key="")
void clear ()

Protected Member Functions

std::string splitLine (const std::string &inputLine, std::string &prolog, std::string &section, std::string &key, std::string &value, std::string &comment) const
void composeLine (const std::string &prolog, const std::string &section, const std::string &key, const std::string &value, const std::string &comment, bool secDef, int keyLength, std::string &outputLine) const
int getMaxKeyLengths (std::map< std::string, int > &maxKeyLengths) const

Protected Attributes

std::map< std::string,
std::map< std::string,
configEntry > > 
dictionary
std::list< std::string > orderSections
std::map< std::string,
std::list< std::string > > 
orderKeys
std::map< std::string,
std::list< std::string > > 
sectionComments
std::map< std::string,
std::string > 
sectionOrig
std::map< std::string,
std::map< std::string,
std::string > > 
keyOrig

Detailed Description

Write and read config files, similar to windows ini files.

These contain:

All entries will be written as specified, however searching keys or values is case insensitive!

Example config file:

  # a global comment

  *
  * comments in cvs style are alowed too
  *

  [a section]
  # a section comment
  key = value ; a key comment

  [another section] ;more comments
  key = value

Comments can be global, for sections or for single keys. A section comment must be positioned before the first key of this section. Comments for keys start with ';'


Constructor & Destructor Documentation

lti::configFileHandler::configFileHandler (  ) 

default constructor

lti::configFileHandler::configFileHandler ( const configFileHandler other  ) 

copy constructor

Parameters:
other the object to be copied
virtual lti::configFileHandler::~configFileHandler (  )  [virtual]

destructor


Member Function Documentation

bool lti::configFileHandler::apply (  ) 

This is an alias for loadFile().

void lti::configFileHandler::clear (  ) 

Delete every comment, section and key of the internal structure of the config file.

If you write after this to disk you get an empty file.

virtual functor* lti::configFileHandler::clone (  )  const [virtual]

returns a pointer to a clone of this functor.

Implements lti::functor.

void lti::configFileHandler::composeLine ( const std::string &  prolog,
const std::string &  section,
const std::string &  key,
const std::string &  value,
const std::string &  comment,
bool  secDef,
int  keyLength,
std::string &  outputLine 
) const [protected]

Creates a line of the configFile based on the given values.

configFileHandler& lti::configFileHandler::copy ( const configFileHandler other  ) 

copy data of "other" functor.

Parameters:
other the functor to be copied
Returns:
a reference to this functor object

Reimplemented from lti::functor.

bool lti::configFileHandler::deleteKey ( const std::string &  section,
const std::string &  key = "" 
)

Delete a key in an section.

The return value is false if no key of this name exists. If you set the name of the section only you remove all comments of this section.

bool lti::configFileHandler::deleteSection ( const std::string &  section = ""  ) 

Remove alle elements of the section 'section'.

If section is not set all comments above the first section are removed. The return value is false if no section of this name exists.

std::list<std::string> lti::configFileHandler::getKeys ( std::string  section  )  const

Returns a list of all keys in the specified section.

int lti::configFileHandler::getMaxKeyLengths ( std::map< std::string, int > &  maxKeyLengths  )  const [protected]

Creates a map containing section|->maxKeyLength for formatted saving.

Additionally returns the overall maximum length of a key name

const parameters& lti::configFileHandler::getParameters (  )  const

returns used parameters

Reimplemented from lti::ioFunctor.

virtual const char* lti::configFileHandler::getTypeName (  )  const [virtual]

returns the name of this type ("configFileHandler")

Reimplemented from lti::ioFunctor.

bool lti::configFileHandler::getValue ( const std::string &  section,
const std::string &  key,
unsigned int &  value 
) const [inline]

unsigned int

References getValue().

bool lti::configFileHandler::getValue ( const std::string &  section,
const std::string &  key,
unsigned int &  value,
std::string &  comment 
) const

unsigned int

bool lti::configFileHandler::getValue ( const std::string &  section,
const std::string &  key,
int &  value 
) const [inline]

int

References getValue().

bool lti::configFileHandler::getValue ( const std::string &  section,
const std::string &  key,
int &  value,
std::string &  comment 
) const

int

bool lti::configFileHandler::getValue ( const std::string &  section,
const std::string &  key,
float &  value 
) const [inline]

float

References getValue().

bool lti::configFileHandler::getValue ( const std::string &  section,
const std::string &  key,
float &  value,
std::string &  comment 
) const

float

bool lti::configFileHandler::getValue ( const std::string &  section,
const std::string &  key,
double &  value 
) const [inline]

double

References getValue().

bool lti::configFileHandler::getValue ( const std::string &  section,
const std::string &  key,
double &  value,
std::string &  comment 
) const

double

bool lti::configFileHandler::getValue ( const std::string &  section,
const std::string &  key,
bool &  value 
) const [inline]

bool

References getValue().

bool lti::configFileHandler::getValue ( const std::string &  section,
const std::string &  key,
bool &  value,
std::string &  comment 
) const

bool

bool lti::configFileHandler::getValue ( const std::string &  section,
const std::string &  key,
std::string &  value 
) const [inline]

string

References getValue().

bool lti::configFileHandler::getValue ( const std::string &  section,
const std::string &  key,
std::string &  value,
std::string &  comment 
) const

string

Referenced by getValue().

bool lti::configFileHandler::loadFile ( const std::string &  fileName  ) 

Same as loadFile(), but given fileName overrides parameters.

bool lti::configFileHandler::loadFile (  ) 

Loads the specified config file into the dictionary.

If the file is not valid, does not exist, or in case of parse errors 'false' will be returned and the statusString will be set.

configFileHandler& lti::configFileHandler::operator= ( const configFileHandler other  ) 

alias for copy member

Parameters:
other the functor to be copied
Returns:
a reference to this functor object

Reimplemented from lti::functor.

bool lti::configFileHandler::saveFile ( const std::string &  fileName  )  const

Same as saveFile(), but given fileName overrides parameters.

bool lti::configFileHandler::saveFile (  )  const

Saves the dictionary in the file specified in the parameters (replaces existing).

On error the status string is set and false is returned.

bool lti::configFileHandler::setValue ( const std::string &  section,
const std::string &  key = "",
const unsigned int &  value = 0,
const std::string &  comment = "" 
)

unsigned int

bool lti::configFileHandler::setValue ( const std::string &  section,
const std::string &  key = "",
const int &  value = 0,
const std::string &  comment = "" 
)

int

bool lti::configFileHandler::setValue ( const std::string &  section,
const std::string &  key = "",
const float &  value = 0.0f,
const std::string &  comment = "" 
)

float

bool lti::configFileHandler::setValue ( const std::string &  section,
const std::string &  key = "",
const double &  value = 0.0,
const std::string &  comment = "" 
)

double

bool lti::configFileHandler::setValue ( const std::string &  section,
const std::string &  key = "",
const bool &  value = false,
const std::string &  comment = "" 
)

bool

bool lti::configFileHandler::setValue ( const std::string &  section,
const std::string &  key = "",
const char *  value = "",
const std::string &  comment = "" 
) [inline]

const char*

References setValue().

bool lti::configFileHandler::setValue ( const std::string &  section,
const std::string &  key = "",
const std::string &  value = "",
const std::string &  comment = "" 
)

string

Referenced by setValue().

void lti::configFileHandler::sortSections (  ) 

Sort the sections of the dictionary.

The sections are sorted in ascending order. The order of the keys in a section in not changed!

std::string lti::configFileHandler::splitLine ( const std::string &  inputLine,
std::string &  prolog,
std::string &  section,
std::string &  key,
std::string &  value,
std::string &  comment 
) const [protected]

This function splits a line into the tokens key, section.

..


Member Data Documentation

std::map<std::string, std::map<std::string, configEntry> > lti::configFileHandler::dictionary [protected]

Map with section name as key, and map of section's keys as value.

std::map<std::string, std::map<std::string, std::string> > lti::configFileHandler::keyOrig [protected]

Stores capitalization of keys.

std::map<std::string, std::list<std::string> > lti::configFileHandler::orderKeys [protected]

Stores the order of the keys in each section.

std::list<std::string> lti::configFileHandler::orderSections [protected]

Stores the order of the sections.

std::map<std::string, std::list<std::string> > lti::configFileHandler::sectionComments [protected]

Stores pure comments without a key.

std::map<std::string, std::string> lti::configFileHandler::sectionOrig [protected]

Stores capitalization of sections.


The documentation for this class was generated from the following file:

Generated on Sat Apr 10 15:28:00 2010 for LTI-Lib by Doxygen 1.6.1