# 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
    00015 #include "fileio_type.h"
    00016
    00018 enum IniGroupType {
    00019   IGT_VARIABLES = 0,
    00020   IGT_LIST      = 1,
    00021   IGT_SEQUENCE  = 2,
    00022 };
    00023
    00025 struct IniItem {
    00026   IniItem *next;
    00027   char *name;
    00028   char *value;
    00029   char *comment;
    00030
    00031   IniItem(struct IniGroup *parent, const char *name, size_t len = 0);
    00032   ~IniItem();
    00033
    00034   void SetValue(const char *value);
    00035 };
    00036
    00038 struct IniGroup {
    00039   IniGroup *next;
    00040   IniGroupType type;
    00041   IniItem *item;
    00042   IniItem **last_item;
    00043   char *name;
    00044   char *comment;
    00045
    00046   IniGroup(struct IniLoadFile *parent, const char *name, size_t len = 0);
    00047   ~IniGroup();
    00048
    00049   IniItem *GetItem(const char *name, bool create);
    00050   void Clear();
    00051 };
    00052
    00054 struct IniLoadFile {
    00055   IniGroup *group;
    00056   IniGroup **last_group;
    00057   char *comment;
    00058   const char * const *list_group_names;
    00059   const char * const *seq_group_names;
    00060
    00061   IniLoadFile(const char * const *list_group_names = NULL, const char * const *seq_group_names = NULL);
    00062   virtual ~IniLoadFile();
    00063
    00064   IniGroup *GetGroup(const char *name, size_t len = 0, bool create_new = true);
    00065   void RemoveGroup(const char *name);
    00066
    00067   void LoadFromDisk(const char *filename, Subdirectory subdir);
    00068
    00076   virtual FILE *OpenFile(const char *filename, Subdirectory subdir, size_t *size) = 0;
    00077
    00084   virtual void ReportFileError(const char * const pre, const char * const buffer, const char * const post) = 0;
    00085 };
    00086
    00088 struct IniFile : IniLoadFile {
    00089   IniFile(const char * const *list_group_names = NULL);
    00090
    00091   bool SaveToDisk(const char *filename);
    00092
    00093   virtual FILE *OpenFile(const char *filename, Subdirectory subdir, size_t *size);
    00094   virtual void ReportFileError(const char * const pre, const char * const buffer, const char * const post);
    00095 };
    00096
    00097 #endif /* INI_TYPE_H */