CppZmqZoltanExt 0.0.1
Loading...
Searching...
No Matches
zpl_config.h
Go to the documentation of this file.
1/*
2MIT License
3
4Copyright (c) 2025 Luan Young
5
6Permission is hereby granted, free of charge, to any person obtaining a copy
7of this software and associated documentation files (the "Software"), to deal
8in the Software without restriction, including without limitation the rights
9to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10copies of the Software, and to permit persons to whom the Software is
11furnished to do so, subject to the following conditions:
12
13The above copyright notice and this permission notice shall be included in all
14copies or substantial portions of the Software.
15
16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22SOFTWARE.
23*/
65#pragma once
66
67#include <cstddef>
68#include <istream>
69#include <memory>
70#include <optional>
71#include <stdexcept>
72#include <string>
73#include <vector>
74
75#include "cppzmqzoltanext/czze_export.h"
76
77namespace zmqzext {
78
84class CZZE_EXPORT zpl_error : public std::runtime_error {
85public:
86 using std::runtime_error::runtime_error;
87};
88
92class CZZE_EXPORT zpl_parse_error : public zpl_error {
93public:
100 zpl_parse_error(std::string message, std::size_t line);
101
107 std::size_t line() const noexcept;
108
109private:
110 std::size_t _line;
111};
112
116class CZZE_EXPORT zpl_property_not_found : public zpl_error {
117public:
118 using zpl_error::zpl_error;
119};
120
137class CZZE_EXPORT zpl_config_t {
138public:
142 zpl_config_t() noexcept;
143
151 explicit zpl_config_t(std::istream& input);
152
161 static zpl_config_t from_stream(std::istream& input);
162
171 static zpl_config_t from_file(const std::string& file_path);
172
182 void load(std::istream& input);
183
193 void load_from_file(const std::string& file_path);
194
200 bool empty() const noexcept;
201
207 const std::string& name() const noexcept;
208
214 const std::string& value() const noexcept;
215
222 bool contains(const std::string& path) const noexcept;
223
231 const std::string& get(const std::string& path) const;
232
239 std::optional<std::string> try_get(const std::string& path) const noexcept;
240
248 std::string get_or(const std::string& path, std::string default_value) const noexcept;
249
257 zpl_config_t child(const std::string& path) const;
258
265 std::optional<zpl_config_t> try_child(const std::string& path) const noexcept;
266
272 std::vector<zpl_config_t> children() const noexcept;
273
274private:
278 struct impl_t;
279 std::shared_ptr<impl_t> _impl;
280};
281
282} // namespace zmqzext
ZPL configuration tree loaded from text or file.
Definition: zpl_config.h:137
Base exception for ZPL configuration errors.
Definition: zpl_config.h:84
Exception thrown when a badly formatted ZPL input is encountered during parsing.
Definition: zpl_config.h:92
Exception thrown when a requested property is missing.
Definition: zpl_config.h:116
std::string value
Raw string value.
Definition: zpl_config.cpp:55
std::string name
Node name segment.
Definition: zpl_config.cpp:54