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

BaseConfig Class Reference

abstract base class config. More...

#include <appconf.h>

Inheritance diagram for BaseConfig:

Inheritance graph
[legend]
List of all members.

Set and retrieve current path

virtual void setCurrentPath (const char *szPath="")
virtual void changeCurrentPath (const char *szPath="")
const char* getCurrentPath () const
char* normalizePath (const char *szStartPath, const char *szPath)

Filter functions.

All key values should pass by these functions, derived classes should call them in their read/writeEntry functions. Currently, these functions only escape meta-characters (mainly spaces which would otherwise confuse the parser), but they could also be used to encode/decode key values.

void expandVariables (Bool bExpand=TRUE)
 should environment variables be automatically expanded?

Bool doesExpandVariables (void) const
 do environment variables get automatically expanded?

char* filterOut (const char *szValue)
 should be called from writeEntry, returns pointer to dynamic buffer.

char* filterIn (const char *szValue)
 should be called from readEntry, returns pointer to dynamic buffer.


Public Methods

void recordDefaults (Bool enable=TRUE)
Constructors and destructor
 BaseConfig ()
 default ctor.

virtual ~BaseConfig ()
 dtor.

Enumeration of subgroups/entries
virtual EnumeratorenumSubgroups () const=0
virtual EnumeratorenumEntries () const=0
Key access
virtual const char* readEntry (const char *szKey, const char *szDefault=NULL) const=0
long int readEntry (const char *szKey, long int Default) const
double readEntry (const char *szKey, double Default) const
virtual Bool writeEntry (const char *szKey, const char *szValue)=0
Bool writeEntry (const char *szKey, long int Value)
Bool writeEntry (const char *szKey, double Value)
virtual Bool deleteEntry (const char *szKey)=0
Other functions
virtual Bool flush (Bool=FALSE)
 permanently writes changes, returns TRUE on success.

Bool isInitialized () const
 returns TRUE if object was correctly initialized.


Protected Attributes

Bool m_bOk
 TRUE if ctor successfully initialized the object.

Bool m_bExpandVariables
 TRUE if environment variables are to be auto-expanded.

Bool m_bRecordDefaults
 TRUE if default values are to be recorded.


Private Attributes

char* m_szCurrentPath

Detailed Description

abstract base class config.

Definition at line 181 of file appconf.h.


Constructor & Destructor Documentation

BaseConfig::BaseConfig ( )
 

default ctor.

BaseConfig::~BaseConfig ( ) [virtual]
 

dtor.


Member Function Documentation

void BaseConfig::changeCurrentPath ( const char * szPath = "" ) [virtual]
 

Change the current path. Works like 'cd' and supports "..".

Parameters:
szPath   name of the group to search by default (created if !exists)

Reimplemented in FileConfig.

Bool BaseConfig::deleteEntry ( const char * szKey ) [pure virtual]
 

Delets the entry. Notice that there is intentionally no such function as deleteGroup: the group is automatically deleted when it's last entry is deleted.

@memo Deletes the entry.

Parameters:
szKey   The key to delete
Returns:
TRUE on success, FALSE on failure

Reimplemented in FileConfig.

Bool BaseConfig::doesExpandVariables ( void ) const [inline]
 

do environment variables get automatically expanded?

Definition at line 375 of file appconf.h.

Enumerator * BaseConfig::enumEntries ( ) const [pure virtual]
 

Enumerate entries of the current group.

Returns:
Number of entries
See also:
Enumerator, enumSubgroups

Reimplemented in FileConfig.

Enumerator * BaseConfig::enumSubgroups ( ) const [pure virtual]
 

Enumerate subgroups of the current group. Caller must delete the returned pointer. Example of usage:

      char **aszGroups;
      config.setCurrentPath("mygroup");
      BaseConfig::Enumerator *pEnum = config.enumSubgroups();
      size_t nGroups = pEnum->Count();
      for ( size_t n = 0; n < nGroups; n++ )
        cout << "Name of subgorup #" << n << " is " << (*pEnum)[n] << endl;
      delete pEnum;
      
Parameters:
Pointer   to an array of strings which is allocated by the function
Returns:
Number of subgroups
See also:
Enumerator, setCurrentPath, enumEntries

