INIFile.h

Go to the documentation of this file.
00001 /*
00002 Copyright (C) 2004 The Pentagram team
00003 
00004 This program is free software; you can redistribute it and/or
00005 modify it under the terms of the GNU General Public License
00006 as published by the Free Software Foundation; either version 2
00007 of the License, or (at your option) any later version.
00008 
00009 This program 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
00012 GNU General Public License for more details.
00013 
00014 You should have received a copy of the GNU General Public License
00015 along with this program; if not, write to the Free Software
00016 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017 */
00018 
00019 #ifndef INIFILE_H
00020 #define INIFILE_H
00021 
00022 #include <set>
00023 #include <list>
00024 
00025 class INIFile
00026 {
00027 public:
00028         INIFile();
00029         INIFile(std::string fname, Pentagram::istring root);
00030         ~INIFile();
00031 
00032         bool readConfigFile(std::string fname);
00033 
00035         bool readConfigString(std::string s);
00036 
00037         void clear(Pentagram::istring root);
00038 
00039         std::string dump();
00040         void write();
00041 
00042         void setReadonly() { readonly = true; }
00043         bool isReadonly() const { return readonly; }
00044 
00045         bool hasSection(Pentagram::istring section);
00046         bool hasKey(Pentagram::istring key);
00047         bool checkRoot(Pentagram::istring key);
00048 
00049         // get value
00050         bool value(Pentagram::istring key, std::string &ret);
00051         bool value(Pentagram::istring key, int &ret);
00052         bool value(Pentagram::istring key, bool &ret);
00053 
00054         // set value
00055         void set(Pentagram::istring key, std::string value);
00056         void set(Pentagram::istring key, const char* value);
00057         void set(Pentagram::istring key, int value);
00058         void set(Pentagram::istring key, bool value);
00059 
00060         // remove key
00061         void unset(Pentagram::istring key);
00062 
00063         void listKeys(std::set<Pentagram::istring>& keys,
00064                                   Pentagram::istring section,
00065                                   bool longformat=false);
00066 
00067         void listSections(std::set<Pentagram::istring>& sections,
00068                                           bool longformat=false);
00069 
00070         void listKeyValues(std::map<Pentagram::istring,std::string>& keyvalues,
00071                                            Pentagram::istring section,
00072                                            bool longformat = false);
00073 
00074 private:
00075         std::string filename;
00076         Pentagram::istring root;
00077         bool is_file;
00078         bool readonly;
00079 
00080         struct KeyValue {
00081                 Pentagram::istring key;
00082                 std::string value;
00083                 std::string comment;
00084         };
00085 
00086         struct Section {
00087                 Pentagram::istring name;
00088                 std::list<KeyValue> keys;
00089                 std::string comment;
00090 
00091                 bool hasKey(Pentagram::istring key);
00092                 KeyValue* getKey(Pentagram::istring key);
00093                 void setKey(Pentagram::istring key, std::string value);
00094                 void unsetKey(Pentagram::istring key);
00095 
00096                 std::string dump();
00097         };
00098 
00099         std::list<Section> sections;
00100 
00101 
00102         bool stripRoot(Pentagram::istring& key);
00103         Section* getSection(Pentagram::istring section);
00104         bool splitKey(Pentagram::istring key, Pentagram::istring& section,
00105                                   Pentagram::istring& sectionkey);
00106 
00107 };
00108 
00109 #endif

Generated on Fri Jul 27 22:27:19 2007 for pentagram by  doxygen 1.4.7