Sese Framework  2.3.0
A cross-platform framework
Loading...
Searching...
No Matches
ConfigUtil.h
Go to the documentation of this file.
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
62 [[nodiscard]] Section::Ptr getDefaultSection() const noexcept { return this->defaultSection; } // GCOVR_EXCL_LINE
68 [[nodiscard]] Section::Ptr getSectionByName(const std::string &section_name) const;
69 void setSection(const Section::Ptr &section);
70 [[nodiscard]] const std::map<std::string, Section::Ptr> &getAllSection() const;
71
72private:
74 std::map<std::string, Section::Ptr> sections;
75};
76
81public:
84
97 static bool write2(const ConfigObject::Ptr &config_file, OutputStream *output);
98
99private:
100 static std::string readLine(InputStream *input);
101};
102} // namespace sese