#include <GenericValues.h>
Inheritance diagram for GenericValues:
Public Member Functions | |
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 Member Functions | |
GenericValueT * | getValuePtr (const char *strName) |
Private Attributes | |
char * | m_strClassName |
GenericValueT ** | m_values |
int | m_iValuesTotal |
int | m_iMaxGenericValues |
Definition at line 124 of file GenericValues.h.
GenericValues::GenericValues | ( | char * | strName, | |
int | iMaxValues | |||
) |
Constructor for the GenericValues class. It creates a GenericValues object.
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.
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.
strName | a string denoting the name associated with the variable of the GenericValueT object to which a pointer should be returned |
Definition at line 329 of file GenericValues.cpp.
References getValuesTotal(), and m_values.
Referenced by addSetting(), getValue(), and setValue().
char * GenericValues::getClassName | ( | ) |
Get method for the 'm_strClassName' member variable.
Definition at line 271 of file GenericValues.cpp.
References m_strClassName.
int GenericValues::getValuesTotal | ( | ) |
Get method for the 'm_iValuesTotal' member variable.
Definition at line 278 of file GenericValues.cpp.
References m_iValuesTotal.
Referenced by getValuePtr(), show(), and ~GenericValues().
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.
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 |
Definition at line 297 of file GenericValues.cpp.
References getValuePtr(), m_iMaxGenericValues, m_iValuesTotal, m_strClassName, and m_values.
Referenced by PlayerSettings::PlayerSettings(), and ServerSettings::ServerSettings().
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'.
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 |
Definition at line 360 of file GenericValues.cpp.
References GenericValueT::getValue(), and getValuePtr().
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.
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 |
Reimplemented in ServerSettings.
Definition at line 387 of file GenericValues.cpp.
References getValuePtr(), and GenericValueT::setValue().
Referenced by readValues(), and ServerSettings::setValue().
bool GenericValues::readValues | ( | const char * | strFile, | |
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'.
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 |
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.
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) |
Definition at line 478 of file GenericValues.cpp.
References show().
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.
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(), and m_values.
Referenced by Player::executeStringCommand(), and saveValues().
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(), getClassName(), 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().
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(), GenericValues(), and getValuesTotal().
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().