Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | Related Pages | Examples

Config Class Reference
[Configuration file support]

#include <tinycfg.h>

Inheritance diagram for Config:

Inheritance graph
[legend]
Collaboration diagram for Config:

Collaboration graph
[legend]
List of all members.

Detailed Description

The wrapper to hide implementation details (and bridge between an old config file format). From the version of the OpenGUI 5.0.2 up, is Config file provided by separate library called 'tinycfg'. It is based on LGPL library from Lee Thomason and Yves Berquincalled - 'tinyxml'. TINYXML HOMEPAGE: www.sourceforge.net/projects/tinyxml

This object saves and restores variables or arrays of basic types to XML file. There are possibilities to write all primitive data types:

You can write all these data types as ordinary variable or as an array of of one. I.e. you can write entire array of doubles within one line!

    config->WriteDoubleArray("an_array", array_of_doubles, sizeof(array_of_doubles)/sizeof(double) );

One big plus of this implementation is that uses 'namespaces' or 'domain' to save one variable name from other to colide:

    bool foo = true;
    config->WriteBool("foo", foo);
    foo = false;
    config->WriteBool("foo", foo, "foo.bar");

    generated file:

    <?xml version="1.0" standalone="no" ?>
    <tinycfg>
        <bool name="foo" val="true" />
        <foo>
            <bar>
                <bool name="foo" val="false" />
            </bar>
        </foo>
    </tinycfg>
These two writes uses its own namespaces. The default namespace is 0 (no parameter) for the root of config file.

See also:
Basic XML support
Examples:

testconfig.cpp.


Public Member Functions

 Config (bool write=true)
 Config (char *, bool write=true)
virtual ~Config ()
bool IsValid (void)
virtual bool Load (char *fname)
virtual bool Save (void)
virtual bool ReadBool (char *name, bool &data, const char *domain=0)
virtual bool ReadInt (char *name, int &data, const char *domain=0)
virtual bool ReadString (char *name, char *data, int max, const char *domain=0)
virtual bool ReadDouble (char *name, double &data, const char *domain=0)
virtual bool ReadHex (char *name, char *data, int length_of_item, const char *domain=0)
virtual bool ReadBoolArray (char *name, bool data[], int range, const char *domain=0)
virtual bool ReadIntArray (char *name, int data[], int range, const char *domain=0)
virtual bool ReadStringArray (char *name, char *data[], int max, int range, const char *domain=0)
virtual bool ReadDoubleArray (char *name, double data[], int range, const char *domain=0)
virtual bool ReadHexArray (char *name, char *data[], int length_of_item, int range, const char *domain=0)
virtual void WriteBool (char *name, bool data, const char *domain=0)
virtual void WriteInt (char *name, int data, const char *domain=0)
virtual void WriteString (char *name, char *data, const char *domain=0)
virtual void WriteDouble (char *name, double data, const char *domain=0)
virtual void WriteHex (char *name, char *data, int length_of_item, const char *domain=0)
virtual void WriteBoolArray (char *name, bool data[], int range, const char *domain=0)
virtual void WriteIntArray (char *name, int data[], int range, const char *domain=0)
virtual void WriteStringArray (char *name, char *data[], int range, const char *domain=0)
virtual void WriteDoubleArray (char *name, double data[], int range, const char *domain=0)
virtual void WriteHexArray (char *name, char *data[], int length_of_item, int range, const char *domain=0)


Constructor & Destructor Documentation

Config::Config bool  write = true  ) 
 

Creates the new and empty config object.

Parameters:
write the flag for object writing, false = read-only object.

Config::Config char *  s,
bool  write = true
 

Creates and loads the config object from the file.

Parameters:
s the file name
write the flag for object writing, false = read-only object.

Config::~Config  )  [virtual]
 

Destruct object. The object will be saved if is 'writable' and state is 'changed'.


Member Function Documentation

bool Config::IsValid void   ) 
 

Returns:
true if object state is valid.

bool Config::Load char *  fname  )  [virtual]
 

Loads object from the file.