Reimplemented in FileConfig.

void BaseConfig::expandVariables ( Bool bExpand = TRUE ) [inline]
 

should environment variables be automatically expanded?

Definition at line 373 of file appconf.h.

char* BaseConfig::filterIn ( const char * szValue ) [static]
 

should be called from readEntry, returns pointer to dynamic buffer.

char* BaseConfig::filterOut ( const char * szValue ) [static]
 

should be called from writeEntry, returns pointer to dynamic buffer.

Bool BaseConfig::flush ( Bool bCurrentOnly = FALSE ) [inline, virtual]
 

permanently writes changes, returns TRUE on success.

Reimplemented in FileConfig.

Definition at line 354 of file appconf.h.

const char * BaseConfig::getCurrentPath ( ) const
 

Query the current path.

Returns:
current '/' separated path

Bool BaseConfig::isInitialized ( ) const [inline]
 

returns TRUE if object was correctly initialized.

Definition at line 356 of file appconf.h.

char* BaseConfig::normalizePath ( const char * szStartPath,
const char * szPath ) [static]
 

Resolve ".." and "/" in the path.

Parameters:
Start   path (i.e. current directory)
Relative   path (".." allowed) from start path
Returns:
Pointer to normalized path (caller should "delete []" it)

double BaseConfig::readEntry ( const char * szKey,
double Default ) const
 

Get the value of an entry, or the default value, interpreted as a double value.

Parameters:
szKey   The key to search for.
Default   The default value to return if not found.
Returns:
The value of the key converted to double or the default value.

Reimplemented in FileConfig.

long int BaseConfig::readEntry ( const char * szKey,
long int Default ) const
 

Get the value of an entry, or the default value, interpreted as a long integer.

Parameters:
szKey   The key to search for.
Default   The default value to return if not found.
Returns:
The value of the key converted to long int or the default value.

Reimplemented in FileConfig.

const char * BaseConfig::readEntry ( const char * szKey,
const char * szDefault = NULL ) const [pure virtual]
 

Get the value of an entry, or the default value.

Parameters:
szKey   The key to search for.
szDefault   The default value to return if not found.
Returns:
The value of the key, or defval if not found

Reimplemented in FileConfig.

Referenced by FileConfig::m_szComment(), and FileConfig::readEntry().

void BaseConfig::recordDefaults ( Bool enable = TRUE )
 

activates recording of default values

Parameters:
enable   TRUE to activate, FALSE to deactivate

void BaseConfig::setCurrentPath ( const char * szPath = "" ) [virtual]
 

Specify the new current path by its absolute name.

Parameters:
szPath   name of the group to search by default (created if !exists)

Bool BaseConfig::writeEntry ( const char * szKey,
double Value )
 

Set the value of an entry to a double value.

Parameters:
szKey   The key whose value to change.
Value   The new value.
Returns:
TRUE on success, FALSE on failure

Reimplemented in FileConfig.

Bool BaseConfig::writeEntry ( const char * szKey,
long int Value )
 

Set the value of an entry to a long int value.

Parameters:
szKey   The key whose value to change.
Value   The new value.
Returns:
TRUE on success, FALSE on failure

Reimplemented in FileConfig.

Bool BaseConfig::writeEntry ( const char * szKey,
const char * szValue ) [pure virtual]
 

Set the value of an entry.

Parameters:
szKey   The key whose value to change.
szValue   The new value.
Returns:
TRUE on success, FALSE on failure

Reimplemented in FileConfig.

Referenced by FileConfig::writeEntry().


Member Data Documentation

Bool BaseConfig::m_bExpandVariables [protected]
 

TRUE if environment variables are to be auto-expanded.

Definition at line 382 of file appconf.h.

Bool BaseConfig::m_bOk [protected]
 

TRUE if ctor successfully initialized the object.

Definition at line 380 of file appconf.h.

Bool BaseConfig::m_bRecordDefaults [protected]
 

TRUE if default values are to be recorded.

Definition at line 384 of file appconf.h.

char* BaseConfig::m_szCurrentPath [private]
 

Definition at line 386 of file appconf.h.


The documentation for this class was generated from the following file:
Generated at Wed Apr 4 19:56:36 2001 for ClanLib by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001