Hugintrunk  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
IniParser.h
Go to the documentation of this file.
1 // -*- c-basic-offset: 4 -*-
2 
12  /* This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public
14  * License as published by the Free Software Foundation; either
15  * version 2 of the License, or (at your option) any later version.
16  *
17  * This software is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20  * General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public
23  * License along with this software. If not, see
24  * <http://www.gnu.org/licenses/>.
25  *
26  */
27 
28 #ifndef INI_PARSER_H
29 #define INI_PARSER_H
30 
31 #include <string>
32 #include <map>
33 #include <vector>
34 
37 class IniParser
38 {
39 public:
43  int Read(const std::string& file);
44 
46  bool HasKey(const std::string& section, const std::string& key) const;
47 
49  std::string GetKey(const std::string& section, const std::string& key, const std::string& defaultValue) const;
50  int GetKey(const std::string& section, const std::string& key, const int defaultValue) const;
51  bool GetKey(const std::string& section, const std::string& key, const bool defaultValue) const;
52 
54  std::vector<std::string> GetSections() const;
56  std::vector<std::string> GetKeys(const std::string& section) const;
58  void PrintValues() const;
59 private:
61  typedef std::map<std::string, std::string> IniValues;
63  std::map<std::string, IniValues> m_iniValues;
64 };
65 
66 #endif
bool HasKey(const std::string &section, const std::string &key) const
Checks if given section/key exists.
Definition: IniParser.cpp:87
std::vector< std::string > GetKeys(const std::string &section) const
returns a vector of all know keys in given section
Definition: IniParser.cpp:168
void PrintValues() const
for debugging purpose, print all values
Definition: IniParser.cpp:182
std::vector< std::string > GetSections() const
returns a vector of all know sections
Definition: IniParser.cpp:157
std::string GetKey(const std::string &section, const std::string &key, const std::string &defaultValue) const
returns the value of the given section/key or default value if it does not exists ...
Definition: IniParser.cpp:100
std::map< std::string, std::string > IniValues
stores the key/values pairs for each section
Definition: IniParser.h:61
int Read(const std::string &file)
Reads the given ini file.
Definition: IniParser.cpp:34
std::map< std::string, IniValues > m_iniValues
map to store the information from different sections
Definition: IniParser.h:63
A simple parser for ini files, it implements only some basic features.
Definition: IniParser.h:37