Parameters:
fname the file name
Returns:
true if object was correctly load from file.

Implements ConfigInterface.

bool Config::ReadBool char *  name,
bool &  data,
const char *  domain = 0
[virtual]
 

Reads an boolean variable from the config file.

Parameters:
name the symbolic name of variable
data where the value of the variable will be stored
domain the path where variable is stored
Returns:
true if variable was found and loaded correctly to the data parameter. If false the 'data' parameter is untouched.

Implements ConfigInterface.

bool Config::ReadBoolArray char *  name,
bool  data[],
int  range,
const char *  domain = 0
[virtual]
 

Reads an array of boolean from the config file.

Parameters:
name the symbolic name of variable
data where the value of the variable will be stored
range the number of items to read
domain the path where variable is stored
Returns:
true if variable was found and loaded correctly to the data parameter. If false the 'data' parameter is untouched.

Implements ConfigInterface.

bool Config::ReadDouble char *  name,
double &  data,
const char *  domain = 0
[virtual]
 

Reads a double variable from the config file.

Parameters:
name the symbolic name of variable
data where the value of the variable will be stored
domain the path where variable is stored
Returns:
true if variable was found and loaded correctly to the data parameter. If false the 'data' parameter is untouched.

Implements ConfigInterface.

bool Config::ReadDoubleArray char *  name,
double  data[],
int  range,
const char *  domain = 0
[virtual]
 

Reads an array of double from the config file.

Parameters:
name the symbolic name of variable
data where the value of the variable will be stored
range the number of items to read
domain the path where variable is stored
Returns:
true if variable was found and loaded correctly to the data parameter. If false the 'data' parameter is untouched.

Implements ConfigInterface.

bool Config::ReadHex char *  name,
char *  data,
int  size,
const char *  domain = 0
[virtual]
 

Reads a block of binary data from the config file.

Parameters:
name the symbolic name of variable
data the pointer where the data will be stored
size the size of allocated memory for data (max 512)
domain the path where variable is stored
Returns:
true if variable was found, memory size fits its size and loaded correctly to the data parameter. If false the 'data' parameter is untouched.

Implements ConfigInterface.

bool Config::ReadHexArray char *  name,
char *  data[],
int  length_of_item,
int  range,
const char *  domain = 0
[virtual]
 

Reads an array of binary items from the config file.

Parameters:
name the symbolic name of variable
data an array of pointers to char - the pointers must be set to already allocated memory.
length_of_item the size of allocated memory for each one object
range the number of items to read
domain the path where variable is stored
Returns:
true if variable was found and loaded correctly to the data parameter. If false the 'data' parameter is untouched.

Implements ConfigInterface.

bool Config::ReadInt char *  name,
int &  data,
const char *  domain = 0
[virtual]
 

Reads an integer variable from the config file.

Parameters:
name the symbolic name of variable
data where the value of the variable will be stored
domain the path where variable is stored
Returns:
true if variable was found and loaded correctly to the data parameter. If false the 'data' parameter is untouched.

Implements ConfigInterface.

bool Config::ReadIntArray char *  name,
int  data[],
int  range,
const char *  domain = 0
[virtual]
 

Reads an array of integer from the config file.

Parameters:
name the symbolic name of variable
data where the value of the variable will be stored
range the number of items to read
domain the path where variable is stored
Returns:
true if variable was found and loaded correctly to the data parameter. If false the 'data' parameter is untouched.

Implements ConfigInterface.

bool Config::ReadString char *  name,
char *  data,
int  max,
const char *  domain = 0
[virtual]
 

Reads a string variable from the config file.

Parameters:
name the symbolic name of variable
data the pointer where the string will be stored
max the size of allocated memory for string
domain the path where variable is stored
Returns:
true if variable was found, memory size fits its size and loaded correctly to the data parameter. If false the 'data' parameter is untouched.

Implements ConfigInterface.

bool Config::ReadStringArray char *  name,
char *  data[],
int  max,
int  range,
const char *  domain = 0
[virtual]
 

Reads an array of char* from the config file.

