DUtils::ConfigFile Class Reference

Manages simple text-based configuration files. More...

#include <ConfigFile.h>

List of all members.

Public Member Functions

 ConfigFile (const char *filename, const FILE_MODES mode)
 ConfigFile (const std::string &filename, const FILE_MODES mode)
void OpenForReading (const char *filename)
void OpenForReading (const std::string &filename)
void OpenForWriting (const char *filename)
void OpenForWriting (const std::string &filename)
void OpenForAppending (const char *filename)
void OpenForAppending (const std::string &filename)
void Close ()
template<class T >
get (const std::string &name) const
template<class T >
get (const char *name) const
int sizeAnonymous () const
template<class T >
getAnonymous (int n) const
template<class T >
void put (const std::string &name, const T &data)
template<class T >
void put (const char *name, const T &data)

Protected Member Functions

void Init (const char *filename, const FILE_MODES mode)
void readContent ()
void writeContent ()
void resolveVariables ()
void resolveVar (std::string &value, const std::set< string > &used)

Protected Attributes

std::map< std::string,
std::string > 
m_data
 Data read from the file.
LineFile m_file
 File.
int m_unknowns
 Number of unknowns entries read.

Detailed Description

Manages simple text-based configuration files.


Constructor & Destructor Documentation

ConfigFile::ConfigFile ( const char *  filename,
const FILE_MODES  mode 
)

Creates a config file by opening a file

Parameters:
filename 
mode,: READ or WRITE
Exceptions:
DException if cannot open the file
DUtils::ConfigFile::ConfigFile ( const std::string &  filename,
const FILE_MODES  mode 
)

Creates a config file by opening a file

Parameters:
filename 
mode,: READ or WRITE
Exceptions:
DException if cannot open the file

Member Function Documentation

void ConfigFile::Close (  ) 

Closes any opened file. It is not necessary to call this function explicitly

template<class T >
T DUtils::ConfigFile::get ( const char *  name  )  const [inline]

Gets data from the file. Returns 0 or similar if it does not exist

Parameters:
name 
template<class T >
T DUtils::ConfigFile::get ( const std::string &  name  )  const [inline]

Gets data from the file. Returns 0 or similar if it does not exist.

Parameters:
name 
template<class T >
T DUtils::ConfigFile::getAnonymous ( int  n  )  const [inline]

Gets anonymous data from the file. Returns 0 or similar if it does not exist

Parameters:
n index of anonymous entry
void ConfigFile::Init ( const char *  filename,
const FILE_MODES  mode 
) [protected]

Initiates the file

void DUtils::ConfigFile::OpenForAppending ( const std::string &  filename  )  [inline]

Opens a file for writing at the end. It closes any other opened file

Parameters:
filename 
Exceptions:
DException if cannot open the file
void ConfigFile::OpenForAppending ( const char *  filename  ) 

Opens a file for writing at the end. It closes any other opened file

Parameters:
filename 
Exceptions:
DException if cannot open the file
void DUtils::ConfigFile::OpenForReading ( const std::string &  filename  )  [inline]

Opens a file for reading. It closes any other opened file

Parameters:
filename 
Exceptions:
DException if cannot create the file
void ConfigFile::OpenForReading ( const char *  filename  ) 

Opens a file for reading. It closes any other opened file

Parameters:
filename 
Exceptions:
DException if cannot create the file
void DUtils::ConfigFile::OpenForWriting ( const std::string &  filename  )  [inline]

Opens a file for writing. It closes any other opened file

Parameters:
filename 
Exceptions:
DException if cannot create the file
void ConfigFile::OpenForWriting ( const char *  filename  ) 

Opens a file for writing. It closes any other opened file

Parameters:
filename 
Exceptions:
DException if cannot create the file
template<class T >
void DUtils::ConfigFile::put ( const char *  name,
const T &  data 
) [inline]

Writes or overwrites a piece of data with the given name

Parameters:
name 
data 
template<class T >
void DUtils::ConfigFile::put ( const std::string &  name,
const T &  data 
) [inline]

Writes or overwrites a piece of data with the given name

Parameters:
name 
data 
void ConfigFile::readContent (  )  [protected]

Reads the content of the m_file already opened and stores it in m_data. This operation also resolves the possible name deferencing when using variables

void ConfigFile::resolveVar ( std::string &  value,
const std::set< string > &  used 
) [protected]

Resolves the value of a single variable

Parameters:
value the string value to modify
used the names of the tokens that cannot be replaced because of circular dependencies
void ConfigFile::resolveVariables (  )  [protected]

Resolves the value of the variables used as right-hand expressions

int DUtils::ConfigFile::sizeAnonymous (  )  const [inline]

Returns the number of anonymous entries when reading a file

Returns:
n
void ConfigFile::writeContent (  )  [protected]

Writes the items into the file


The documentation for this class was generated from the following files:
 All Classes Namespaces Functions Variables Enumerations Friends
Generated on Thu Feb 7 19:16:00 2013 by  doxygen 1.6.3