CrystalSpace

Public API Reference

iutil/pluginconfig.h
Go to the documentation of this file.
00001 /*
00002     Copyright (C) 1998 by Jorrit Tyberghein
00003 
00004     This library is free software; you can redistribute it and/or
00005     modify it under the terms of the GNU Library General Public
00006     License as published by the Free Software Foundation; either
00007     version 2 of the License, or (at your option) any later version.
00008 
00009     This library is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012     Library General Public License for more details.
00013 
00014     You should have received a copy of the GNU Library General Public
00015     License along with this library; if not, write to the Free
00016     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
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__

Generated for Crystal Space 2.0 by doxygen 1.7.6.1