Google

Main Page   Class Hierarchy   Compound List   File List   Compound Members  

config.h

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 __IUTIL_CONFIG_H__
00020 #define __IUTIL_CONFIG_H__
00021 
00022 #include "csutil/scf.h"
00023 #include "csutil/util.h"
00024 
00025 enum csVariantType
00026 {
00027   CSVAR_LONG,
00028   CSVAR_BOOL,
00029   CSVAR_CMD,
00030   CSVAR_FLOAT,
00031   CSVAR_STRING
00032 };
00033 
00034 struct csVariant
00035 {
00036 private:
00037   csVariantType type;
00038   union value
00039   {
00040     long l;
00041     bool b;
00042     float f;
00043     char* s;
00044   } v;
00045 
00046 public:
00047   csVariant () { type = CSVAR_LONG; v.s = NULL; }
00048   ~csVariant () { if (type == CSVAR_STRING) delete[] v.s; }
00049   void SetLong (long l)
00050   {
00051     if (type == CSVAR_STRING) delete[] v.s;
00052     type = CSVAR_LONG;
00053     v.l = l;
00054   }
00055   void SetBool (bool b)
00056   {
00057     if (type == CSVAR_STRING) delete[] v.s;
00058     type = CSVAR_BOOL;
00059     v.b = b;
00060   }
00061   void SetFloat (float f)
00062   {
00063     if (type == CSVAR_STRING) delete[] v.s;
00064     type = CSVAR_FLOAT;
00065     v.f = f;
00066   }
00067   void SetString (const char* s)
00068   {
00069     if (type == CSVAR_STRING) delete[] v.s;
00070     type = CSVAR_STRING;
00071     if (s)
00072       v.s = csStrNew (s);
00073     else
00074       v.s = NULL;
00075   }
00076   void SetCommand ()
00077   {
00078     if (type == CSVAR_STRING) delete[] v.s;
00079     type = CSVAR_CMD;
00080   }
00081 
00082   long GetLong () const
00083   {
00084     CS_ASSERT (type == CSVAR_LONG);
00085     return v.l;
00086   }
00087   bool GetBool () const
00088   {
00089     CS_ASSERT (type == CSVAR_BOOL);
00090     return v.b;
00091   }
00092   float GetFloat () const
00093   {
00094     CS_ASSERT (type == CSVAR_FLOAT);
00095     return v.f;
00096   }
00097   const char* GetString () const
00098   {
00099     CS_ASSERT (type == CSVAR_STRING);
00100     return v.s;
00101   }
00102   csVariantType GetType () const { return type; }
00103 };
00104 
00105 struct csOptionDescription
00106 {
00107   int id;
00108   char* name;           // Short name of this option.
00109   char* description;    // Description for this option.
00110   csVariantType type;   // Type to use for this option.
00111 };
00112 
00113 SCF_VERSION (iConfig, 1, 0, 0);
00114 
00120 struct iConfig : public iBase
00121 {
00123   virtual bool GetOptionDescription (int idx, csOptionDescription *option) = 0;
00125   virtual bool SetOption (int id, csVariant* value) = 0;
00127   virtual bool GetOption (int id, csVariant* value) = 0;
00128 };
00129 
00130 #endif // __IUTIL_CONFIG_H__

Generated for Crystal Space by doxygen 1.2.5 written by Dimitri van Heesch, ©1997-2000