Kiwano Engine v1.3.x
ConfigIni.h
1// Copyright (c) 2016-2018 Kiwano - Nomango
2//
3// Permission is hereby granted, free of charge, to any person obtaining a copy
4// of this software and associated documentation files (the "Software"), to deal
5// in the Software without restriction, including without limitation the rights
6// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7// copies of the Software, and to permit persons to whom the Software is
8// furnished to do so, subject to the following conditions:
9//
10// The above copyright notice and this permission notice shall be included in
11// all copies or substantial portions of the Software.
12//
13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19// THE SOFTWARE.
20
21#pragma once
22#include <kiwano/core/Common.h>
23#include <kiwano/base/ObjectBase.h>
24
25namespace kiwano
26{
27
30class KGE_API ConfigIni : public ObjectBase
31{
32public:
35 typedef UnorderedMap<String, String> ValueMap;
36
39 typedef UnorderedMap<String, ValueMap> SectionMap;
40
41 ConfigIni();
42
46 ConfigIni(StringView file_path);
47
51 bool Load(StringView file_path);
52
56 bool Load(std::istream& is);
57
61 bool LoadFromString(StringView content);
62
66 bool Save(StringView file_path);
67
71 bool Save(std::ostream& os);
72
76 bool SaveToString(String& content);
77
81 bool HasSection(StringView section) const;
82
87 bool HasKey(StringView section, StringView key) const;
88
91 SectionMap GetSectionMap() const;
92
96 ValueMap GetSection(StringView section) const;
97
102 String GetString(StringView section, StringView key, StringView default_value = String()) const;
103
109 float GetFloat(StringView section, StringView key, float default_value = 0.0f) const;
110
116 double GetDouble(StringView section, StringView key, double default_value = 0.0) const;
117
123 int GetInt(StringView section, StringView key, int default_value = 0) const;
124
130 bool GetBool(StringView section, StringView key, bool default_value = false) const;
131
135 void SetSectionMap(const SectionMap& sections);
136
141 void SetSection(StringView section, const ValueMap& values);
142
148 void SetString(StringView section, StringView key, StringView value);
149
155 void SetFloat(StringView section, StringView key, float value);
156
162 void SetDouble(StringView section, StringView key, double value);
163
169 void SetInt(StringView section, StringView key, int value);
170
176 void SetBool(StringView section, StringView key, bool value);
177
181 void DeleteSection(StringView section);
182
187 void DeleteKey(StringView section, StringView key);
188
189 ValueMap& operator[](StringView section);
190
191 const ValueMap& operator[](StringView section) const;
192
193private:
194 void ParseLine(StringView line, String* section);
195
196private:
197 SectionMap sections_;
198};
199
200} // namespace kiwano
ini格式文件
Definition: ConfigIni.h:31
UnorderedMap< String, String > ValueMap
键值字典
Definition: ConfigIni.h:35
UnorderedMap< String, ValueMap > SectionMap
Section字典
Definition: ConfigIni.h:39
基础对象
Definition: ObjectBase.h:138