cpp-hocon 0.3.0
Loading...
Searching...
No Matches
simple_config_object.hpp
1#pragma once
2
3#include <internal/container.hpp>
4#include <hocon/config_object.hpp>
5#include <hocon/config_value.hpp>
6#include <hocon/config.hpp>
7#include <unordered_map>
8
9namespace hocon {
10
12 public:
13 simple_config_object(shared_origin origin, std::unordered_map<std::string, shared_value> value,
14 resolve_status status, bool ignores_fallbacks);
15
16 simple_config_object(shared_origin origin, std::unordered_map<std::string, shared_value> value);
17
18 shared_value attempt_peek_with_partial_resolve(std::string const& key) const override;
19
20 // map interface
21 bool is_empty() const override { return _value.empty(); }
22 size_t size() const override { return _value.size(); }
23 shared_value operator[](std::string const& key) const override { return _value.at(key); }
24 iterator begin() const override { return _value.begin(); }
25 iterator end() const override { return _value.end(); }
26 unwrapped_value unwrapped() const override;
27
28 shared_value get(std::string const& key) const override {
29 if (_value.find(key) == _value.end()) {
30 return nullptr;
31 }
32 return _value.at(key);
33 }
34
35 std::unordered_map<std::string, shared_value> const& entry_set() const override;
36
37 resolve_status get_resolve_status() const override { return _resolved; }
38 bool ignores_fallbacks() const override { return _ignores_fallbacks; }
39 shared_value with_fallbacks_ignored() const override;
40 shared_value merged_with_object(shared_object fallback) const override;
41
42 shared_object with_value(path raw_path, shared_value value) const override;
43 shared_object with_value(std::string key, shared_value value) const override;
44 shared_object without_path(path raw_path) const override;
45 shared_object with_only_path(path raw_path) const override;
46
54 shared_object with_only_path_or_null(path raw_path) const override;
55
61 shared_value replace_child(shared_value const& child, shared_value replacement) const override;
62
67 bool has_descendant(shared_value const& descendant) const override;
68
73 std::vector<std::string> key_set() const override;
74
79 std::vector<shared_value> value_set(std::unordered_map<std::string, shared_value> m) const;
80
81 bool operator==(config_value const& other) const override;
82
83 static std::shared_ptr<simple_config_object> empty();
84 static std::shared_ptr<simple_config_object> empty(shared_origin origin);
85 static std::shared_ptr<simple_config_object> empty_instance();
86
87 protected:
89 resolve_substitutions(resolve_context const& context, resolve_source const& source) const override;
90 shared_value new_copy(shared_origin) const override;
91 void render(std::string& s, int indent, bool at_root, config_render_options options) const override;
92
93 private:
94 std::unordered_map<std::string, shared_value> _value;
95 resolve_status _resolved;
96 bool _ignores_fallbacks;
97
98 shared_object new_copy(resolve_status const& new_status, shared_origin new_origin) const override;
99 std::shared_ptr<simple_config_object> modify(no_exceptions_modifier& modifier) const;
100 std::shared_ptr<simple_config_object> modify_may_throw(modifier& modifier) const;
101
102 static resolve_status resolve_status_from_value(const std::unordered_map<std::string, shared_value>& value);
103
104 struct resolve_modifier;
105 };
106
107} // namespace hocon
An immutable value, following the JSON type schema.
virtual shared_origin const & origin() const
The origin of the value (file, line number, etc.), for debugging and error messages.
virtual std::string render() const
Renders the config value as a HOCON string.
An AbstractConfigValue which contains other values.
Definition: container.hpp:12
shared_value attempt_peek_with_partial_resolve(std::string const &key) const override
Look up the key on an only-partially-resolved object, with no transformation or type conversion of an...
shared_value replace_child(shared_value const &child, shared_value replacement) const override
Replace a child of this value.
bool has_descendant(shared_value const &descendant) const override
Super-expensive full traversal to see if descendant is anywhere underneath this container.
std::vector< shared_value > value_set(std::unordered_map< std::string, shared_value > m) const
Construct a list of the values from the provided map.
shared_object with_only_path_or_null(path raw_path) const override
Gets the object with only the path if the path exists, otherwise null if it doesn't.
std::vector< std::string > key_set() const override
Construct a list of keys in the _value map.
Factory for creating config_document instances.
Definition: config.hpp:18