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

GenericValues Class Reference

#include <GenericValues.h>

Inheritance diagram for GenericValues:

Inheritance graph
[legend]
Collaboration diagram for GenericValues:

Collaboration graph
[legend]
List of all members.

Public Methods

 GenericValues (char *strName, int iMaxValues)
virtual ~GenericValues ()
char * getClassName ()
int getValuesTotal ()
bool addSetting (const char *strName, void *vAddress, GenericValueKind t)
virtual char * getValue (const char *strName, char *strValue)
virtual bool setValue (const char *strName, const char *strValue)
virtual bool readValues (const char *strFile, const char *strSeparator=0)
virtual bool saveValues (const char *strFile, const char *strSeparator=0, bool bAppend=true)
virtual void show (ostream &out, const char *strSeparator)

Private Methods

GenericValueTgetValuePtr (const char *strName)

Private Attributes

char * m_strClassName
GenericValueT ** m_values
int m_iValuesTotal
int m_iMaxGenericValues

Detailed Description

This class contains a collection of GenericValueT objects. This makes it possible to reference variables using string names. The class is an abstract class which should not be instantiated. It is the subclass of this class which contains the actual variables. In order to add a reference to a variable the method 'addSetting' must be used which associates the variables in the subclass with string names. The GenericValues class is used to read in configuration files. This now becomes very easy as long as one makes sure that the names in the configuration file match the string names associated with the corresponding variables

Definition at line 124 of file GenericValues.h.


Constructor & Destructor Documentation

GenericValues::GenericValues char *    strName,
int    iMaxValues
 

Constructor for the GenericValues class. It creates a GenericValues object.

Parameters:
strName  a string denoting the name associated with this group of generic values (this is usually the name of the subclass which contains the actual generic variables)
iMaxValues  an integer denoting the number of generic values in the current collection, i.e. the maximum number that can be stored

Definition at line 243 of file GenericValues.cpp.

References m_iMaxGenericValues, m_iValuesTotal, m_strClassName, and m_values.

GenericValues::~GenericValues void    [virtual]
 

Destructor for the GenericValues class. It destroys a GenericValues object by freeing all memory allocated to it.

Definition at line 258 of file GenericValues.cpp.

References getValuesTotal(), m_strClassName, and m_values.


Member Function Documentation

bool GenericValues::addSetting const char *    strName,
void *    vAddress,
GenericValueKind    type
 

This method adds a new generic value to the collection and provides a connection between a string name and the variable name of the generic value.

Parameters:
strName  a string denoting the name associated with the variable of the generic value which is added (the variable can be reached through this name)
vAddress  a (void) pointer to the actual variable itself
type  the (generic) type of the variable which is added
Returns:
a boolean indicating whether the generic value has been succesfully added

Definition at line 297 of file GenericValues.cpp.

References GenericValueKind, getValuePtr(), m_iMaxGenericValues, m_iValuesTotal, m_strClassName, and m_values.

Referenced by PlayerSettings::PlayerSettings(), and ServerSettings::ServerSettings().

char * GenericValues::getClassName  
 

Get method for the 'm_strClassName' member variable.

Returns:
the name associated with this group of generic values (this is usually the name of the subclass which contains the actual variables)

Definition at line 271 of file GenericValues.cpp.

char * GenericValues::getValue const char *    strName,
char *    strValue
[virtual]
 

This method determines the value of the variable of which the name associated with it matches the first argument to the method. The value is converted to a string which is put into the second argument (note that enough memory must be allocated for this char*). This same string is also returned by the method. This enables you to use the method as an argument to a function such as 'strcpy'.

Parameters:
strName  a string denoting the name associated with the variable of which the value should be returned
strValue  a string which after the method call will contain the value of the variable of which the name associated with it matches the first argument to the method
Returns:
a string containing the value of the variable of which the name associated with it matches the first argument to the method

Definition at line 360 of file GenericValues.cpp.

References GenericValueT::getValue(), and getValuePtr().

GenericValueT * GenericValues::getValuePtr const char *    strName [private]
 

This (private) method returns a pointer to the GenericValueT object of which the name associated with the variable matches the argument passed to the method.

Parameters:
strName  a string denoting the name associated with the variable of the GenericValueT object to which a pointer should be returned
Returns:
a pointer to the GenericValueT object of which the name associated with the variable matches the argument; 0 when a GenericValueT object with a variable associated with the given name does not exist

