Clio  develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
Array.hpp
1#pragma once
2
3#include "util/config/ConfigValue.hpp"
4#include "util/config/Error.hpp"
5#include "util/config/Types.hpp"
6
7#include <cstddef>
8#include <optional>
9#include <ostream>
10#include <string_view>
11#include <vector>
12
13namespace util::config {
14
22class Array {
23public:
29 Array(ConfigValue arg);
30
40 static std::string_view
41 prefix(std::string_view key);
42
50 [[nodiscard]] std::optional<Error>
51 addValue(Value value, std::optional<std::string_view> key = std::nullopt);
52
61 [[nodiscard]] std::optional<Error>
62 addNull(std::optional<std::string_view> key = std::nullopt);
63
69 [[nodiscard]] size_t
70 size() const;
71
78 [[nodiscard]] ConfigValue const&
79 at(std::size_t idx) const;
80
87 [[nodiscard]] ConfigValue const&
88 getArrayPattern() const;
89
95 [[nodiscard]] std::vector<ConfigValue>::const_iterator
96 begin() const;
97
103 [[nodiscard]] std::vector<ConfigValue>::const_iterator
104 end() const;
105
106private:
107 ConfigValue itemPattern_;
108 std::vector<ConfigValue> elements_;
109};
110
118inline std::ostream&
119operator<<(std::ostream& stream, Array arr)
120{
121 stream << arr.getArrayPattern();
122 return stream;
123}
124
125} // namespace util::config
Array definition to store multiple values provided by the user from Json/Yaml.
Definition Array.hpp:22
ConfigValue const & at(std::size_t idx) const
Returns the ConfigValue at the specified index.
Definition Array.cpp:61
ConfigValue const & getArrayPattern() const
Returns the ConfigValue that defines the type/constraint every ConfigValue must follow in Array.
Definition Array.cpp:68
std::optional< Error > addNull(std::optional< std::string_view > key=std::nullopt)
Add null value to the array.
Definition Array.cpp:41
std::optional< Error > addValue(Value value, std::optional< std::string_view > key=std::nullopt)
Add ConfigValues to Array class.
Definition Array.cpp:30
std::vector< ConfigValue >::const_iterator end() const
Returns an iterator to the end of the ConfigValue vector.
Definition Array.cpp:80
size_t size() const
Returns the number of values stored in the Array.
Definition Array.cpp:55
Array(ConfigValue arg)
Constructs an Array with provided Arg.
Definition Array.cpp:16
std::vector< ConfigValue >::const_iterator begin() const
Returns an iterator to the beginning of the ConfigValue vector.
Definition Array.cpp:74
static std::string_view prefix(std::string_view key)
Extract array prefix from a key, For example for a key foo.[].bar the method will return foo....
Definition Array.cpp:21
Represents the config values for Json/Yaml config.
Definition ConfigValue.hpp:28