home *** CD-ROM | disk | FTP | other *** search
/ Enter 2005 March / ENTER.ISO / files / fwp-0.0.6-win32-installer.exe / CVar.h < prev    next >
Encoding:
C/C++ Source or Header  |  2004-12-06  |  6.6 KB  |  192 lines

  1. #ifndef __CVar_h__
  2. #define __CVar_h__
  3.  
  4. #include "Console.h"
  5.  
  6.  
  7. enum cVarTypes_e{
  8.     CON_CVAR_TYPE_BOOL,
  9.     CON_CVAR_TYPE_INT,
  10.     CON_CVAR_TYPE_REAL,
  11.     CON_CVAR_TYPE_STRING,
  12.     CON_CVAR_TYPE_REAL_VECTOR,
  13.     
  14.     CON_NUM_CVAR_TYPES
  15. };
  16.  
  17.  
  18.  
  19. /*
  20.     This is the mother of all cvars.
  21.     It is an abstract class witch only defines the interface
  22. */
  23. class CVar{
  24. public:
  25.     const char* name;            /* name of the cvar */
  26.     const char* infoStr;        /* string to be displayed by 'info'-cmd */
  27.     const char* changeStr;        /* string to be displayed after changing */
  28.     
  29.     cVarTypes_e type;
  30.     unsigned short flags;    /* accessability flags */
  31.     bool instantUpdate;
  32.  
  33.     CVar(const char* name);
  34.     virtual ~CVar()=0;    /* make this class abstract, so only the derivates can be used */
  35.  
  36.     virtual char* getValStr(char* buff)=0;            /* writes the value of the cvar in buff and returns a pointer to buff */
  37.     virtual char* getVarValStr(char* buff)=0;            /* writes the value of the real var in buff and returns a pointer to buff */
  38.     virtual void setValStr(const char* valStr)=0;    /* sets the cvar to the value contained in valStr */
  39.     virtual bool valStrIsValid(const char* valStr)=0;    /* tests if the cvar can be set to the value in valStr */
  40.     virtual bool toggle()=0;                            /* cycles through all possible values of the cvar */
  41.     virtual bool updateVar()=0;
  42.  
  43.     char* getTypeStr(char* buff);        /* writes th type-identifier (e.g. 'integer') to buff and returns a pointer to buff */
  44.     char* getFlagsStr(char* buff);        /* writes a string describing the accessability-flags to buff (unix-like format) */
  45.     virtual char* getValRangeStr(char* buff)=0;
  46. };
  47.  
  48. /*
  49.     This class represents a cvar that holds a bool value
  50. */
  51. class CVarBool:public CVar{
  52. public:
  53.     CVarBool(const char* name, bool val);    /* Creates a pure cvar with value val */
  54.     CVarBool(const char* name, bool* var, bool instantUpdate);    /* Creates a cvar whitch reflects the real variable var */
  55.  
  56.     char* getValStr(char* buff);            /* functions from CVar that we overwrite */
  57.     char* getVarValStr(char* buff);
  58.     void setValStr(const char* valStr);
  59.     bool valStrIsValid(const char* valStr);
  60.     bool toggle();
  61.     bool updateVar();
  62.  
  63.     void setValRange(bool min, bool max);    /* With this function you can set the min/max value the cvar can hold */
  64.     char* getValRangeStr(char* buff);
  65.  
  66.     void setVal(bool newVal);
  67.     bool getVal();
  68.  
  69. private:
  70.     bool* var;        /* this points to the 'real' variable (can be NULL if the cvar doesn't reflect a 'real' var) */
  71.     bool val;        /* this holds the value of the cvar */
  72.     bool maxVal;    /* maximum value that cvar can hold */
  73.     bool minVal;    /* minimum value that cvar can hold */
  74. };
  75.  
  76. /*
  77.     This class represents a cvar that holds a int value
  78. */
  79. class CVarInt:public CVar{
  80. public:
  81.     CVarInt(const char* name, int val);    /* Creates a pure cvar with value val */
  82.     CVarInt(const char* name, int* var, bool instantUpdate);    /* Creates a cvar which reflects the real variable var */
  83.  
  84.     char* getValStr(char* buff);            /* functions from CVar that we overwrite */
  85.     char* getVarValStr(char* buff);
  86.     void setValStr(const char* valStr);
  87.     bool valStrIsValid(const char* valStr);
  88.     bool toggle();
  89.     bool updateVar();
  90.  
  91.     void setValRange(int min, int max);    /* With this function you can set the min/max value the cvar can hold */
  92.     char* getValRangeStr(char* buff);
  93.  
  94.     void setVal(int NewVal);
  95.     int getVal();
  96.  
  97. private:
  98.     int* var;        /* this points to the 'real' variable (can be NULL if the cvar doesn't reflect a 'real' var) */
  99.     int val;        /* this holds the value of the cvar */
  100.     int maxVal;    /* maximum value that cvar can hold */
  101.     int minVal;    /* minimum value that cvar can hold */
  102. };
  103.  
  104. /*
  105.     This class represents a cvar that holds a float value
  106. */
  107. class CVarReal:public CVar{
  108. public:
  109.     CVarReal(const char* name, float val);    /* Creates a pure cvar with value val */
  110.     CVarReal(const char* name, float* var, bool instantUpdate);    /* Creates a cvar whitch reflects the real variable var */
  111.  
  112.     char* getValStr(char* buff);            /* functions from CVar that we overwrite */
  113.     char* getVarValStr(char* buff);
  114.     void setValStr(const char* valStr);
  115.     bool valStrIsValid(const char* valStr);
  116.     bool toggle();
  117.     bool updateVar();
  118.  
  119.     void setValRange(float min, float max);    /* With this function you can set the min/max value the cvar can hold */
  120.     char* getValRangeStr(char* buff);
  121.  
  122.     void setVal(float newVal);
  123.     float getVal();
  124.  
  125. private:
  126.     float* var;        /* this points to the 'real' variable (can be NULL if the cvar doesn't reflect a 'real' var) */
  127.     float val;        /* this holds the value of the cvar */
  128.     float maxVal;    /* maximum value that cvar can hold */
  129.     float minVal;    /* minimum value that cvar can hold */
  130. };
  131.  
  132. /*
  133.     This class represents a cvar that holds a string
  134. */
  135.  
  136. class CVarString:public CVar{
  137. public:
  138.     CVarString(const char* name, const char* val);    /* Creates a pure cvar with value val */
  139.     CVarString(const char* name, char** var, bool instantUpdate);    /* Creates a cvar whitch reflects the real variable var */
  140.  
  141.     char* getValStr(char* buff);            /* functions from CVar that we overwrite */
  142.     char* getVarValStr(char* buff);
  143.     void setValStr(const char* valStr);
  144.     bool valStrIsValid(const char* valStr);
  145.     bool toggle();
  146.     bool updateVar();
  147.  
  148.     void setValRange(int min, int max);    /* With this function you can set the min/max length of the string the cvar can hold */
  149.     char* getValRangeStr(char* buff);
  150.  
  151. //    void setVal(char* newVal);
  152.     char* getVal();
  153.  
  154. private:
  155.     char** var;        /* this points to the 'real' variable (can be NULL if the cvar doesn't reflect a 'real' var) */
  156.     char val[CON_MAX_STRING_LENGTH];        /* this holds the value of the cvar */
  157.     int maxLength;    /* maximum length of the string the cvar can hold */
  158.     int minLength;    /* minimum length of the string the cvar can hold */
  159. };
  160.  
  161. /*
  162.     This class represents a cvar that holds a vector of type float
  163. */
  164.  
  165. class CVarRealVector:public CVar{
  166. public:
  167.     int dim;
  168.  
  169.     CVarRealVector(const char* name, float* val, int dimension);    /* Creates a pure cvar with value val */
  170.     CVarRealVector(const char* name, float** var, int dimension, bool instantUpdate);    /* Creates a cvar whitch reflects the real variable var */
  171.  
  172.     char* getValStr(char* buff);            /* functions from CVar that we overwrite */
  173.     char* getVarValStr(char* buff);
  174.     void setValStr(const char* valStr);
  175.     bool valStrIsValid(const char* valStr);
  176.     bool toggle();
  177.     bool updateVar();
  178.  
  179.     void setValRange(float min, float max);    /* With this function you can set the min/max length of the string the cvar can hold */
  180.     char* getValRangeStr(char* buff);
  181.  
  182. private:
  183.     float** var;        /* this points to the 'real' variable (can be NULL if the cvar doesn't reflect a 'real' var) */
  184.     float* val;        /* this holds the value of the cvar */
  185.     float maxVal;
  186.     float minVal;
  187. };
  188.  
  189.  
  190.  
  191. #endif    /* __CVar_h__ */
  192.