Definition at line 329 of file GenericValues.cpp.

References getValuesTotal(), and m_values.

Referenced by addSetting(), getValue(), and setValue().

int GenericValues::getValuesTotal  
 

Get method for the 'm_iValuesTotal' member variable.

Returns:
the number of generic values stored in the collection so far

Definition at line 278 of file GenericValues.cpp.

Referenced by getValuePtr(), show(), and ~GenericValues().

bool GenericValues::readValues const char *    strFileName,
const char *    strSeparator = 0
[virtual]
 

This method reads generic values from a file indicated by the first argument to the method and stores them in the collection. In this file the names associated with each value must be listed first followed by a separator and then the value. The names associated with each value should match the string names with which the corresponding generic value is added using 'addSetting'.

Parameters:
strFile  a string denoting the name of the file from which the values must be read
strSeparator  a string representing the separator which is written between name and value in the configuration file
Returns:
a boolean indicating whether the values have been read correctly

Reimplemented in ServerSettings.

Definition at line 412 of file GenericValues.cpp.

References setValue().

Referenced by main(), and ServerSettings::readValues().

bool GenericValues::saveValues const char *    strFile,
const char *    strSeparator = 0,
bool    bAppend = true
[virtual]
 

This method writes the generic values in the current collection to a file indicated by the first argument to the method. The string name associated with the value and the value itself are separated by a separator which is specified as the second argument.

Parameters:
strFile  a string denoting the name of the file to which the generic values should be written
strSeparator  a string representing the separator which should be written between the name associated with each value and the value itself
bAppend  a boolean indicating whether the values should be appended to the given file (=true) or if current contents of the file should be overwritten (=false)
Returns:
a boolean indicating whether the values in the current collection have been correctly written to the given file

Definition at line 478 of file GenericValues.cpp.

References show().

bool GenericValues::setValue const char *    strName,
const char *    strValue
[virtual]
 

This method sets the variable of which the name associated with it matches the first argument to the method to the value indicated by the second argument. The value is always supplied as a string which is then converted into the right type for the generic value in question.

Parameters:
strName  a string denoting the name associated with the variable which must be set
strValue  a string denoting the value to which the variable indicated by the first argument should be set
Returns:
a boolean indicating whether the update was successful

Reimplemented in ServerSettings.

Definition at line 387 of file GenericValues.cpp.

References getValuePtr(), and GenericValueT::setValue().

Referenced by readValues(), and ServerSettings::setValue().

void GenericValues::show ostream &    out,
const char *    strSeparator
[virtual]
 

This display method writes all the generic values in the current collection to the output stream indicated by the first argument to the method. The name associated with each value and the value itself are separated by a separator which is specified as the second argument.

Parameters:
out  the output stream to which the current collection of generic values should be written
strSeparator  a string representing the separator which should be written between the name associated with each value and the value itself

Definition at line 509 of file GenericValues.cpp.

References getValuesTotal(), m_values, and GenericValueT::show().

Referenced by Player::executeStringCommand(), and saveValues().


Member Data Documentation

int GenericValues::m_iMaxGenericValues [private]
 

the number of generic values in the current collection, i.e. the maximum number of values that can be stored

Definition at line 136 of file GenericValues.h.

Referenced by addSetting(), and GenericValues().

int GenericValues::m_iValuesTotal [private]
 

the total number of generic values stored in the collection so far

Definition at line 134 of file GenericValues.h.

Referenced by addSetting(), and GenericValues().

char* GenericValues::m_strClassName [private]
 

the name associated with this group of generic values; this is usually the name of the subclass which contains the actual variables

Definition at line 129 of file GenericValues.h.

Referenced by addSetting(), GenericValues(), and ~GenericValues().

GenericValueT** GenericValues::m_values [private]
 

a pointer to an array containing all generic value pointers (GenericValueT objects)

Definition at line 132 of file GenericValues.h.

Referenced by addSetting(), GenericValues(), getValuePtr(), show(), and ~GenericValues().


The documentation for this class was generated from the following files:
Generated on Fri Nov 7 11:46:03 2003 for UvA Trilearn 2003 Base Code by doxygen1.2.12 written by Dimitri van Heesch, © 1997-2001