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