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

AnyConfig::AcConfiguration Class Reference

The base class for all configuration classes. More...

#include <AnyConfig.h>

Inheritance diagram for AnyConfig::AcConfiguration::

AnyConfig::AcRegConfig AnyConfig::AcWriteableConfig AnyConfig::AcCorbaConfig AnyConfig::AcEnvConfig AnyConfig::AcFileConfig AnyConfig::AcMemConfig AnyConfig::AcMySQLConfig AnyConfig::AcBufFileConfig List of all members.

Public Methods

 AcConfiguration ()
 Constructor method. More...

virtual ~AcConfiguration ()
 Destructor method. More...

bool copyFrom (AcConfiguration *pConfig)
 Copy another configuration to this one. More...

virtual bool copyTo (AcWriteableConfig *pWriteableConfig)
 Copy this configuration to another configuration. More...

virtual AcConfiguration* createFromSection (const char *section)
 Extract a sub-configuration containing only the indicated section. More...

virtual void display ()=0
virtual bool getBool (const char *pKey, const bool defaultValue=false)
 Returns a boolean value from the configuration. More...

virtual long getLong (const char *pKey, const long defaultValue=-1)
 Get a 32 bit value from the configuration. More...

virtual double getNumber (const char *pKey, const double defaultValue=-1.0)
 Returns a floating point (real) number from the configuration. More...

virtual bool getSectionStr (const char *pSection, const char *pKey, CString &rValue)
 Like getStr() but can fetch keys from another section than the current one. More...

virtual bool getStr (const char *pKey, CString &rValue)=0
virtual bool initialize (AcConfiguration &parentConfig)
 Initialize the configuration using another, probably more primitive, parent configuration. More...

virtual bool initRequired ()=0
virtual bool keyExists (const char *pKey)=0
const CString& GetCurrentSection () const
 Returns the value of member '_currentSection'. More...

void SetCurrentSection (const CString &rCurrentSection)
 Set the value of member '_currentSection' to 'rCurrentSection'. More...

int IsBufFileConfig () const
 Method that returns a non zero value if it is actually a AcBufFileConfig Object. More...

int IsCorbaConfig () const
 Method that returns a non zero value if it is actually a AcCorbaConfig Object. More...

int IsEnvConfig () const
 Method that returns a non zero value if it is actually a AcEnvConfig Object. More...

int IsFileConfig () const
 Method that returns a non zero value if it is actually a AcFileConfig Object. More...

int IsMemConfig () const
 Method that returns a non zero value if it is actually a AcMemConfig Object. More...

int IsMySQLConfig () const
 Method that returns a non zero value if it is actually a AcMySQLConfig Object. More...

int IsRegConfig () const
 Method that returns a non zero value if it is actually a AcRegConfig Object. More...

int IsWriteableConfig () const
 Method that returns a non zero value if it is actually a AcWriteableConfig Object. More...


Static Public Methods

bool cfg2string (CString &rString, AcConfiguration *pConfiguration)
 Convert a configuration into a stringified representation. More...

AcConfiguration* findAnyConfig (int argn, char *argv[])
 Look for configuration in all the right places. More...

AcConfiguration* loadFrom (const char *source)
 Load a configuration from the specified Configuration source.. More...

bool string2bool (const char *string)
 Interpret a string as a boolean. More...

AcConfiguration* string2cfg (const char *string)
 Return a configuration from a stringified representation. More...


Static Protected Methods

void decode (CString &rSt)
 Decode an encoded representation. More...

void encode (CString &rSt)
 Make an encoded representation. More...


Protected Attributes

CString _currentSection

Private Methods

void ConstructorInclude ()
 Method which must be called first in a constructor. More...

void DestructorInclude ()
 Method which must be called first in a destructor. More...


Static Private Methods

void findInHomeDir (AcWriteableConfig &parent, AcConfiguration &rEnv)
 Try to find a configuration file in some kind of 'home' directory. More...


