home *** CD-ROM | disk | FTP | other *** search
- #ifndef __CVar_h__
- #define __CVar_h__
-
- #include "Console.h"
-
-
- enum cVarTypes_e{
- CON_CVAR_TYPE_BOOL,
- CON_CVAR_TYPE_INT,
- CON_CVAR_TYPE_REAL,
- CON_CVAR_TYPE_STRING,
- CON_CVAR_TYPE_REAL_VECTOR,
-
- CON_NUM_CVAR_TYPES
- };
-
-
-
- /*
- This is the mother of all cvars.
- It is an abstract class witch only defines the interface
- */
- class CVar{
- public:
- const char* name; /* name of the cvar */
- const char* infoStr; /* string to be displayed by 'info'-cmd */
- const char* changeStr; /* string to be displayed after changing */
-
- cVarTypes_e type;
- unsigned short flags; /* accessability flags */
- bool instantUpdate;
-
- CVar(const char* name);
- virtual ~CVar()=0; /* make this class abstract, so only the derivates can be used */
-
- virtual char* getValStr(char* buff)=0; /* writes the value of the cvar in buff and returns a pointer to buff */
- virtual char* getVarValStr(char* buff)=0; /* writes the value of the real var in buff and returns a pointer to buff */
- virtual void setValStr(const char* valStr)=0; /* sets the cvar to the value contained in valStr */
- virtual bool valStrIsValid(const char* valStr)=0; /* tests if the cvar can be set to the value in valStr */
- virtual bool toggle()=0; /* cycles through all possible values of the cvar */
- virtual bool updateVar()=0;
-
- char* getTypeStr(char* buff); /* writes th type-identifier (e.g. 'integer') to buff and returns a pointer to buff */
- char* getFlagsStr(char* buff); /* writes a string describing the accessability-flags to buff (unix-like format) */
- virtual char* getValRangeStr(char* buff)=0;
- };
-
- /*
- This class represents a cvar that holds a bool value
- */
- class CVarBool:public CVar{
- public:
- CVarBool(const char* name, bool val); /* Creates a pure cvar with value val */
- CVarBool(const char* name, bool* var, bool instantUpdate); /* Creates a cvar whitch reflects the real variable var */
-
- char* getValStr(char* buff); /* functions from CVar that we overwrite */
- char* getVarValStr(char* buff);
- void setValStr(const char* valStr);
- bool valStrIsValid(const char* valStr);
- bool toggle();
- bool updateVar();
-
- void setValRange(bool min, bool max); /* With this function you can set the min/max value the cvar can hold */
- char* getValRangeStr(char* buff);
-
- void setVal(bool newVal);
- bool getVal();
-
- private:
- bool* var; /* this points to the 'real' variable (can be NULL if the cvar doesn't reflect a 'real' var) */
- bool val; /* this holds the value of the cvar */
- bool maxVal; /* maximum value that cvar can hold */
- bool minVal; /* minimum value that cvar can hold */
- };
-
- /*
- This class represents a cvar that holds a int value
- */
- class CVarInt:public CVar{
- public:
- CVarInt(const char* name, int val); /* Creates a pure cvar with value val */
- CVarInt(const char* name, int* var, bool instantUpdate); /* Creates a cvar which reflects the real variable var */
-
- char* getValStr(char* buff); /* functions from CVar that we overwrite */
- char* getVarValStr(char* buff);
- void setValStr(const char* valStr);
- bool valStrIsValid(const char* valStr);
- bool toggle();
- bool updateVar();
-
- void setValRange(int min, int max); /* With this function you can set the min/max value the cvar can hold */
- char* getValRangeStr(char* buff);
-
- void setVal(int NewVal);
- int getVal();
-
- private:
- int* var; /* this points to the 'real' variable (can be NULL if the cvar doesn't reflect a 'real' var) */
- int val; /* this holds the value of the cvar */
- int maxVal; /* maximum value that cvar can hold */
- int minVal; /* minimum value that cvar can hold */
- };
-
- /*
- This class represents a cvar that holds a float value
- */
- class CVarReal:public CVar{
- public:
- CVarReal(const char* name, float val); /* Creates a pure cvar with value val */
- CVarReal(const char* name, float* var, bool instantUpdate); /* Creates a cvar whitch reflects the real variable var */
-
- char* getValStr(char* buff); /* functions from CVar that we overwrite */
- char* getVarValStr(char* buff);
- void setValStr(const char* valStr);
- bool valStrIsValid(const char* valStr);
- bool toggle();
- bool updateVar();
-
- void setValRange(float min, float max); /* With this function you can set the min/max value the cvar can hold */
- char* getValRangeStr(char* buff);
-
- void setVal(float newVal);
- float getVal();
-
- private:
- float* var; /* this points to the 'real' variable (can be NULL if the cvar doesn't reflect a 'real' var) */
- float val; /* this holds the value of the cvar */
- float maxVal; /* maximum value that cvar can hold */
- float minVal; /* minimum value that cvar can hold */
- };
-
- /*
- This class represents a cvar that holds a string
- */
-
- class CVarString:public CVar{
- public:
- CVarString(const char* name, const char* val); /* Creates a pure cvar with value val */
- CVarString(const char* name, char** var, bool instantUpdate); /* Creates a cvar whitch reflects the real variable var */
-
- char* getValStr(char* buff); /* functions from CVar that we overwrite */
- char* getVarValStr(char* buff);
- void setValStr(const char* valStr);
- bool valStrIsValid(const char* valStr);
- bool toggle();
- bool updateVar();
-
- void setValRange(int min, int max); /* With this function you can set the min/max length of the string the cvar can hold */
- char* getValRangeStr(char* buff);
-
- // void setVal(char* newVal);
- char* getVal();
-
- private:
- char** var; /* this points to the 'real' variable (can be NULL if the cvar doesn't reflect a 'real' var) */
- char val[CON_MAX_STRING_LENGTH]; /* this holds the value of the cvar */
- int maxLength; /* maximum length of the string the cvar can hold */
- int minLength; /* minimum length of the string the cvar can hold */
- };
-
- /*
- This class represents a cvar that holds a vector of type float
- */
-
- class CVarRealVector:public CVar{
- public:
- int dim;
-
- CVarRealVector(const char* name, float* val, int dimension); /* Creates a pure cvar with value val */
- CVarRealVector(const char* name, float** var, int dimension, bool instantUpdate); /* Creates a cvar whitch reflects the real variable var */
-
- char* getValStr(char* buff); /* functions from CVar that we overwrite */
- char* getVarValStr(char* buff);
- void setValStr(const char* valStr);
- bool valStrIsValid(const char* valStr);
- bool toggle();
- bool updateVar();
-
- void setValRange(float min, float max); /* With this function you can set the min/max length of the string the cvar can hold */
- char* getValRangeStr(char* buff);
-
- private:
- float** var; /* this points to the 'real' variable (can be NULL if the cvar doesn't reflect a 'real' var) */
- float* val; /* this holds the value of the cvar */
- float maxVal;
- float minVal;
- };
-
-
-
- #endif /* __CVar_h__ */
-