Clio  develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
ConfigFileJson.hpp
1#pragma once
2
3#include "util/config/ConfigFileInterface.hpp"
4#include "util/config/Error.hpp"
5#include "util/config/Types.hpp"
6
7#include <boost/json/object.hpp>
8
9#include <expected>
10#include <filesystem>
11#include <optional>
12#include <string>
13#include <string_view>
14#include <vector>
15
16namespace util::config {
17
19class ConfigFileJson final : public ConfigFileInterface {
20 boost::json::object jsonObject_;
21
22public:
29 ConfigFileJson(boost::json::object jsonObj);
30
37 [[nodiscard]] Value
38 getValue(std::string_view key) const override;
39
46 [[nodiscard]] std::vector<std::optional<Value>>
47 getArray(std::string_view key) const override;
48
55 [[nodiscard]] bool
56 containsKey(std::string_view key) const override;
57
63 [[nodiscard]] std::vector<std::string>
64 getAllKeys() const override;
65
73 [[nodiscard]] static std::expected<ConfigFileJson, Error>
74 makeConfigFileJson(std::filesystem::path const& configFilePath);
75
82 [[nodiscard]] boost::json::object const&
83 inner() const;
84
85private:
94 void
95 flattenJson(boost::json::object const& jsonRootObject);
96};
97
98} // namespace util::config
The interface for configuration files.
Definition ConfigFileInterface.hpp:18
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:69
std::vector< std::optional< Value > > getArray(std::string_view key) const override
Retrieves an array of configuration values by its key.
Definition ConfigFileJson.cpp:104
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:63
boost::json::object const & inner() const
Get the inner representation of json file.
Definition ConfigFileJson.cpp:140
Value getValue(std::string_view key) const override
Retrieves a configuration value by its key.
Definition ConfigFileJson.cpp:94
bool containsKey(std::string_view key) const override
Checks if the configuration contains a specific key.
Definition ConfigFileJson.cpp:124
std::vector< std::string > getAllKeys() const override
Retrieves all keys in the configuration file.
Definition ConfigFileJson.cpp:130