00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef __CS_IUTIL_CONFIG_H__
00020 #define __CS_IUTIL_CONFIG_H__
00021
00026 #include "csutil/scf.h"
00027 #include "csutil/util.h"
00028
00030 enum csVariantType
00031 {
00033 CSVAR_LONG,
00035 CSVAR_BOOL,
00037 CSVAR_CMD,
00039 CSVAR_FLOAT,
00041 CSVAR_STRING
00042 };
00043
00049 struct csVariant
00050 {
00051 private:
00052 csVariantType type;
00053 union value
00054 {
00055 long l;
00056 bool b;
00057 float f;
00058 char* s;
00059 } v;
00060
00061 public:
00062 csVariant () { type = CSVAR_LONG; v.s = NULL; }
00063 ~csVariant () { if (type == CSVAR_STRING) delete[] v.s; }
00065 void SetLong (long l)
00066 {
00067 if (type == CSVAR_STRING) delete[] v.s;
00068 type = CSVAR_LONG;
00069 v.l = l;
00070 }
00072 void SetBool (bool b)
00073 {
00074 if (type == CSVAR_STRING) delete[] v.s;
00075 type = CSVAR_BOOL;
00076 v.b = b;
00077 }
00079 void SetFloat (float f)
00080 {
00081 if (type == CSVAR_STRING) delete[] v.s;
00082 type = CSVAR_FLOAT;
00083 v.f = f;
00084 }
00086 void SetString (const char* s)
00087 {
00088 if (type == CSVAR_STRING) delete[] v.s;
00089 type = CSVAR_STRING;
00090 if (s)
00091 v.s = csStrNew (s);
00092 else
00093 v.s = NULL;
00094 }
00096 void SetCommand ()
00097 {
00098 if (type == CSVAR_STRING) delete[] v.s;
00099 type = CSVAR_CMD;
00100 }
00101
00103 long GetLong () const
00104 {
00105 CS_ASSERT (type == CSVAR_LONG);
00106 return v.l;
00107 }
00109 bool GetBool () const
00110 {
00111 CS_ASSERT (type == CSVAR_BOOL);
00112 return v.b;
00113 }
00115 float GetFloat () const
00116 {
00117 CS_ASSERT (type == CSVAR_FLOAT);
00118 return v.f;
00119 }
00121 const char* GetString () const
00122 {
00123 CS_ASSERT (type == CSVAR_STRING);
00124 return v.s;
00125 }
00126 csVariantType GetType () const { return type; }
00127 };
00128
00130 struct csOptionDescription
00131 {
00133 int id;
00135 char* name;
00137 char* description;
00139 csVariantType type;
00140 };
00141
00142 SCF_VERSION (iConfig, 1, 0, 0);
00143
00149 struct iConfig : public iBase
00150 {
00152 virtual bool GetOptionDescription (int idx, csOptionDescription *option) = 0;
00154 virtual bool SetOption (int id, csVariant* value) = 0;
00156 virtual bool GetOption (int id, csVariant* value) = 0;
00157 };
00160 #endif // __CS_IUTIL_CONFIG_H__