Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   Related Pages  

CConfig Class Reference

List of all members.

Detailed Description

Configuration files support.

Item in config file is represented by a name, a value and (optionally) a section it belongs. Names and sections are case sensitive. Section name is written in a separate line between '[' and ']' brackets; all items till next section belong to this section. All items before the very first section belong to all sections. Comments are written after '#' or ';' till end of line.

Program can optionally modify config file values (or append new ones), and they can be written back to the file (if writing is not disabled in the constructor).

Global game config file can be accesed via CEngine.

See also:
CEngine.


Public Types

typedef std::vector< int > TIntVector
 Vector of int's.

typedef std::vector< float > TFloatVector
 Vector of float's.

typedef std::vector< std::string > TStringVector
 Vector of std::string's.


Public Methods

 CConfig (const std::string &readName="default.cfg", bool write=false)
 Constructor.

 CConfig (const std::string &readName, const std::string &writeName)
 Constructor.

 ~CConfig ()
 Destructor.

std::string readS (const std::string &section, const std::string &name, const std::string &def)
 Read string from config.

int readI (const std::string &section, const std::string &name, int def)
 Read integer from config.

float readF (const std::string &section, const std::string &name, float def)
 Read float from config.

TStringVector readSn (const std::string &section, const std::string &name)
 Read strings from config (eg.

TIntVector readIn (const std::string &section, const std::string &name)
 Read ints from config (eg.

TFloatVector readFn (const std::string &section, const std::string &name)
 Read floats from config (eg.

void modifyS (const std::string &section, const std::string &name, const std::string &val)
 Sets item value as a string.

void modifyI (const std::string &section, const std::string &name, int val)
 Sets item value as an integer.

void modifyF (const std::string &section, const std::string &name, float val)
 Sets item value as a float.


Constructor & Destructor Documentation

CConfig::CConfig const std::string &    readName = "default.cfg",
bool    write = false
 

Constructor.

Parameters:
readName  Name of the config file.
write  If true, then modified/appended values are written back to the file.

CConfig::CConfig const std::string &    readName,
const std::string &    writeName
 

Constructor.

Parameters:
readName  Name of the config file.
writeName  Name of new config file that contains the original values and the modified/added ones.

CConfig::~CConfig  
 

Destructor.

Writing of modified/added values happens upon destruction only!


Member Function Documentation

void CConfig::modifyF const std::string &    section,
const std::string &    name,
float    val
 

Sets item value as a float.

Modifies existing one or appends.

Parameters:
section  The section of the item.
name  The name of the item.
val  The new value.

void CConfig::modifyI const std::string &    section,
const std::string &    name,
int    val
 

Sets item value as an integer.

Modifies existing one or appends.

Parameters:
section  The section of the item.
name  The name of the item.
val  The new value.

void CConfig::modifyS const std::string &    section,
const std::string &    name,
const std::string &    val
 

Sets item value as a string.

Modifies existing one or appends.

Parameters:
section  The section of the item.
name  The name of the item.
val  The new value.

float CConfig::readF const std::string &    section,
const std::string &    name,
float    def
 

Read float from config.

Parameters:
section  The section to take item from.
name  The name of the item.
def  The default value (if needed item isn't present).

CConfig::TFloatVector CConfig::readFn const std::string &    section,
const std::string &    name
 

Read floats from config (eg.

name = 14.5 -3.0 3.1415927).

Parameters:
section  The section to take item from.
name  The name of the item.

int CConfig::readI const std::string &    section,
const std::string &    name,
int    def
 

Read integer from config.

Parameters:
section  The section to take item from.
name  The name of the item.
def  The default value (if needed item isn't present).

CConfig::TIntVector CConfig::readIn const std::string &    section,
const std::string &    name
 

Read ints from config (eg.

name = 1 -7 124).

Parameters:
section  The section to take item from.
name  The name of the item.

std::string CConfig::readS const std::string &    section,
const std::string &    name,
const std::string &    def
 

Read string from config.

Parameters:
section  The section to take item from.
name  The name of the item.
def  The default value (if needed item isn't present).

CConfig::TStringVector CConfig::readSn const std::string &    section,
const std::string &    name
 

Read strings from config (eg.

name = abc ghty llkfj).

Parameters:
section  The section to take item from.
name  The name of the item.


Generated on Thu Dec 5 17:27:58 2002 for LT Game Jam Session by doxygen1.2.17