Sese Framework  x.y.z
A cross-platform framework
载入中...
搜索中...
未找到
ConfigUtil.h
浏览该文件的文档.
1// Copyright 2024 libsese
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
23#pragma once
24
25#include "sese/io/InputStream.h"
27
28#include <map>
29
30#ifdef _WIN32
31#pragma warning(disable : 4251)
32#endif
33
34namespace sese {
35
40public:
41 using Ptr = std::shared_ptr<ConfigObject>;
42
44 struct Section {
45 using Ptr = std::shared_ptr<Section>;
46
47 std::string name;
48 std::map<std::string, std::string> parameter{};
49
50 explicit Section(std::string name);
57 [[nodiscard]] std::string getValueByKey(const std::string &key, const std::string &default_value)const;
58 void setKeyValue(const std::string &key, const std::string &value);
59 };
60
61public:
63 [[nodiscard]] Section::Ptr getDefaultSection() const noexcept { return this->defaultSection; } // GCOVR_EXCL_LINE
69 [[nodiscard]] Section::Ptr getSectionByName(const std::string &section_name)const;
70 void setSection(const Section::Ptr &section);
71 [[nodiscard]] const std::map<std::string, Section::Ptr> &getAllSection() const;
72
73private:
75 std::map<std::string, Section::Ptr> sections;
76};
77
82public:
85
98 static bool write2(const ConfigObject::Ptr &config_file, OutputStream *output);
99
100private:
101 static std::string readLine(InputStream *input);
102};
103} // namespace sese