My Project
IniParser.h
1 /*
2  * Copyright (C) 2013 Canonical Ltd
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License version 3 as
6  * published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * Authored by: Jussi Pakkanen <jussi.pakkanen@canonical.com>
17  */
18 
19 #ifndef LOMIRI_UTIL_INIPARSER_H
20 #define LOMIRI_UTIL_INIPARSER_H
21 
22 #include <lomiri/SymbolExport.h>
24 
25 #include <string>
26 #include <vector>
27 
28 namespace lomiri
29 {
30 
31 namespace util
32 {
33 
34 namespace internal
35 {
36 struct IniParserPrivate;
37 }
38 
71 class LOMIRI_API IniParser final {
72 public:
74  IniParser(const char* filename);
75  ~IniParser() noexcept;
76 
79 
80  IniParser(const IniParser& ip) = delete;
81  IniParser() = delete;
83 
84  //{@
85 
92  bool has_group(const std::string& group) const noexcept;
93  bool has_key(const std::string& group, const std::string& key) const;
94 
95  std::string get_string(const std::string& group, const std::string& key) const;
96  std::string get_locale_string(const std::string& group,
97  const std::string& key,
98  const std::string& locale = std::string()) const;
99  bool get_boolean(const std::string& group, const std::string& key) const;
100  int get_int(const std::string& group, const std::string& key) const;
101  double get_double(const std::string& group, const std::string& key) const;
102 
103  std::vector<std::string> get_string_array(const std::string& group, const std::string& key) const;
104  std::vector<std::string> get_locale_string_array(const std::string& group,
105  const std::string& key,
106  const std::string& locale = std::string()) const;
107  std::vector<bool> get_boolean_array(const std::string& group, const std::string& key) const;
108  std::vector<int> get_int_array(const std::string& group, const std::string& key) const;
109  std::vector<double> get_double_array(const std::string& group, const std::string& key) const;
110 
111  std::string get_start_group() const;
112  std::vector<std::string> get_groups() const;
113  std::vector<std::string> get_keys(const std::string& group) const;
114 
122  bool remove_group(const std::string& group);
123  bool remove_key(const std::string& group, const std::string& key);
124 
125  void set_string(const std::string& group, const std::string& key, const std::string& value);
126  void set_locale_string(const std::string& group,
127  const std::string& key,
128  const std::string& value,
129  const std::string& locale = std::string());
130  void set_boolean(const std::string& group, const std::string& key, bool value);
131  void set_int(const std::string& group, const std::string& key, int value);
132  void set_double(const std::string& group, const std::string& key, double value);
133 
134  void set_string_array(const std::string& group, const std::string& key, const std::vector<std::string>& value);
135  void set_locale_string_array(const std::string& group,
136  const std::string& key,
137  const std::vector<std::string>& value,
138  const std::string& locale = std::string());
139  void set_boolean_array(const std::string& group, const std::string& key, const std::vector<bool>& value);
140  void set_int_array(const std::string& group, const std::string& key, const std::vector<int>& value);
141  void set_double_array(const std::string& group, const std::string& key, const std::vector<double>& value);
142 
148  void sync();
149 
151 
152 private:
153  internal::IniParserPrivate* p;
154 };
155 
156 
157 } // namespace util
158 
159 } // namespace lomiri
160 
161 #endif
#define LOMIRI_DEFINES_PTRS(classname)
Macro to add smart pointer definitions to a class.
Definition: DefinesPtrs.h:52
Helper class to read and write configuration files.
Definition: IniParser.h:71
Top-level namespace for all things Lomiri-related.
Definition: Version.h:38