cpp-hocon  0.3.0
simple_config_list.hpp
1 #pragma once
2 
3 #include <hocon/config_value.hpp>
4 #include <hocon/config_list.hpp>
5 #include <hocon/config_render_options.hpp>
6 #include <hocon/config_exception.hpp>
7 #include <internal/container.hpp>
8 #include <algorithm>
9 #include <memory>
10 #include <vector>
11 #include <boost/optional.hpp>
12 
13 namespace hocon {
14 
15  class simple_config_list : public config_list, public container {
16  public:
17  simple_config_list(shared_origin origin, std::vector<shared_value> value);
18  simple_config_list(shared_origin origin, std::vector<shared_value> value, resolve_status status);
19 
20  config_value::type value_type() const override { return config_value::type::LIST; }
21  resolve_status get_resolve_status() const override { return _resolved; }
22 
23  shared_value replace_child(shared_value const& child, shared_value replacement) const override;
24  bool has_descendant(shared_value const& descendant) const override;
25 
26  shared_value relativized(const std::string prefix) const override;
27 
28  bool contains(shared_value v) const { return std::find(_value.begin(), _value.end(), v) != _value.end(); }
29  bool contains_all(std::vector<shared_value>) const;
30 
31  int index_of(shared_value v) {
32  auto pos = find(_value.begin(), _value.end(), v);
33  if (pos == _value.end()) {
34  return -1;
35  } else {
36  return pos - _value.begin();
37  }
38  }
39 
40  // list interface
41  bool is_empty() const override { return _value.empty(); }
42  size_t size() const override { return _value.size(); }
43  shared_value operator[](size_t index) const override { return _value.at(index); }
44  shared_value get(size_t index) const override { return _value.at(index); }
45  iterator begin() const override { return _value.begin(); }
46  iterator end() const override { return _value.end(); }
47 
48  std::shared_ptr<const simple_config_list> concatenate(std::shared_ptr<const simple_config_list> other) const;
49 
50  unwrapped_value unwrapped() const override;
51 
52  bool operator==(config_value const& other) const override;
53 
54  protected:
55  resolve_result<shared_value>
56  resolve_substitutions(resolve_context const& context, resolve_source const& source) const override;
57  shared_value new_copy(shared_origin origin) const override;
58 
59  void render(std::string& result, int indent, bool at_root, config_render_options options) const override;
60 
61  private:
62  static const long _serial_version_UID = 2L;
63  const std::vector<shared_value> _value;
64  const resolve_status _resolved;
65 
66  std::shared_ptr<const simple_config_list>
67  modify(no_exceptions_modifier& modifier, boost::optional<resolve_status> new_resolve_status) const;
68 
69  std::shared_ptr<const simple_config_list>
70  modify_may_throw(modifier& modifier, boost::optional<resolve_status> new_resolve_status) const;
71 
72  struct resolve_modifier;
73  };
74 
75 } // namespace hocon
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::type
type
The type of a configuration value (following the JSON type schema).
Definition: config_value.hpp:56
hocon::simple_config_list::replace_child
shared_value replace_child(shared_value const &child, shared_value replacement) const override
Replace a child of this value.
hocon::simple_config_list::value_type
config_value::type value_type() const override
The type of the value; matches the JSON type schema.
Definition: simple_config_list.hpp:20
hocon::simple_config_list::relativized
shared_value relativized(const std::string prefix) const override
This is used when including one file in another; the included file is relativized to the path it's in...
hocon
Factory for creating config_document instances.
Definition: config.hpp:18
hocon::simple_config_list
Definition: simple_config_list.hpp:15
hocon::config_value::render
virtual std::string render() const
Renders the config value as a HOCON string.
hocon::value
Definition: tokens.hpp:8
hocon::container
An Abstractconfig_value which contains other values.
Definition: container.hpp:12
hocon::simple_config_list::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_list
Subtype of config_value representing a list value, as in JSON's.
Definition: config_list.hpp:37