Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   Namespace Members   Compound Members  

PLMConfigMgr Class Reference

Configuration manager. More...

#include <PLMConfig.hpp>

List of all members.

Public Types

enum  ValType

Public Methods

 PLMConfigMgr (u32 startsize=5)
 ~PLMConfigMgr ()
u32 NbParameters () const
bool DeclareBool (const char *name, bool defval)
bool DeclareInt (const char *name, int defval)
bool DeclareColor (const char *name, PLMColor defval)
bool DeclareDate (const char *name, time_t defval)
bool DeclareFloat (const char *name, float defval)
bool DeclareString (const char *name, const char *defval)
bool RemoveParameter (const char *name)
int ParamType (const char *name)
bool ParseCL (int argc, char **argv)
bool ParseFile (const char *file)
bool Save (const char *filename, const char *title=0) const
bool GetBool (const char *name) const
int GetInt (const char *name) const
PLMColor GetColor (const char *name) const
time_t GetDate (const char *name) const
float GetFloat (const char *name) const
const char * GetString (const char *name) const
bool SetBool (const char *name, bool val, bool force=false)
bool SetInt (const char *name, int val, bool force=false)
bool SetColor (const char *name, PLMColor val, bool force=false)
bool SetDate (const char *name, time_t val, bool force=false)
bool SetFloat (const char *name, float val, bool force=false)
bool SetString (const char *name, const char *val, bool force=false)
void PrintInfo () const

Protected Methods

bool AddParameter (const char *name, int type, CfgValue defval)
CfgValue GetValue (const char *name, int type) const
CfgCellGetCell (const char *name) const
bool SetValue (const char *name, int type, CfgValue val, bool force=false)
bool Find (const char *name, u32 &idx) const


Detailed Description

Configuration manager.

This class allows an application to easily define global parameters with different data types (boolean, integer, floating point or string). A parameter is basically a name associated with a value. A parameter must be declared (with Declare*()) before it can be used. It can then be accessed or modified (read/write) with Get*()/Set*() methods.

The values can be read from the program command line, or from a config file (a simple text file), and saved to a file.

Syntax:

  • Names of parameters: they are not case dependant (name = NAME = nAmE) and can not contain any space (or tab). Also, it should not begin with '-' or contain any system-forbidden characters like '*&<>' ... since it would make it difficult to read it from the command line.
  • On the command line, parameters must start by a '-' and the next argument gives its value, ex: "program -width 800 -height 600".
  • In the file, each line must contain only one parameter, in the form '<param-name> <value>' Name and value can be separated by one or many spaces (or tabs). Empty lines and lines starting by '#' (comments) are simply ignored.
  • boolean : '1', 'true', 'yes' means true, any other value means false
  • integer and float : standard values
  • string : no
    allowed, and do not forget to use quotes on the command line if it contains spaces
  • color : RRGGBB[AA] where RR,GG,BB,AA are red, green, blue and optionnaly alpha components in hexadecimal base
  • date : YYYY/MM/DD [HH:MM[:SS]] add a 0 before values < 10, and use quotes on the command line
Notes :
  • parameters _must_ be declared (by calling Declare*()) before using ParseCL() or ParseFile(). Otherwise unknown parameters will be ignored.
  • to ask for a parameter value with the wrong type is considered as an error (ex: calling GetInt() on anything but an int, even a boolean).


Member Enumeration Documentation

enum PLMConfigMgr::ValType
 

Types of parameters (data type).


Constructor & Destructor Documentation

PLMConfigMgr::PLMConfigMgr u32    startsize = 5
 

Create a new configuration manager and allocate startsize cells.

PLMConfigMgr::~PLMConfigMgr  
 

Delete all existing parameters and values.


Member Function Documentation

u32 PLMConfigMgr::NbParameters   [inline]
 

Get current number of parameters defined.

bool PLMConfigMgr::DeclareBool const char *    name,
bool    defval
[inline]
 

Add a new boolean parameter named name, with default value defval.

Returns:
false if the name is already used.

bool PLMConfigMgr::DeclareInt const char *    name,
int    defval
[inline]
 

Add a new integer parameter named name, with default value defval.

Returns:
false if the name is already used.

bool PLMConfigMgr::DeclareColor const char *    name,
PLMColor    defval
[inline]
 

Add a new color parameter named name, with default value defval.

Returns:
false if the name is already used.

bool PLMConfigMgr::DeclareDate const char *    name,
time_t    defval
[inline]
 

Add a new integer parameter named name, with default value defval.

Returns:
false if the name is already used.

bool PLMConfigMgr::DeclareFloat const char *    name,
float    defval
[inline]
 

Add a new float parameter named name, with default value defval.

Returns:
false if the name is already used.

bool PLMConfigMgr::DeclareString const char *    name,
const char *    defval
[inline]
 

Add a new string parameter named name, with default value defval.

A copy of the string is stored, so defval can be modified/deleted. Important: the value may contain any character but no line separator (
).

Returns:
false if the name is already used.

bool PLMConfigMgr::RemoveParameter const char *    name
 

Remove an existing parameter. Return false if not found.