Detailed Description

The base class for all configuration classes.


Constructor & Destructor Documentation

AnyConfig::AcConfiguration::AcConfiguration ( )
 

Constructor method.

AnyConfig::AcConfiguration::~AcConfiguration ( ) [virtual]
 

Destructor method.


Member Function Documentation

void AnyConfig::AcConfiguration::ConstructorInclude ( ) [private]
 

Method which must be called first in a constructor.

Reimplemented in AnyConfig::AcWriteableConfig, AnyConfig::AcMemConfig, AnyConfig::AcBufFileConfig, AnyConfig::AcEnvConfig, AnyConfig::AcFileConfig, AnyConfig::AcMySQLConfig, AnyConfig::AcRegConfig, and AnyConfig::AcCorbaConfig.

void AnyConfig::AcConfiguration::DestructorInclude ( ) [private]
 

Method which must be called first in a destructor.

Reimplemented in AnyConfig::AcWriteableConfig, AnyConfig::AcMemConfig, AnyConfig::AcBufFileConfig, AnyConfig::AcEnvConfig, AnyConfig::AcFileConfig, AnyConfig::AcMySQLConfig, AnyConfig::AcRegConfig, and AnyConfig::AcCorbaConfig.

const CString & AnyConfig::AcConfiguration::GetCurrentSection ( ) const [inline]
 

Returns the value of member '_currentSection'.

int AnyConfig::AcConfiguration::IsBufFileConfig ( ) const
 

Method that returns a non zero value if it is actually a AcBufFileConfig Object.

int AnyConfig::AcConfiguration::IsCorbaConfig ( ) const
 

Method that returns a non zero value if it is actually a AcCorbaConfig Object.

int AnyConfig::AcConfiguration::IsEnvConfig ( ) const
 

Method that returns a non zero value if it is actually a AcEnvConfig Object.

int AnyConfig::AcConfiguration::IsFileConfig ( ) const
 

Method that returns a non zero value if it is actually a AcFileConfig Object.

int AnyConfig::AcConfiguration::IsMemConfig ( ) const
 

Method that returns a non zero value if it is actually a AcMemConfig Object.

int AnyConfig::AcConfiguration::IsMySQLConfig ( ) const
 

Method that returns a non zero value if it is actually a AcMySQLConfig Object.

int AnyConfig::AcConfiguration::IsRegConfig ( ) const
 

Method that returns a non zero value if it is actually a AcRegConfig Object.

int AnyConfig::AcConfiguration::IsWriteableConfig ( ) const
 

Method that returns a non zero value if it is actually a AcWriteableConfig Object.

void AnyConfig::AcConfiguration::SetCurrentSection ( const CString & rCurrentSection ) [inline]
 

Set the value of member '_currentSection' to 'rCurrentSection'.

bool AnyConfig::AcConfiguration::cfg2string ( CString & rString,
AcConfiguration * pConfiguration ) [static]
 

Convert a configuration into a stringified representation.

Parameters:
string   The configuration as one string without spaces.
pConfiguration   The configuration to convert.
Returns:
True if the conversion succeeded, false otherwise.

bool AnyConfig::AcConfiguration::copyFrom ( AcConfiguration * pConfig )
 

Copy another configuration to this one.

Just calls the other configuration's copyTo method to this. This must therefore be an AcWriteableConfig to succeed. Likewise, the pointed-to configuration must support copying.

Parameters:
pConfig   The configuration to copy.
Returns:
True if the copy was succesful.

bool AnyConfig::AcConfiguration::copyTo ( AcWriteableConfig * pWriteableConfig ) [virtual]
 

Copy this configuration to another configuration.

This method is specifically handy when the source configuration comes from a text file and the destination configuration is AcMemConfig, which offers much more functionality. Along the same lines, this method can be used to save an AcMemConfig in a file. If the target configuration already has filled-in items, the result of this operation is undefined. Some derived classes may end up containing a merged result of the old and the new values (AcMemConfig, AcEnvConfig), other may only contain the copied values (like AcFileConfig).

