Clio develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
Array.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/ConfigValue.hpp"
23#include "util/newconfig/Error.hpp"
24#include "util/newconfig/Types.hpp"
25
26#include <cstddef>
27#include <optional>
28#include <ostream>
29#include <string_view>
30#include <vector>
31
32namespace util::config {
33
41class Array {
42public:
48 Array(ConfigValue arg);
49
58 static std::string_view
59 prefix(std::string_view key);
60
68 std::optional<Error>
69 addValue(Value value, std::optional<std::string_view> key = std::nullopt);
70
76 [[nodiscard]] size_t
77 size() const;
78
85 [[nodiscard]] ConfigValue const&
86 at(std::size_t idx) const;
87
94 [[nodiscard]] ConfigValue const&
95 getArrayPattern() const;
96
102 [[nodiscard]] std::vector<ConfigValue>::const_iterator
103 begin() const;
104
110 [[nodiscard]] std::vector<ConfigValue>::const_iterator
111 end() const;
112
113private:
114 ConfigValue itemPattern_;
115 std::vector<ConfigValue> elements_;
116};
117
125inline std::ostream&
126operator<<(std::ostream& stream, Array arr)
127{
128 stream << arr.getArrayPattern();
129 return stream;
130}
131
132} // namespace util::config
Array definition to store multiple values provided by the user from Json/Yaml.
Definition Array.hpp:41
ConfigValue const & at(std::size_t idx) const
Returns the ConfigValue at the specified index.
Definition Array.cpp:68
ConfigValue const & getArrayPattern() const
Returns the ConfigValue that defines the type/constraint every ConfigValue must follow in Array.
Definition Array.cpp:75
std::optional< Error > addValue(Value value, std::optional< std::string_view > key=std::nullopt)
Add ConfigValues to Array class.
Definition Array.cpp:49
std::vector< ConfigValue >::const_iterator end() const
Returns an iterator to the end of the ConfigValue vector.
Definition Array.cpp:87
size_t size() const
Returns the number of values stored in the Array.
Definition Array.cpp:62
Array(ConfigValue arg)
Constructs an Array with provided Arg.
Definition Array.cpp:35
std::vector< ConfigValue >::const_iterator begin() const
Returns an iterator to the beginning of the ConfigValue vector.
Definition Array.cpp:81
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:40
Represents the config values for Json/Yaml config.
Definition ConfigValue.hpp:48
std::ostream & operator<<(std::ostream &stream, Severity sev)
Custom labels for Severity in log output.
Definition Logger.cpp:73