ini_type.h

Go to the documentation of this file.
00001 /* $Id$ */
00002 
00003 /*
00004  * This file is part of OpenTTD.
00005  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
00006  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00007  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
00008  */
00009 
00012 #ifndef INI_TYPE_H
00013 #define INI_TYPE_H
00014 
00016 enum IniGroupType {
00017   IGT_VARIABLES = 0, 
00018   IGT_LIST      = 1, 
00019   IGT_SEQUENCE  = 2, 
00020 };
00021 
00023 struct IniItem {
00024   IniItem *next; 
00025   char *name;    
00026   char *value;   
00027   char *comment; 
00028 
00029   IniItem(struct IniGroup *parent, const char *name, size_t len = 0);
00030   ~IniItem();
00031 
00032   void SetValue(const char *value);
00033 };
00034 
00036 struct IniGroup {
00037   IniGroup *next;      
00038   IniGroupType type;   
00039   IniItem *item;       
00040   IniItem **last_item; 
00041   char *name;          
00042   char *comment;       
00043 
00044   IniGroup(struct IniLoadFile *parent, const char *name, size_t len = 0);
00045   ~IniGroup();
00046 
00047   IniItem *GetItem(const char *name, bool create);
00048   void Clear();
00049 };
00050 
00052 struct IniLoadFile {
00053   IniGroup *group;                      
00054   IniGroup **last_group;                
00055   char *comment;                        
00056   const char * const *list_group_names; 
00057   const char * const *seq_group_names;  
00058 
00059   IniLoadFile(const char * const *list_group_names = NULL, const char * const *seq_group_names = NULL);
00060   virtual ~IniLoadFile();
00061 
00062   IniGroup *GetGroup(const char *name, size_t len = 0, bool create_new = true);
00063   void RemoveGroup(const char *name);
00064 
00065   void LoadFromDisk(const char *filename);
00066 
00073   virtual FILE *OpenFile(const char *filename, size_t *size) = 0;
00074 
00081   virtual void ReportFileError(const char * const pre, const char * const buffer, const char * const post) = 0;
00082 };
00083 
00085 struct IniFile : IniLoadFile {
00086   IniFile(const char * const *list_group_names = NULL);
00087 
00088   bool SaveToDisk(const char *filename);
00089 
00090   virtual FILE *OpenFile(const char *filename, size_t *size);
00091   virtual void ReportFileError(const char * const pre, const char * const buffer, const char * const post);
00092 };
00093 
00094 #endif /* INI_TYPE_H */

Generated on Sun Jun 5 04:19:57 2011 for OpenTTD by  doxygen 1.6.1