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 
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 = 0; }
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 (s != v.s)
00089     {
00090       if (type == CSVAR_STRING) delete[] v.s;
00091       type = CSVAR_STRING;
00092       if (s)
00093         v.s = csStrNew (s);
00094       else
00095         v.s = 0;
00096     }
00097   }
00099   void SetCommand ()
00100   {
00101     if (type == CSVAR_STRING) delete[] v.s;
00102     type = CSVAR_CMD;
00103   }
00104 
00106   long GetLong () const
00107   {
00108     CS_ASSERT (type == CSVAR_LONG);
00109     return v.l;
00110   }
00112   bool GetBool () const
00113   {
00114     CS_ASSERT (type == CSVAR_BOOL);
00115     return v.b;
00116   }
00118   float GetFloat () const
00119   {
00120     CS_ASSERT (type == CSVAR_FLOAT);
00121     return v.f;
00122   }
00124   const char* GetString () const
00125   {
00126     CS_ASSERT (type == CSVAR_STRING);
00127     return v.s;
00128   }
00129   csVariantType GetType () const { return type; }
00130 };
00131 
00133 struct csOptionDescription
00134 {
00136   int id;
00138   const char* name;             
00140   const char* description;      
00142   csVariantType type;   
00143 };
00144 
00160 struct iPluginConfig : public virtual iBase
00161 {
00162   SCF_INTERFACE(iPluginConfig,2,0,0);
00164   virtual bool GetOptionDescription (int idx, csOptionDescription *option) = 0;
00166   virtual bool SetOption (int id, csVariant* value) = 0;
00168   virtual bool GetOption (int id, csVariant* value) = 0;
00169 };
00172 #endif // __CS_IUTIL_PLUGINCONFIG_H__

Generated for Crystal Space by doxygen 1.4.6