userver: userver/dynamic_config/value.hpp Source File
Loading...
Searching...
No Matches
value.hpp
Go to the documentation of this file.
1#pragma once
2
5
6#include <optional>
7#include <string>
8#include <unordered_set>
9
14#include <userver/utils/impl/internal_tag.hpp>
15#include <userver/utils/impl/transparent_hash.hpp>
16
17USERVER_NAMESPACE_BEGIN
18
19namespace dynamic_config {
20
22class DocsMap final {
23public:
24 /* Returns config item or throws an exception if key is missing */
25 formats::json::Value Get(std::string_view name) const;
26
27 bool Has(std::string_view name) const;
28 void Set(std::string name, formats::json::Value);
29 void Parse(std::string_view json_string, bool empty_ok);
30 void Parse(formats::json::Value json, bool empty_ok);
31 void Remove(std::string_view name);
32 size_t Size() const;
33
34 void MergeOrAssign(DocsMap&& source);
35 void MergeMissing(const DocsMap& source);
36
37 std::unordered_set<std::string> GetNames() const;
38 formats::json::Value AsJson() const;
39 bool AreContentsEqual(const DocsMap& other) const;
40
42 // For internal use only.
43 // Set of configs expected to be used is automatically updated when
44 // configs are retrieved with 'Get' method.
45 void SetConfigsExpectedToBeUsed(utils::impl::TransparentSet<std::string> configs, utils::impl::InternalTag);
46
47 // For internal use only.
48 const utils::impl::TransparentSet<std::string>& GetConfigsExpectedToBeUsed(utils::impl::InternalTag) const;
50
51private:
52 utils::impl::TransparentMap<std::string, formats::json::Value> docs_;
53 mutable utils::impl::TransparentSet<std::string> configs_to_be_used_;
54};
55
56template <typename ValueType>
57using ValueDict = utils::DefaultDict<ValueType>;
58
59inline constexpr auto kValueDictDefaultName = utils::kDefaultDictDefaultName;
60
61} // namespace dynamic_config
62
63USERVER_NAMESPACE_END