int PLMConfigMgr::ParamType const char *    name
 

Return the data type of parameter named name.

Return a ValType enum, VAL_UNKNOWN if the name is not found.

bool PLMConfigMgr::ParseCL int    argc,
char **    argv
 

Update the values of current parameters with the parameters read from the application's command line.

Unknown parameters are ignored.

Parameters:
argc  the number of strings in argv (from main).
argv  an array of strings, each string contains one argument, like the parameter of main().
Returns:
false if at least one parameter was unknown or a value was missing.

bool PLMConfigMgr::ParseFile const char *    file
 

Update the values of current parameters with the values read from the file.

Undeclared parameters found in the file are ignored.

Parameters:
file  the name of a configuration file, containing parameters definitions in the form : <param> <value> on each lines. See the class description for details.
Returns:
false if the file can not be read, or if no values are defined. Return true if at least one valid value is found.

bool PLMConfigMgr::Save const char *    filename,
const char *    title = 0
const
 

Save current values to the file filename.

Parameters:
filename  the name of the configuration file to create, if this file already exists, it is overwritten.
title  an optional string printed in the header of the file as a comment to give some informations (ex: author, date, ...).
Returns:
false if the file can not be created.

bool PLMConfigMgr::GetBool const char *    name const [inline]
 

Get the current value of the boolean parameter named name.

int PLMConfigMgr::GetInt const char *    name const [inline]
 

Get the current value of the integer parameter named name.

PLMColor PLMConfigMgr::GetColor const char *    name const [inline]
 

Get the current value of the integer parameter named name.

time_t PLMConfigMgr::GetDate const char *    name const [inline]
 

Get the current value of the integer parameter named name.

float PLMConfigMgr::GetFloat const char *    name const [inline]
 

Get the current value of the float parameter named name.

const char * PLMConfigMgr::GetString const char *    name const [inline]
 

Get the current value of the string parameter named name.

Never modify or delete this string, use SetString() for this.

bool PLMConfigMgr::SetBool const char *    name,
bool    val,
bool    force = false
[inline]
 

Change the value of the parameter name with val.

Modification is canceled if current type is not boolean, unless force is true, which also changes the type.

Returns:
false if name is not found or if the type is wrong.

bool PLMConfigMgr::SetInt const char *    name,
int    val,
bool    force = false
[inline]
 

Change the value of the parameter name with val.

Modification is canceled if current type is not integer, unless force is true, which also changes the type.

Returns:
false if name is not found or if the type is wrong.

bool PLMConfigMgr::SetColor const char *    name,
PLMColor    val,
bool    force = false
[inline]
 

Change the value of the parameter name with val.

Modification is canceled if current type is not Color, unless force is true, which also changes the type.

Returns:
false if name is not found or if the type is wrong.

bool PLMConfigMgr::SetDate const char *    name,
time_t    val,
bool    force = false
[inline]
 

Change the value of the parameter name with val.

Modification is canceled if current type is not Date, unless force is true, which also changes the type.

Returns:
false if name is not found or if the type is wrong.

bool PLMConfigMgr::SetFloat const char *    name,
float    val,
bool    force = false
[inline]
 

Change the value of the parameter name with val.

Modification is canceled if current type is not float, unless force is true, which also changes the type.

Returns:
false if name is not found or if the type is wrong.

bool PLMConfigMgr::SetString const char *    name,
const char *    val,
bool    force = false
[inline]
 

Change the value of the parameter name with val.

The given string is copied internally. Modification is canceled if current type is not String, unless force is true, which also changes the type.

Returns:
false if name is not found or if the type is wrong.

void PLMConfigMgr::PrintInfo  
 

Print some debug info on current log.

bool PLMConfigMgr::AddParameter const char *    name,
int    type,
CfgValue    defval
[protected]
 

Add a new declaration with a default value. Return false if it already exists.

CfgValue PLMConfigMgr::GetValue const char *    name,
int    type
const [protected]
 

Get the value associated with name, or a null value if not found (means false/0/NULL).

CfgCell* PLMConfigMgr::GetCell const char *    name const [protected]
 

Get the cell associated with name, or NULL if not found.

bool PLMConfigMgr::SetValue const char *    name,
int    type,
CfgValue    val,
bool    force = false
[protected]
 

Change the value of the parameter named name.

The new value is given by val, and its type by type. If the new type does not match the declared type, nothing is modified and it returns false, unless force is true, which forces the new value to be assigned and the type to be changed.

Parameters:
name  name of the parameter to modify (must exist)
type  data type of the parameter (see ValType enum)
val  the new value (must be of type type)
force  true means that the new type and value must be assigned even if the old type is different (new type is then type).
Returns:
true on success, false if the parameter does not exist or if the type is wrong and force is false.

bool PLMConfigMgr::Find const char *    name,
u32 &    idx
const [protected]
 

Check if a parameter named name exists.

Returns:
true if found and set its internal cell index in idx. Return false if not found and put in idx the index where it should be.


The documentation for this class was generated from the following file:
  • PLMConfig.hpp

Generated by Doxygen 1.2.18 on Tue Oct 26 12:07:43 2004.