userver
C++ Async Framework
Toggle main menu visibility
Loading...
Searching...
No Matches
storage_mock.hpp
Go to the documentation of this file.
1
#pragma once
2
5
6
#include <initializer_list>
7
#include <memory>
8
#include <vector>
9
10
#include <
userver/dynamic_config/snapshot.hpp
>
11
#include <
userver/dynamic_config/source.hpp
>
12
#include <
userver/dynamic_config/value.hpp
>
13
#include <
userver/formats/json/serialize.hpp
>
14
#include <
userver/formats/json/value.hpp
>
15
16
USERVER_NAMESPACE_BEGIN
17
18
namespace
dynamic_config {
19
namespace
impl {
20
21
template
<
typename
T>
22
concept
IsJson = std::is_same_v<T, formats::json::Value>;
23
24
}
// namespace impl
25
27
class
KeyValue
final {
28
public
:
34
template
<
typename
VariableType,
typename
Value = VariableType>
35
KeyValue
(
const
Key<VariableType>
& key, Value&& value)
36
: id_(impl::ConfigIdGetter::Get(key)),
37
value_(Convert<VariableType>(
std
::forward<Value>(value)))
38
{}
39
41
impl::ConfigId
GetId
()
const
{
return
id_; }
42
44
std::any
GetValue
()
const
{
return
value_; }
45
46
private
:
47
template
<
typename
VariableType,
typename
Value>
48
static
VariableType Convert(Value&& value) {
49
if
constexpr
(std::is_same_v<std::decay_t<Value>,
formats::json::Value
>) {
50
return
value.template As<VariableType>();
51
}
else
{
52
return
static_cast<
VariableType
>
(std::forward<Value>(value));
53
}
54
}
55
56
impl::ConfigId id_;
57
std::any value_;
58
};
59
66
class
StorageMock
final {
67
public
:
69
StorageMock
();
70
73
StorageMock
(std::initializer_list<KeyValue> config_variables);
74
76
explicit
StorageMock
(
const
std::vector<KeyValue>& config_variables);
77
81
StorageMock
(
const
DocsMap
& defaults,
const
std::vector<KeyValue>& overrides);
82
83
StorageMock
(
StorageMock
&&) noexcept;
84
StorageMock
& operator=(
StorageMock
&&) noexcept;
85
~
StorageMock
();
86
88
void
Extend
(const
std
::vector<
KeyValue
>& overrides);
89
90
Source
GetSource() const&;
91
Snapshot
GetSnapshot() const&;
92
93
// Store the StorageMock in a variable before using
94
Snapshot
GetSource() && = delete;
95
Snapshot
GetSnapshot() && = delete;
96
97
private:
98
std
::unique_ptr<impl::StorageData> storage_;
99
};
100
101
}
// namespace dynamic_config
102
103
USERVER_NAMESPACE_END
userver
dynamic_config
storage_mock.hpp
Generated on
for userver by
Doxygen
1.17.0