Clio develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
ConfigFileJson.hpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of clio: https://github.com/XRPLF/clio
4 Copyright (c) 2024, the clio developers.
5
6 Permission to use, copy, modify, and distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#pragma once
21
22#include "util/newconfig/ConfigFileInterface.hpp"
23#include "util/newconfig/Error.hpp"
24#include "util/newconfig/Types.hpp"
25
26#include <boost/json/object.hpp>
27
28#include <expected>
29#include <filesystem>
30#include <string>
31#include <string_view>
32#include <vector>
33
34namespace util::config {
35
37class ConfigFileJson final : public ConfigFileInterface {
38 boost::json::object jsonObject_;
39
40public:
47 ConfigFileJson(boost::json::object jsonObj);
48
55 [[nodiscard]] Value
56 getValue(std::string_view key) const override;
57
64 [[nodiscard]] std::vector<Value>
65 getArray(std::string_view key) const override;
66
73 [[nodiscard]] bool
74 containsKey(std::string_view key) const override;
75
83 [[nodiscard]] static std::expected<ConfigFileJson, Error>
84 makeConfigFileJson(std::filesystem::path const& configFilePath);
85
92 [[nodiscard]] boost::json::object const&
93 inner() const;
94
95private:
104 void
105 flattenJson(boost::json::object const& jsonRootObject);
106};
107
108} // namespace util::config
The interface for configuration files.
Definition ConfigFileInterface.hpp:35
Json representation of config.
Definition ConfigFileJson.hpp:37
static std::expected< ConfigFileJson, Error > makeConfigFileJson(std::filesystem::path const &configFilePath)
Creates a new ConfigFileJson by parsing the provided JSON file and stores the values in the object.
Definition ConfigFileJson.cpp:91
ConfigFileJson(boost::json::object jsonObj)
Construct a new ConfigJson object and stores the values from user's config into a json object.
Definition ConfigFileJson.cpp:85
boost::json::object const & inner() const
Get the inner representation of json file.
Definition ConfigFileJson.cpp:145
Value getValue(std::string_view key) const override
Retrieves a configuration value by its key.
Definition ConfigFileJson.cpp:113
bool containsKey(std::string_view key) const override
Checks if the configuration contains a specific key.
Definition ConfigFileJson.cpp:139
std::vector< Value > getArray(std::string_view key) const override
Retrieves an array of configuration values by its key.
Definition ConfigFileJson.cpp:123