13#include <userver/dynamic_config/fwd.hpp>
14#include <userver/formats/json_fwd.hpp>
16USERVER_NAMESPACE_BEGIN
18namespace dynamic_config::impl {
20using Factory = std::function<std::any(
const DocsMap&)>;
22[[noreturn]]
void WrapGetError(
const std::exception& ex, std::type_index type);
24formats::
json::Value DocsMapGet(
const DocsMap&, std::string_view key);
26using ConfigId = std::size_t;
28ConfigId Register(std::string&& name, Factory factory,
29 std::string&& default_docs_map_string);
31struct InternalTag
final {
32 explicit InternalTag() =
default;
35std::any MakeConfig(ConfigId id,
const DocsMap&);
37std::string_view GetName(ConfigId id);
39DocsMap MakeDefaultDocsMap();
41struct ConfigIdGetter
final {
42 template <
typename Key>
43 static ConfigId Get(
const Key& key)
noexcept {
48class SnapshotData
final {
50 SnapshotData() =
default;
52 explicit SnapshotData(
const std::vector<KeyValue>& config_variables);
54 SnapshotData(
const DocsMap& defaults,
const std::vector<KeyValue>& overrides);
56 SnapshotData(
const SnapshotData& defaults,
57 const std::vector<KeyValue>& overrides);
59 SnapshotData(SnapshotData&&)
noexcept =
default;
60 SnapshotData& operator=(SnapshotData&&)
noexcept =
default;
63 const T& Get(ConfigId id)
const {
65 return std::any_cast<
const T&>(DoGet(id));
66 }
catch (
const std::exception& ex) {
67 impl::WrapGetError(ex,
typeid(T));
71 bool IsEmpty()
const noexcept;
74 const std::any& DoGet(ConfigId id)
const;
76 std::vector<std::any> user_configs_;