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/internal_tag.hpp>
12#include <userver/utils/impl/transparent_hash.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,
43 utils::impl::InternalTag);
44
45 // For internal use only.
46 const utils::impl::TransparentSet<std::string>& GetConfigsExpectedToBeUsed(
47 utils::impl::InternalTag) const;
48 /// @endcond
49
50 private:
51 utils::impl::TransparentMap<std::string, formats::json::Value> docs_;
52 mutable utils::impl::TransparentSet<std::string> configs_to_be_used_;
53};
54
55template <typename ValueType>
56using ValueDict = utils::DefaultDict<ValueType>;
57
58inline constexpr auto kValueDictDefaultName = utils::kDefaultDictDefaultName;
59
60} // namespace dynamic_config
61
62USERVER_NAMESPACE_END