Clio  develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
ObjectView.hpp
1#pragma once
2
3#include "util/config/ValueView.hpp"
4
5#include <cstddef>
6#include <functional>
7#include <optional>
8#include <string>
9#include <string_view>
10
11namespace util::config {
12
14class ArrayView;
15
22public:
29 ObjectView(std::string_view prefix, ClioConfigDefinition const& clioConfig);
30
39 std::string_view prefix,
40 std::size_t arrayIndex,
41 ClioConfigDefinition const& clioConfig
42 );
43
50 [[nodiscard]] bool
51 containsKey(std::string_view key) const;
52
59 [[nodiscard]] ValueView
60 getValueView(std::string_view key) const;
61
69 template <typename T>
70 T
71 get(std::string_view key) const
72 {
73 return getValueView(key).getValueImpl<T>();
74 }
75
83 template <typename T>
84 std::optional<T>
85 maybeValue(std::string_view key) const
86 {
87 return getValueView(key).asOptional<T>();
88 }
89
97 [[nodiscard]] ObjectView
98 getObject(std::string_view key) const;
99
107 [[nodiscard]] ArrayView
108 getArray(std::string_view key) const;
109
110private:
117 [[nodiscard]] std::string
118 getFullKey(std::string_view key) const;
119
126 [[nodiscard]] bool
127 startsWithKey(std::string_view key) const;
128
129 std::string prefix_;
130 std::optional<size_t> arrayIndex_;
131 std::reference_wrapper<ClioConfigDefinition const> clioConfig_;
132};
133
134} // namespace util::config
View for array structure for config.
Definition ArrayView.hpp:23
All the config data will be stored and extracted from this class.
Definition ConfigDefinition.hpp:31
Provides a view into a subset of configuration data defined by a prefix.
Definition ObjectView.hpp:21
ObjectView getObject(std::string_view key) const
Retrieves an ObjectView in ClioConfigDefinition with key that starts with prefix_....
Definition ObjectView.cpp:49
ValueView getValueView(std::string_view key) const
Retrieves the value associated with the specified prefix._key in ClioConfigDefinition.
Definition ObjectView.cpp:39
ArrayView getArray(std::string_view key) const
Retrieves an ArrayView in ClioConfigDefinition with key that starts with prefix_.key....
Definition ObjectView.cpp:63
bool containsKey(std::string_view key) const
Checks if prefix_.key (fullkey) exists in ClioConfigDefinition.
Definition ObjectView.cpp:33
std::optional< T > maybeValue(std::string_view key) const
Returns the specified value of given string of type T if type and value exists.
Definition ObjectView.hpp:85
T get(std::string_view key) const
Returns the specified value of given string if value exists.
Definition ObjectView.hpp:71
ObjectView(std::string_view prefix, ClioConfigDefinition const &clioConfig)
Constructs an ObjectView for the specified prefix. The view must be of type object.
Definition ObjectView.cpp:18
Provides view into ConfigValues that represents values in Clio Config.
Definition ValueView.hpp:27
T getValueImpl() const
Retrieves the stored value as the specified type T.
Definition ValueView.hpp:146
std::optional< T > asOptional() const
Returns an optional value of the specified type T if valid.
Definition ValueView.hpp:177