cpp-hocon  0.3.0
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 
9 namespace hocon {
10 
11  class simple_config_object : public config_object, public container {
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
hocon::simple_config_object::attempt_peek_with_partial_resolve
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...
hocon::config_value::origin
virtual shared_origin const & origin() const
The origin of the value (file, line number, etc.), for debugging and error messages.
hocon::config_value::modifier
Definition: config_value.hpp:212
hocon
Factory for creating config_document instances.
Definition: config.hpp:18
hocon::simple_config_object::value_set
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.
hocon::resolve_context
Definition: resolve_context.hpp:16
hocon::simple_config_object
Definition: simple_config_object.hpp:11
hocon::simple_config_object::key_set
std::vector< std::string > key_set() const override
Construct a list of keys in the _value map.
hocon::simple_config_object::replace_child
shared_value replace_child(shared_value const &child, shared_value replacement) const override
Replace a child of this value.
hocon::config_value::render
virtual std::string render() const
Renders the config value as a HOCON string.
hocon::resolve_result< shared_value >
hocon::config_render_options
Definition: config_render_options.hpp:20
hocon::config_value::no_exceptions_modifier
Definition: config_value.hpp:217
hocon::value
Definition: tokens.hpp:8
hocon::path
Definition: path.hpp:13
hocon::simple_config_object::with_only_path_or_null
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.
hocon::config_value
An immutable value, following the JSON type schema.
Definition: config_value.hpp:39
hocon::container
An Abstractconfig_value which contains other values.
Definition: container.hpp:12
hocon::resolve_source
Definition: resolve_source.hpp:15
hocon::simple_config_object::has_descendant
bool has_descendant(shared_value const &descendant) const override
Super-expensive full traversal to see if descendant is anywhere underneath this container.
hocon::config_object
Definition: config_object.hpp:11