Parameters:
name the symbolic name of variable
data an array of pointers to char - the pointers must be set to already allocated memory.
max the size of allocated memory for each one string
range the number of items to read
domain the path where variable is stored
Returns:
true if variable was found and loaded correctly to the data parameter. If false the 'data' parameter is untouched.

Implements ConfigInterface.

bool Config::Save void   )  [virtual]
 

Saves the object if is 'writable' and state is 'changed'.

Returns:
true if object was correctly load from file.

Implements ConfigInterface.

void Config::WriteBool char *  name,
bool  val,
const char *  domain = 0
[virtual]
 

Writes an item of type boolean with the 'name' to the config object (to save to the file use Config::Save() )

Parameters:
name the name of variable
val the value to write (true or false)
domain the path where variable will be stored
See also:
Config::Config()

Implements ConfigInterface.

void Config::WriteBoolArray char *  name,
bool  data[],
int  range,
const char *  domain = 0
[virtual]
 

Writes an array of boolean type with name and range.

Parameters:
name the name of variable
data data array to write
range the number of items in the array
domain the path where variable will be stored

Implements ConfigInterface.

void Config::WriteDouble char *  name,
double  val,
const char *  domain = 0
[virtual]
 

Writes an item of type 'double' with the 'name' to the config object (to save to the file use Config::Save() )

Parameters:
name the name of variable
val the value to write
domain the path where variable will be stored
See also:
Config::Config()

Implements ConfigInterface.

void Config::WriteDoubleArray char *  name,
double  data[],
int  range,
const char *  domain = 0
[virtual]
 

Writes an array of double type with name and range.

Parameters:
name the name of variable
data data array to write
range the number of items in the array
domain the path where variable will be stored

Implements ConfigInterface.

void Config::WriteHex char *  name,
char *  val,
int  len,
const char *  domain = 0
[virtual]
 

Writes an item of type 'char *' with the 'name' to the config object (to save to the file use Config::Save() ). This saves memory contents as HEXADECIMAL string. Bytes 00ff00 will be writed as "00FF00" ascii string.

Parameters:
name the name of variable
val the value to write ( C integer )
len the size of object in bytes to write (max. 512 bytes)
domain the path where variable will be stored
See also:
Config::Config()

Implements ConfigInterface.

void Config::WriteHexArray char *  name,
char *  data[],
int  length_of_item,
int  range,
const char *  domain = 0
[virtual]
 

Writes an array of char* as binary data type with name and range.

Parameters:
name the name of variable
data data array to write
length_of_item the sizeof of one data item
range the number of items in the array
domain the path where variable will be stored

Implements ConfigInterface.

void Config::WriteInt char *  name,
int  val,
const char *  domain = 0
[virtual]
 

Writes an item of type 'int' with the 'name' to the config object (to save to the file use Config::Save() )

Parameters:
name the name of variable
val the value to write ( C integer )
domain the path where variable will be stored
See also:
Config::Config()

Implements ConfigInterface.

void Config::WriteIntArray char *  name,
int  data[],
int  range,
const char *  domain = 0
[virtual]
 

Writes an array of integer type with name and range.

Parameters:
name the name of variable
data data array to write
range the number of items in the array
domain the path where variable will be stored

Implements ConfigInterface.

void Config::WriteString char *  name,
char *  val,
const char *  domain = 0
[virtual]
 

Writes an item of type 'char *' with the 'name' to the config object (to save to the file use Config::Save() )

Parameters:
name the name of variable
val the string to write (a traditional ASCIIZ form)
domain the path where variable will be stored
See also:
Config::Config()

Implements ConfigInterface.

void Config::WriteStringArray char *  name,
char *  data[],
int  range,
const char *  domain = 0
[virtual]
 

Writes an array of char* type with name and range.

Parameters:
name the name of variable
data data array to write
range the number of items in the array
domain the path where variable will be stored

Implements ConfigInterface.


Generated on Wed Feb 9 11:31:35 2005 for OpenGUI by  doxygen 1.4.0