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