00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef __IUTIL_CONFIG_H__
00020 #define __IUTIL_CONFIG_H__
00021
00022 #include "csutil/scf.h"
00023 #include "csutil/util.h"
00024
00025 enum csVariantType
00026 {
00027 CSVAR_LONG,
00028 CSVAR_BOOL,
00029 CSVAR_CMD,
00030 CSVAR_FLOAT,
00031 CSVAR_STRING
00032 };
00033
00034 struct csVariant
00035 {
00036 private:
00037 csVariantType type;
00038 union value
00039 {
00040 long l;
00041 bool b;
00042 float f;
00043 char* s;
00044 } v;
00045
00046 public:
00047 csVariant () { type = CSVAR_LONG; v.s = NULL; }
00048 ~csVariant () { if (type == CSVAR_STRING) delete[] v.s; }
00049 void SetLong (long l)
00050 {
00051 if (type == CSVAR_STRING) delete[] v.s;
00052 type = CSVAR_LONG;
00053 v.l = l;
00054 }
00055 void SetBool (bool b)
00056 {
00057 if (type == CSVAR_STRING) delete[] v.s;
00058 type = CSVAR_BOOL;
00059 v.b = b;
00060 }
00061 void SetFloat (float f)
00062 {
00063 if (type == CSVAR_STRING) delete[] v.s;
00064 type = CSVAR_FLOAT;
00065 v.f = f;
00066 }
00067 void SetString (const char* s)
00068 {
00069 if (type == CSVAR_STRING) delete[] v.s;
00070 type = CSVAR_STRING;
00071 if (s)
00072 v.s = csStrNew (s);
00073 else
00074 v.s = NULL;
00075 }
00076 void SetCommand ()
00077 {
00078 if (type == CSVAR_STRING) delete[] v.s;
00079 type = CSVAR_CMD;
00080 }
00081
00082 long GetLong () const
00083 {
00084 CS_ASSERT (type == CSVAR_LONG);
00085 return v.l;
00086 }
00087 bool GetBool () const
00088 {
00089 CS_ASSERT (type == CSVAR_BOOL);
00090 return v.b;
00091 }
00092 float GetFloat () const
00093 {
00094 CS_ASSERT (type == CSVAR_FLOAT);
00095 return v.f;
00096 }
00097 const char* GetString () const
00098 {
00099 CS_ASSERT (type == CSVAR_STRING);
00100 return v.s;
00101 }
00102 csVariantType GetType () const { return type; }
00103 };
00104
00105 struct csOptionDescription
00106 {
00107 int id;
00108 char* name;
00109 char* description;
00110 csVariantType type;
00111 };
00112
00113 SCF_VERSION (iConfig, 1, 0, 0);
00114
00120 struct iConfig : public iBase
00121 {
00123 virtual bool GetOptionDescription (int idx, csOptionDescription *option) = 0;
00125 virtual bool SetOption (int id, csVariant* value) = 0;
00127 virtual bool GetOption (int id, csVariant* value) = 0;
00128 };
00129
00130 #endif // __IUTIL_CONFIG_H__