Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

Ini.h

Go to the documentation of this file.
00001 /*
00002  * Ini.h
00003  *
00004  * Part of Fly! Legacy project
00005  *
00006  * Copyright 2003 Chris Wallace
00007  *
00008  * Fly! Legacy is free software; you can redistribute it and/or modify
00009  *   it under the terms of the GNU General Public License as published by
00010  *   the Free Software Foundation; either version 2 of the License, or
00011  *   (at your option) any later version.
00012  *
00013  * Fly! Legacy is distributed in the hope that it will be useful,
00014  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  *   GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  *   along with Fly! Legacy; if not, write to the Free Software
00020  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021  *
00022  */
00023 
00028 #ifndef INI_H
00029 #define INI_H
00030 
00031 #include "FlyLegacy.h"
00032 #include <map>
00033 #include <string>
00034 
00035 
00036 typedef enum {
00037   INI_UNKNOWN_SETTING,
00038   INI_FLOAT_SETTING,
00039   INI_INT_SETTING,
00040   INI_STRING_SETTING
00041 } EIniSettingType;
00042 
00043 
00044 /*
00045  * CIniSetting
00046  */
00047 
00048 class CIniSetting {
00049 public:
00050   // Constructor
00051   CIniSetting (const char* key);
00052 
00053   // CIniSetting methods
00054   void    Set (float f);
00055   void    Set (int i);
00056   void    Set (const char* s);
00057   void    Get (float* f);
00058   void    Get (int* i);
00059   void    Get (char* s, int maxLength);
00060   void    Save (FILE *f);
00061 
00062 public:
00063   EIniSettingType type;
00064   char      key[64];
00065   float     value;
00066   char      s_value[64];
00067 };
00068 
00069 
00070 /*
00071  * CIniSection
00072  */
00073 
00074 class CIniSection {
00075 public:
00076   // Constructor
00077   CIniSection (const char* section);
00078   ~CIniSection (void);
00079 
00080   // CIniSection methods
00081   void    Set (const char* key, float f);
00082   void    Set (const char* key, int i);
00083   void    Set (const char* key, const char* s);
00084   void    Get (const char* key, float *f);
00085   void    Get (const char* key, int *i);
00086   void    Get (const char* key, char *s, int maxLength);
00087   void    Save (FILE *f);
00088   void    Remove (const char* key);
00089 
00090 protected:
00091   // CIniSection methods
00092   CIniSetting*  FindSetting (const char* key);
00093   void      Clear (void);
00094 
00095 public:
00096   char                                section[64];  // Section name
00097   std::map<std::string,CIniSetting*>  setting;      // Setting map indexed by key name
00098 };
00099 
00100 
00101 /*
00102  * CIniFile
00103  */
00104 
00105 class CIniFile {
00106 public:
00107   // Constructor
00108   CIniFile (void);
00109   CIniFile (const char* iniFilename);
00110   ~CIniFile (void);
00111 
00112   // CIniFile methods
00113   int       Load (const char* iniFilename);
00114   int       Merge (const char* iniFilename);
00115   int       Save (const char* iniFilename);
00116   void      Set (const char* section, const char* key, float f);
00117   void      Set (const char* section, const char* key, int i);
00118   void      Set (const char* section, const char* key, const char* s);
00119   void      Get (const char* section, const char* key, float* f);
00120   void      Get (const char* section, const char* key, int* i);
00121   void      Get (const char* section, const char* key, char* s, int maxLength);
00122   void      Remove (const char* section, const char* key);
00123   int       GetNumSections (void);
00124   char*     GetSectionName (int i);
00125 
00126 protected:
00127   // CIniFile methods
00128   CIniSection*  FindSection (const char* sectname);
00129   void      Clear (void);
00130 
00131 protected:
00132   std::map<std::string,CIniSection*>  section;    // Section map indexed by name
00133 };
00134 
00135 #endif // INI_H
SourceForge.net Logo Documentation generated by doxygen