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:
00066   csVariant () { type = CSVAR_LONG; memset (&v, 0, sizeof (v)); }
00067   ~csVariant () { Clear(); }
00068 
00070   csVariant (const csVariant& var)
00071   {
00072     memset (&v, 0, sizeof (v));
00073     
00074     type = var.type;
00075     v = var.v;
00076     if ((type == CSVAR_STRING) && (v.s != 0)) v.s->IncRef(); 
00077   }
00078 
00080   const csVariant& operator = (const csVariant& var)
00081   {
00082     Clear ();
00083     type = var.type;
00084     v = var.v;
00085     if ((type == CSVAR_STRING) && (v.s != 0)) v.s->IncRef ();
00086     return var;
00087   }
00088   
00090   void SetLong (long l)
00091   {
00092     Clear();
00093     type = CSVAR_LONG;
00094     v.l = l;
00095   }
00097   void SetBool (bool b)
00098   {
00099     Clear();
00100     type = CSVAR_BOOL;
00101     v.b = b;
00102   }
00104   void SetFloat (float f)
00105   {
00106     Clear();
00107     type = CSVAR_FLOAT;
00108     v.f = f;
00109   }
00111   void SetString (const char* s)
00112   {
00113     Clear();
00114     type = CSVAR_STRING;
00115     if (s)
00116       v.s = new scfString (s);
00117     else
00118       v.s = 0;
00119   }
00121   void SetCommand ()
00122   {
00123     Clear();
00124     type = CSVAR_CMD;
00125   }
00126 
00128   long GetLong () const
00129   {
00130     CS_ASSERT (type == CSVAR_LONG);
00131     return v.l;
00132   }
00134   bool GetBool () const
00135   {
00136     CS_ASSERT (type == CSVAR_BOOL);
00137     return v.b;
00138   }
00140   float GetFloat () const
00141   {
00142     CS_ASSERT (type == CSVAR_FLOAT);
00143     return v.f;
00144   }
00146   const char* GetString () const
00147   {
00148     CS_ASSERT (type == CSVAR_STRING);
00149     return v.s->GetData();
00150   }
00151   csVariantType GetType () const { return type; }
00152 };
00153 
00155 struct csOptionDescription
00156 {
00158   int id;
00160   const char* name;             
00162   const char* description;      
00164   csVariantType type;   
00165 };
00166 
00182 struct iPluginConfig : public virtual iBase
00183 {
00184   SCF_INTERFACE(iPluginConfig,2,1,0);
00186   virtual bool GetOptionDescription (int idx, csOptionDescription *option) = 0;
00188   virtual bool SetOption (int id, csVariant* value) = 0;
00190   virtual bool GetOption (int id, csVariant* value) = 0;
00191 };
00194 #endif // __CS_IUTIL_PLUGINCONFIG_H__

Generated for Crystal Space by doxygen 1.4.7