Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef __CS_IUTIL_PLUGINCONFIG_H__
00020 #define __CS_IUTIL_PLUGINCONFIG_H__
00021
00027 #include "csutil/scf.h"
00028 #include "csutil/scfstr.h"
00029
00031 enum csVariantType
00032 {
00034 CSVAR_LONG,
00036 CSVAR_BOOL,
00038 CSVAR_CMD,
00040 CSVAR_FLOAT,
00042 CSVAR_STRING
00043 };
00044
00050 struct csVariant
00051 {
00052 private:
00053 csVariantType type;
00054 union value
00055 {
00056 long l;
00057 bool b;
00058 float f;
00059 iString* s;
00060 } v;
00061 void Clear()
00062 {
00063 if ((type == CSVAR_STRING) && (v.s != 0)) v.s->DecRef();
00064 }
00065 public:
00067 csVariant () { type = CSVAR_CMD; memset (&v, 0, sizeof (v)); }
00069 csVariant (int i) { type = CSVAR_LONG; v.l = i; }
00071 csVariant (long l) { type = CSVAR_LONG; v.l = l; }
00073 csVariant (bool b) { type = CSVAR_BOOL; v.b = b; }
00075 csVariant (float f) { type = CSVAR_FLOAT; v.f = f; }
00077 csVariant (const char* s) { type = CSVAR_STRING; v.s = s ? new scfString (s) : nullptr; }
00078
00080 csVariant (const csVariant& var)
00081 {
00082 memset (&v, 0, sizeof (v));
00083
00084 type = var.type;
00085 v = var.v;
00086 if ((type == CSVAR_STRING) && (v.s != 0)) v.s->IncRef();
00087 }
00088
00089 ~csVariant () { Clear(); }
00090
00092 const csVariant& operator = (const csVariant& var)
00093 {
00094 Clear ();
00095 type = var.type;
00096 v = var.v;
00097 if ((type == CSVAR_STRING) && (v.s != 0)) v.s->IncRef ();
00098 return var;
00099 }
00100
00102 void SetLong (long l)
00103 {
00104 Clear();
00105 type = CSVAR_LONG;
00106 v.l = l;
00107 }
00109 void SetBool (bool b)
00110 {
00111 Clear();
00112 type = CSVAR_BOOL;
00113 v.b = b;
00114 }
00116 void SetFloat (float f)
00117 {
00118 Clear();
00119 type = CSVAR_FLOAT;
00120 v.f = f;
00121 }
00123 void SetString (const char* s)
00124 {
00125 Clear();
00126 type = CSVAR_STRING;
00127 if (s)
00128 v.s = new scfString (s);
00129 else
00130 v.s = 0;
00131 }
00133 void SetCommand ()
00134 {
00135 Clear();
00136 type = CSVAR_CMD;
00137 }
00138
00140 long GetLong () const
00141 {
00142 CS_ASSERT (type == CSVAR_LONG);
00143 return v.l;
00144 }
00146 bool GetBool () const
00147 {
00148 CS_ASSERT (type == CSVAR_BOOL);
00149 return v.b;
00150 }
00152 float GetFloat () const
00153 {
00154 CS_ASSERT (type == CSVAR_FLOAT);
00155 return v.f;
00156 }
00158 const char* GetString () const
00159 {
00160 CS_ASSERT (type == CSVAR_STRING);
00161 return v.s->GetData();
00162 }
00163
00165 csVariantType GetType () const { return type; }
00166 };
00167
00169 struct csOptionDescription
00170 {
00172 int id;
00174 csString name;
00176 csString description;
00178 csVariantType type;
00179
00181 csOptionDescription () {}
00182
00190 csOptionDescription (int id, const char* name, const char* description, csVariantType type)
00191 : id (id), name (name), description (description), type (type) {}
00192
00200 csOptionDescription (const char* name, const char* description, csVariantType type)
00201 : id (0), name (name), description (description), type (type) {}
00202
00203 ~csOptionDescription () {}
00204 };
00205
00221 struct iPluginConfig : public virtual iBase
00222 {
00223 SCF_INTERFACE (iPluginConfig,2,1,0);
00224
00231 virtual bool GetOptionDescription (int index, csOptionDescription* option) = 0;
00232
00239 virtual bool SetOption (int index, csVariant* value) = 0;
00240
00247 virtual bool GetOption (int index, csVariant* value) = 0;
00248 };
00251 #endif // __CS_IUTIL_PLUGINCONFIG_H__