Parameters:
pWriteableConfig   A pointer to an initialized AcWriteableConfig.
return   True if the derived configuration supports copying, false otherwise.

Reimplemented in AnyConfig::AcMemConfig, AnyConfig::AcFileConfig, AnyConfig::AcMySQLConfig, AnyConfig::AcRegConfig, and AnyConfig::AcCorbaConfig.

AcConfiguration * AnyConfig::AcConfiguration::createFromSection ( const char * section ) [virtual]
 

Extract a sub-configuration containing only the indicated section.

Parameters:
section   The section to extract.
Returns:
An AcConfiguration pointer if the section existed or NULL if it didn't or the derived class does not support this operation. The returned configuration will already have its one and only section selected.

Note to implementors:
If your implementation returns a specialized sub-class for this, make sure it is either not an AcWriteableConfig implementation or if it is that writing to it does not alter the original section's information.
Probably your best solution is to return an AcMemConfig with a copy of the section, like the original classes do.

Reimplemented in AnyConfig::AcMemConfig, and AnyConfig::AcMySQLConfig.

void AnyConfig::AcConfiguration::decode ( CString & rSt ) [static, protected]
 

Decode an encoded representation.

void AnyConfig::AcConfiguration::encode ( CString & rSt ) [static, protected]
 

Make an encoded representation.

AcConfiguration * AnyConfig::AcConfiguration::findAnyConfig ( int argn,
char * argv[] ) [static]
 

Look for configuration in all the right places.

The passed parameters are not altered in any way.
If there is an argv that starts with either --anycfg or --ANYCFG and contains an Equals sign (=), whatever follows the Equals sign is taken to be a stringified configuration. A stringified configuration is formed by concatenating key-value pairs, using At signs (@) as delimiters.
There is no support for passing the At sign itself.
A single command line parameter cannot contain spaces unless your shell provides an escape mechanism.

If there is no such command line option, findAnyConfig() will look in the program's environment for a key "ANYCFG". If found, it is assumed to contain a stringified configuration as above.

If there is no such environment entry, we look for a file-based configuration. See findInHomeDir().

If any of the above attempts yielded a parent configuration that contains a key CFGFILENAME in its default section, that file will be loaded as the resulting configuration of this method.

If there is no CFGFILENAME key or if loading the file it points to failed, the method attempts to connect to a MySQL database server, if MySQLConfig support is linking in. It will do so using USERNAME, PASSWORD, etc. from the configuration obtained so far. If a MySQL server can be contacted, it will be used to load the configuration to return.

If all else failed but we had an initial bootstrap configuration, that will be returned. Otherwise, the method returns NULL to indicate a total failure.

Parameters:
argn   From main.
argv   From main,
Returns:
Can be NULL, see above.

void AnyConfig::AcConfiguration::findInHomeDir ( AcWriteableConfig & parent,
AcConfiguration & rEnv ) [static, private]
 

Try to find a configuration file in some kind of 'home' directory.

This function will try to load the parent configuration from the following paths, in order and if the environment variables ($envvar) are set.

  • $HOME/.anycfg.ini Hidden file in the home directory
  • $HOME/anycfg.ini Normal file in the home directory
  • $HOME/.anycfg/parent.ini Parent configuration in a directory with configuration files.
  • $WINDIR/anycfg.ini
  • $WINDIR/system32/anycfg.ini
  • $WINDIR/system/anycfg.ini
  • $SYSTEMROOT/anycfg.ini
  • $SYSTEMROOT/system32/anycfg.ini
  • $SYSTEMROOT/system/anycfg.ini
