XML Configuration Structure. More...

#include <rconfig.h>

Collaboration diagram for RConfig:
[legend]

Public Member Functions

 RConfig (void)
 
 RConfig (bool dirs, const RString &param1, const RString &param2=RString::Null)
 
void SetParams (bool dirs, const RString &param1, const RString &param2=RString::Null)
 
void Load (lParams *cat, RXMLTag *tag)
 
void Save (lParams *cat, RXMLStruct &config, RXMLTag *parent)
 
void Load (bool global=true, bool exist=false)
 
void Save (void)
 
RCursor< RParamGetParams (const RString &cat=RString::Null, const RString &subcat=RString::Null, const RString &subsubcat=RString::Null)
 
void GetCategories (RContainer< RString, true, false > &cats, const RString &cat=RString::Null, const RString &subcat=RString::Null)
 
template<class T >
T * FindParam (const RString &name, const RString &cat=RString::Null, const RString &subcat=RString::Null, const RString &subsubcat=RString::Null)
 
void InsertParam (RParam *param, const RString &cat=RString::Null, const RString &subcat=RString::Null, const RString &subsubcat=RString::Null)
 
void Reset (const RString &name, const RString &cat=RString::Null, const RString &subcat=RString::Null, const RString &subsubcat=RString::Null)
 
RString Get (const RString &name, const RString &cat=RString::Null, const RString &subcat=RString::Null, const RString &subsubcat=RString::Null)
 
int GetInt (const RString &name, const RString &cat=RString::Null, const RString &subcat=RString::Null, const RString &subsubcat=RString::Null)
 
unsigned int GetUInt (const RString &name, const RString &cat=RString::Null, const RString &subcat=RString::Null, const RString &subsubcat=RString::Null)
 
long GetLong (const RString &name, const RString &cat=RString::Null, const RString &subcat=RString::Null, const RString &subsubcat=RString::Null)
 
unsigned long GetULong (const RString &name, const RString &cat=RString::Null, const RString &subcat=RString::Null, const RString &subsubcat=RString::Null)
 
double GetDouble (const RString &name, const RString &cat=RString::Null, const RString &subcat=RString::Null, const RString &subsubcat=RString::Null)
 
bool GetBool (const RString &name, const RString &cat=RString::Null, const RString &subcat=RString::Null, const RString &subsubcat=RString::Null)
 
RCursor< RStringGetList (const RString &name, const RString &cat=RString::Null, const RString &subcat=RString::Null, const RString &subsubcat=RString::Null)
 
RCursor< RParamGetStruct (const RString &name, const RString &cat=RString::Null, const RString &subcat=RString::Null, const RString &subsubcat=RString::Null)
 
void Set (const RString &name, const RString &v, const RString &cat=RString::Null, const RString &subcat=RString::Null, const RString &subsubcat=RString::Null)
 
void SetInt (const RString &name, int v, const RString &cat=RString::Null, const RString &subcat=RString::Null, const RString &subsubcat=RString::Null)
 
void SetUInt (const RString &name, size_t v, const RString &cat=RString::Null, const RString &subcat=RString::Null, const RString &subsubcat=RString::Null)
 
void SetDouble (const RString &name, double v, const RString &cat=RString::Null, const RString &subcat=RString::Null, const RString &subsubcat=RString::Null)
 
void SetBool (const RString &name, bool v, const RString &cat=RString::Null, const RString &subcat=RString::Null, const RString &subsubcat=RString::Null)
 
void AddToList (const RString &name, const RString &v, const RString &cat=RString::Null, const RString &subcat=RString::Null, const RString &subsubcat=RString::Null)
 
void AddToStruct (const RString &name, RParam *param, const RString &cat=RString::Null, const RString &subcat=RString::Null, const RString &subsubcat=RString::Null)
 
virtual ~RConfig (void)
 

Private Member Functions

void Analyze (RXMLTag *tag, lParams *cat)
 
RParamGetParam (const RString &name, const RString &cat, const RString &subcat, const RString &subsubcat)
 

Private Attributes

bool Dirs
 
RString Param1
 
RString Param2
 
lParams * Root
 

Detailed Description

XML Configuration Structure.

The RConfig class provides a representation for a XML structure representing a set of parameters that can load from and store.

The parameters should be declare (with the InsertParam method) before the structure is loaded. Parameters that are in the file but not declared are lost.

To each instance, two directory can be specified : a local one that is modified, and a global one that can propose default values. There are two ways to specify the directories: (a) specify their names, (b) provides a category and a name. In this latest case, default directory names are built. In particular, the local file is managed in the ".r/config" subdirectory in the home directory of the user running the corresponding program.

Constructor & Destructor Documentation

RConfig ( void  )

