11#include <userver/dynamic_config/fwd.hpp>
13USERVER_NAMESPACE_BEGIN
15namespace dynamic_config::impl {
17using Factory = std::any (*)(
const DocsMap&);
19template <
typename Key>
20using VariableOfKey =
decltype(Key::Parse(std::declval<
const DocsMap&>()));
22template <
typename Key>
23std::any FactoryFor(
const DocsMap& map) {
24 return std::any{Key::Parse(map)};
27[[noreturn]]
void WrapGetError(
const std::exception& ex, std::type_index type);
30T ParseByConstructor(
const DocsMap& docs_map) {
34using ConfigId = std::size_t;
36ConfigId Register(Factory factory);
40template <
typename Key>
41inline const ConfigId kConfigId = Register(&FactoryFor<Key>);
43class SnapshotData
final {
45 SnapshotData() =
default;
47 SnapshotData(
const std::vector<KeyValue>& config_variables);
49 SnapshotData(
const DocsMap& defaults,
const std::vector<KeyValue>& overrides);
51 SnapshotData(
const SnapshotData& defaults,
52 const std::vector<KeyValue>& overrides);
54 SnapshotData(SnapshotData&&)
noexcept =
default;
55 SnapshotData& operator=(SnapshotData&&)
noexcept =
default;
57 template <
typename Key>
58 const auto& operator[](Key)
const {
59 using VariableType = VariableOfKey<Key>;
61 return std::any_cast<
const VariableType&>(Get(impl::kConfigId<Key>));
62 }
catch (
const std::exception& ex) {
63 impl::WrapGetError(ex,
typeid(VariableType));
67 bool IsEmpty()
const noexcept;
70 const std::any& Get(impl::ConfigId id)
const;
72 std::vector<std::any> user_configs_;