Slashes or backslashes are used based on the kind found in the environment variable.
The file is determined to exist and be accessible if the current user can succesfully do a regular fopen (pathname, "rt") on it.
Parameters:
parent   Will acquire a CFGFILENAME setting in its current section if any of the above paths worked.
rEnv   Any configuration to obtain $HOME, $WINDIR and/or $SYSTEMROOT from. As its name implies, findAnyConfig() sets this to be the program's environment.

bool AnyConfig::AcConfiguration::getBool ( const char * pKey,
const bool defaultValue = false ) [virtual]
 

Returns a boolean value from the configuration.

Parameters:
pKey   The key we're looking for.
defaultValue   To be returned if there is no such key.
Returns:
If the key does not exist the default value is returned. Otherwise the following rules apply:
  • FALSE: The value does not start with a digit and the first character is a N or a F.
  • FALSE: The value does start with a digit and its numerical value is 0
  • TRUE: Anything else.
The intend of these rules is to return true for "Yes" in most languages, as well as for the word 'True'. 'No' in most languages happens to start with a N and we added the F for 'False'.

long AnyConfig::AcConfiguration::getLong ( const char * pKey,
const long defaultValue = -1 ) [virtual]
 

Get a 32 bit value from the configuration.

Parameters:
key   The key to fetch from [the current section in] the configuration.
defaultValue   An optional default value to return.
Returns:
The value found or the default value if the key did not exist.

double AnyConfig::AcConfiguration::getNumber ( const char * pKey,
const double defaultValue = -1.0 ) [virtual]
 

Returns a floating point (real) number from the configuration.

Parameters:
pKey   The key.
defaultValue   To be returned if the key does not exist.
Returns:
Whatever strtod() made of the value found or the default value if the key was not found.

bool AnyConfig::AcConfiguration::getSectionStr ( const char * pSection,
const char * pKey,
CString & rValue ) [virtual]
 

Like getStr() but can fetch keys from another section than the current one.

The default implementation just pushes _currentSection on stack, replaces it with the supplied section and calls the regular getStr() function.

Parameters:
pKey   The key to fetch.
pSection   The section to fetch it from.
rValue   The value found, if any.
Returns:
False if the key could not be found in the specified section.

Reimplemented in AnyConfig::AcMemConfig, AnyConfig::AcEnvConfig, AnyConfig::AcMySQLConfig, and AnyConfig::AcRegConfig.

bool AnyConfig::AcConfiguration::initialize ( AcConfiguration & parentConfig ) [virtual]
 

Initialize the configuration using another, probably more primitive, parent configuration.

The default implementation of this method just returns true.

Parameters:
parentConfig   The parent configuration to use.
Returns:
False if the initialization failed.

Reimplemented in AnyConfig::AcBufFileConfig, AnyConfig::AcFileConfig, AnyConfig::AcMySQLConfig, AnyConfig::AcRegConfig, and AnyConfig::AcCorbaConfig.

AcConfiguration * AnyConfig::AcConfiguration::loadFrom ( const char * source ) [static]
 

Load a configuration from the specified Configuration source..

Builds an AcMemConfig using the information supplied, instantiates the specified class and invokes its initialize() member.
Warning: it is not legal to assume the returned configuration can be typecast to any specific derived class. Specifically, you might get an AcMemConfig on return regardless of the type you asked for.

Parameters:
source   A Configuration source..
Returns:
The configuration specified or NULL if there were any failures.

bool AnyConfig::AcConfiguration::string2bool ( const char * string ) [static]
 

Interpret a string as a boolean.

Parameters:
string   The string to interpret.
Returns:
True of false depending on the interpretation.

AcConfiguration * AnyConfig::AcConfiguration::string2cfg ( const char * string ) [static]
 

Return a configuration from a stringified representation.

Parameters:
string   The stringified configuration.
Returns:
The configuration represented by the string or NULL if the conversion failed.


The documentation for this class was generated from the following files:
Generated at Wed Nov 21 11:34:18 2001 for AnyConfig by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001