Default constructor. In practice, it does nothing. The method Set should be called before the methods Load and Save.

RConfig ( bool  dirs,
const RString param1,
const RString param2 = RString::Null 
)

Constructor.

Parameters
dirsSpecify if the parameters are directories or a pair (name,category).
param1Local directory or configuration name ('/' are replaced by '-').
param2Global directory of category name.
virtual ~RConfig ( void  )
virtual

Destructor.

Member Function Documentation

void SetParams ( bool  dirs,
const RString param1,
const RString param2 = RString::Null 
)

Set the parameters.

Parameters
dirsSpecify if the parameters are directories or a pair (name,category).
param1Local directory or configuration name ('/' are replaced by '-').
param2Global directory of category name.
void Analyze ( RXMLTag tag,
lParams *  cat 
)
private

Analyze a tag that is supposed to represent a parameter if a given category.

Parameters
tagTag.
catCategory.
void Load ( lParams *  cat,
RXMLTag tag 
)

Load a given category (and its parameters and sub-categories).

Parameters
catCategory to load.
tagTag coming from the XML file.
void Save ( lParams *  cat,
RXMLStruct config,
RXMLTag parent 
)

Save a given category (and its parameters and sub-categories).

Parameters
catCategory to save.
configXML configuration file.
parentParent tag in the configuration.
void Load ( bool  global = true,
bool  exist = false 
)

Load a file in the structure.

Parameters
globalGlobal configuration file must be searched?
existShould the configuration file exists?
void Save ( void  )

Save a file in the structure.

RParam* GetParam ( const RString name,
const RString cat,
const RString subcat,
const RString subsubcat 
)
private

Get the name of the configuration. Get the category of the configuration. Find a given parameter.

Parameters
nameName of the parameter.
catCategory of the parameter.
subcatSub-category of the parameter.
subsubcatSub-Sub-category of the parameter.
Returns
Pointer or null if not found.
RCursor<RParam> GetParams ( const RString cat = RString::Null,
const RString subcat = RString::Null,
const RString subsubcat = RString::Null 
)
Returns
a cursor over the parameters.
Parameters
catCategory of the parameter.
subcatSub-category of the parameter.
subsubcatSub-Sub-category of the parameter.
void GetCategories ( RContainer< RString, true, false > &  cats,
const RString cat = RString::Null,
const RString subcat = RString::Null 
)

Fill a container with the categories name.

Parameters
catsContainer that will be filled (it is emptied by the method).
catCategory of the parameter.
subcatSub-category of the parameter.
T* FindParam ( const RString name,
const RString cat = RString::Null,
const RString subcat = RString::Null,
const RString subsubcat = RString::Null 
)

Find a given parameter (template version).

Template Parameters
TType of the parameter.
Parameters
nameName of the parameter.
catCategory of the parameter.
subcatSub-category of the parameter.
subsubcatSub-Sub-category of the parameter.
Returns
Pointer or null if not found.
void InsertParam ( RParam param,
const RString cat = RString::Null,
const RString subcat = RString::Null,
const RString subsubcat = RString::Null 
)

Declare a new parameter. If it exist, the parameter passed as argument is deleted.

Parameters
paramParameter.
catCategory of the parameter.
subcatSub-category of the parameter.
subsubcatSub-Sub-category of the parameter.
void Reset ( const RString name,
const RString cat = RString::Null,
const RString subcat = RString::Null,
const RString subsubcat = RString::Null 
)

Reset a parameter with a given name and from a given category.

Parameters
nameName of the parameter.
catCategory of the parameter.
subcatSub-category of the parameter.
subsubcatSub-Sub-category of the parameter.
RString Get ( const RString name,
const RString cat = RString::Null,
const RString subcat = RString::Null,
const RString subsubcat = RString::Null 
)
Returns
the content of the parameter.
Parameters
nameName of the parameter.
catCategory of the parameter.
subcatSub-category of the parameter.
subsubcatSub-Sub-category of the parameter.
int GetInt ( const RString name,
const RString cat = RString::Null,
const RString subcat = RString::Null,
const RString subsubcat = RString::Null 
)
Returns
the content of the parameter.
Parameters
nameName of the parameter.
catCategory of the parameter.
subcatSub-category of the parameter.
subsubcatSub-Sub-category of the parameter.
unsigned int GetUInt ( const RString name,
const RString cat = RString::Null,
const RString subcat = RString::Null,
const RString subsubcat = RString::Null 
)
Returns
the content of the parameter.
Parameters
nameName of the parameter.
catCategory of the parameter.
subcatSub-category of the parameter.
subsubcatSub-Sub-category of the parameter.
long GetLong ( const RString name,
const RString cat = RString::Null,
const RString subcat = RString::Null,
const RString subsubcat = RString::Null 
)
Returns
the content of the parameter.
Parameters
nameName of the parameter.
catCategory of the parameter.
subcatSub-category of the parameter.
subsubcatSub-Sub-category of the parameter.
unsigned long GetULong ( const RString name,
const RString cat = RString::Null,
const RString subcat = RString::Null,
const RString subsubcat = RString::Null 
)
Returns
the content of the parameter.
Parameters
nameName of the parameter.
catCategory of the parameter.
subcatSub-category of the parameter.
subsubcatSub-Sub-category of the parameter.
double GetDouble ( const RString name,
const RString cat = RString::Null,
const RString subcat = RString::Null,
const RString subsubcat = RString::Null 
)

