Yate
Public Member Functions
Configuration Class Reference

Configuration file handling. More...

#include <yatengine.h>

Inheritance diagram for Configuration:
String GenObject

List of all members.

Public Member Functions

 Configuration ()
 Configuration (const char *filename, bool warn=true)
Configurationoperator= (const String &value)
unsigned int sections () const
NamedListgetSection (unsigned int index) const
NamedListgetSection (const String &sect) const
NamedStringgetKey (const String &sect, const String &key) const
const char * getValue (const String &sect, const String &key, const char *defvalue=0) const
int getIntValue (const String &sect, const String &key, int defvalue=0, int minvalue=INT_MIN, int maxvalue=INT_MAX, bool clamp=true) const
int getIntValue (const String &sect, const String &key, const TokenDict *tokens, int defvalue=0) const
double getDoubleValue (const String &sect, const String &key, double defvalue=0.0) const
bool getBoolValue (const String &sect, const String &key, bool defvalue=false) const
void clearSection (const char *sect=0)
NamedListcreateSection (const String &sect)
void clearKey (const String &sect, const String &key)
void addValue (const String &sect, const char *key, const char *value=0)
void setValue (const String &sect, const char *key, const char *value=0)
void setValue (const String &sect, const char *key, int value)
void setValue (const String &sect, const char *key, bool value)
bool load (bool warn=true)
bool save () const

Detailed Description

Configuration file handling.

A class for parsing and quickly accessing INI style configuration files


Constructor & Destructor Documentation

Create an empty configuration

Configuration ( const char *  filename,
bool  warn = true 
) [explicit]

Create a configuration from a file

Parameters:
filenameName of file to initialize from
warnTrue to warn if the configuration could not be loaded

Member Function Documentation

void addValue ( const String sect,
const char *  key,
const char *  value = 0 
)

Add the value of a key in a section.

Parameters:
sectName of the section, will be created if missing
keyName of the key to add in the section
valueValue to set in the key
void clearKey ( const String sect,
const String key 
)

Deletes a key/value pair

Parameters:
sectName of section
keyName of the key to delete
void clearSection ( const char *  sect = 0)

Deletes an entire section

Parameters:
sectName of section to delete, NULL to delete all
NamedList* createSection ( const String sect)

Makes sure a section with a given name exists, creates if required

Parameters:
sectName of section to check or create
Returns:
The section's content or NULL if no such section
bool getBoolValue ( const String sect,
const String key,
bool  defvalue = false 
) const

Retrieve the boolean value of a key in a section.

Parameters:
sectName of the section
keyName of the key in section
defvalueDefault value to return if not found
Returns:
The boolean value contained in the key or the default
double getDoubleValue ( const String sect,
const String key,
double  defvalue = 0.0 
) const

Retrieve the floating point value of a key in a section.

Parameters:
sectName of the section
keyName of the key in section
defvalueDefault value to return if not found
Returns:
The numeric value contained in the key or the default
int getIntValue ( const String sect,
const String key,
int  defvalue = 0,
int  minvalue = INT_MIN,
int  maxvalue = INT_MAX,
bool  clamp = true 
) const

Retrieve the numeric value of a key in a section.

Parameters:
sectName of the section
keyName of the key in section
defvalueDefault value to return if not found
minvalueMinimum value allowed for the parameter
maxvalueMaximum value allowed for the parameter
clampControl the out of bound values: true to adjust to the nearest bound, false to return the default value
Returns:
The number contained in the key or the default
int getIntValue ( const String sect,
const String key,
const TokenDict tokens,
int  defvalue = 0 
) const

Retrieve the numeric value of a key in a section trying first a table lookup.

Parameters:
sectName of the section
keyName of the key in section
tokensA pointer to an array of tokens to try to lookup
defvalueDefault value to return if not found
Returns:
The number contained in the key or the default
NamedString* getKey ( const String sect,
const String key 
) const

Locate a key/value pair in the section.

Parameters:
sectName of the section
keyName of the key in section
Returns:
A pointer to the key/value pair or NULL.
NamedList* getSection ( unsigned int  index) const

Retrieve an entire section

Parameters:
indexIndex of the section
Returns:
The section's content or NULL if no such section
NamedList* getSection ( const String sect) const

Retrieve an entire section

Parameters:
sectName of the section
Returns:
The section's content or NULL if no such section
const char* getValue ( const String sect,
const String key,
const char *  defvalue = 0 
) const

Retrieve the value of a key in a section.

Parameters:
sectName of the section
keyName of the key in section
defvalueDefault value to return if not found
Returns:
The string contained in the key or the default
bool load ( bool  warn = true)

Load the configuration from file

Parameters:
warnTrue to also warn if the configuration could not be loaded
Returns:
True if successfull, false for failure
Configuration& operator= ( const String value) [inline]

Assignment from string operator

Reimplemented from String.

References String::operator=().

bool save ( ) const

Save the configuration to file

Returns:
True if successfull, false for failure
unsigned int sections ( ) const [inline]

Get the number of sections

Returns:
Count of sections
void setValue ( const String sect,
const char *  key,
const char *  value = 0 
)

Set the value of a key in a section.

Parameters:
sectName of the section, will be created if missing
keyName of the key in section, will be created if missing
valueValue to set in the key
void setValue ( const String sect,
const char *  key,
int  value 
)

Set the numeric value of a key in a section.

Parameters:
sectName of the section, will be created if missing
keyName of the key in section, will be created if missing
valueValue to set in the key
void setValue ( const String sect,
const char *  key,
bool  value 
)

Set the boolean value of a key in a section.

Parameters:
sectName of the section, will be created if missing
keyName of the key in section, will be created if missing
valueValue to set in the key

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