CrystalSpace

Public API Reference

Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

config.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_CONFIG_H__
00020 #define __CS_IUTIL_CONFIG_H__
00021 
00026 #include "csutil/scf.h"
00027 #include "csutil/util.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 (type == CSVAR_STRING) delete[] v.s;
00089     type = CSVAR_STRING;
00090     if (s)
00091       v.s = csStrNew (s);
00092     else
00093       v.s = 0;
00094   }
00096   void SetCommand ()
00097   {
00098     if (type == CSVAR_STRING) delete[] v.s;
00099     type = CSVAR_CMD;
00100   }
00101 
00103   long GetLong () const
00104   {
00105     CS_ASSERT (type == CSVAR_LONG);
00106     return v.l;
00107   }
00109   bool GetBool () const
00110   {
00111     CS_ASSERT (type == CSVAR_BOOL);
00112     return v.b;
00113   }
00115   float GetFloat () const
00116   {
00117     CS_ASSERT (type == CSVAR_FLOAT);
00118     return v.f;
00119   }
00121   const char* GetString () const
00122   {
00123     CS_ASSERT (type == CSVAR_STRING);
00124     return v.s;
00125   }
00126   csVariantType GetType () const { return type; }
00127 };
00128 
00130 struct csOptionDescription
00131 {
00133   int id;
00135   char* name;           
00137   char* description;    
00139   csVariantType type;   
00140 };
00141 
00142 SCF_VERSION (iConfig, 1, 0, 0);
00143 
00149 struct iConfig : public iBase
00150 {
00152   virtual bool GetOptionDescription (int idx, csOptionDescription *option) = 0;
00154   virtual bool SetOption (int id, csVariant* value) = 0;
00156   virtual bool GetOption (int id, csVariant* value) = 0;
00157 };
00160 #endif // __CS_IUTIL_CONFIG_H__

Generated for Crystal Space by doxygen 1.2.14