Get the content of the parameter.

Parameters
nameName of the parameter.
catCategory of the parameter.
subcatSub-category of the parameter.
subsubcatSub-Sub-category of the parameter.
Returns
double.
bool GetBool ( const RString name,
const RString cat = RString::Null,
const RString subcat = RString::Null,
const RString subsubcat = RString::Null 
)
Returns
the content of the parameter.
Parameters
nameName of the parameter.
catCategory of the parameter.
subcatSub-category of the parameter.
subsubcatSub-Sub-category of the parameter.
RCursor<RString> GetList ( const RString name,
const RString cat = RString::Null,
const RString subcat = RString::Null,
const RString subsubcat = RString::Null 
)

Get the content of a list.

Parameters
nameName of the list.
catCategory of the list.
subcatSub-category of the parameter.
subsubcatSub-Sub-category of the parameter.
Returns
Cursor of string.
RCursor<RParam> GetStruct ( const RString name,
const RString cat = RString::Null,
const RString subcat = RString::Null,
const RString subsubcat = RString::Null 
)

Get the content of a structure.

Parameters
nameName of the structure.
catCategory of the structure.
subcatSub-category of the parameter.
subsubcatSub-Sub-category of the parameter.
Returns
Cursor of parameters.
void Set ( const RString name,
const RString v,
const RString cat = RString::Null,
const RString subcat = RString::Null,
const RString subsubcat = RString::Null 
)

Set the content of the parameter.

Parameters
nameName of the parameter.
vValue of the parameter.
catCategory of the parameter.
subcatSub-category of the parameter.
subsubcatSub-Sub-category of the parameter.
void SetInt ( const RString name,
int  v,
const RString cat = RString::Null,
const RString subcat = RString::Null,
const RString subsubcat = RString::Null 
)

Set the content of the parameter.

Parameters
nameName of the parameter.
vValue of the parameter.
catCategory of the parameter.
subcatSub-category of the parameter.
subsubcatSub-Sub-category of the parameter.
void SetUInt ( const RString name,
size_t  v,
const RString cat = RString::Null,
const RString subcat = RString::Null,
const RString subsubcat = RString::Null 
)

Set the content of the parameter.

Parameters
nameName of the parameter.
vValue of the parameter.
catCategory of the parameter.
subcatSub-category of the parameter.
subsubcatSub-Sub-category of the parameter.
void SetDouble ( const RString name,
double  v,
const RString cat = RString::Null,
const RString subcat = RString::Null,
const RString subsubcat = RString::Null 
)

Set the content of the parameter.

Parameters
nameName of the parameter.
vValue of the parameter.
catCategory of the parameter.
subcatSub-category of the parameter.
subsubcatSub-Sub-category of the parameter.
void SetBool ( const RString name,
bool  v,
const RString cat = RString::Null,
const RString subcat = RString::Null,
const RString subsubcat = RString::Null 
)

Set the content of the parameter.

Parameters
nameName of the parameter.
vValue of the parameter.
catCategory of the parameter.
subcatSub-category of the parameter.
subsubcatSub-Sub-category of the parameter.
void AddToList ( const RString name,
const RString v,
const RString cat = RString::Null,
const RString subcat = RString::Null,
const RString subsubcat = RString::Null 
)

Add a value to a list.

Parameters
nameName of the parameter.
vValue of the parameter.
catCategory of the parameter.
subcatSub-category of the parameter.
subsubcatSub-Sub-category of the parameter.
void AddToStruct ( const RString name,
RParam param,
const RString cat = RString::Null,
const RString subcat = RString::Null,
const RString subsubcat = RString::Null 
)

Add a parameter to a structure.

Parameters
nameName of the structure.
paramParameter.
catCategory of the structure.
subcatSub-category of the parameter.
subsubcatSub-Sub-category of the parameter.

Field Documentation

bool Dirs
private

Are the parameters directories or a pair (category,name).

RString Param1
private

Parameter 1.

RString Param2
private

Global file name.

lParams* Root
private

Root of all parameters.