4 #include "config_origin.hpp" 5 #include "config_render_options.hpp" 6 #include "config_mergeable.hpp" 11 #include <leatherman/locale/locale.hpp> 17 class resolve_context;
22 enum class resolve_status { RESOLVED, UNRESOLVED };
57 OBJECT, LIST, NUMBER, BOOLEAN, CONFIG_NULL, STRING, UNSPECIFIED
59 static char const* type_name(type t) {
61 case type::OBJECT:
return "object";
62 case type::LIST:
return "list";
63 case type::NUMBER:
return "number";
64 case type::BOOLEAN:
return "boolean";
65 case type::CONFIG_NULL:
return "null";
66 case type::STRING:
return "string";
67 case type::UNSPECIFIED:
return "unspecified";
68 default:
throw std::logic_error(leatherman::locale::format(
"Got impossible value for type enum"));
78 virtual shared_origin
const& origin()
const;
85 virtual type value_type()
const = 0;
93 return type_name(value_type());
96 virtual unwrapped_value unwrapped()
const = 0;
115 virtual std::string render()
const;
146 shared_config at_key(std::string
const& key)
const;
157 shared_config at_path(std::string
const& path_expression)
const;
167 virtual shared_value with_origin(shared_origin origin)
const;
181 virtual shared_value
relativized(std::string prefix)
const {
return shared_from_this(); }
183 virtual resolve_status get_resolve_status()
const;
185 friend resolve_status resolve_status_from_values(std::vector<shared_value>
const& v);
187 std::shared_ptr<const config_mergeable> with_fallback(std::shared_ptr<const config_mergeable> other)
const override;
191 virtual std::string transform_to_string()
const;
196 virtual void render(std::string& result,
int indent,
bool at_root, std::string
const& at_key,
config_render_options options)
const;
197 virtual void render(std::string& result,
int indent,
bool at_root,
config_render_options options)
const;
200 shared_config at_key(shared_origin origin, std::string
const& key)
const;
201 shared_config at_path(shared_origin origin,
path raw_path)
const;
203 virtual shared_value new_copy(shared_origin origin)
const = 0;
208 static std::vector<shared_value> replace_child_in_list(std::vector<shared_value>
const& values,
209 shared_value
const& child, shared_value replacement);
210 static bool has_descendant_in_list(std::vector<shared_value>
const& values, shared_value
const& descendant);
214 virtual shared_value modify_child_may_throw(std::string
const& key_or_null, shared_value v) = 0;
221 shared_value modify_child_may_throw(std::string
const &key_or_null, shared_value v)
override;
222 shared_value modify_child(std::string
const& key, shared_value v)
const;
226 void require_not_ignoring_fallbacks()
const;
232 virtual bool ignores_fallbacks()
const;
233 virtual shared_value with_fallbacks_ignored()
const;
235 shared_value merged_with_the_unmergeable(std::vector<shared_value> stack,
236 std::shared_ptr<const unmergeable> fallback)
const;
237 shared_value merged_with_the_unmergeable(std::shared_ptr<const unmergeable> fallback)
const;
239 shared_value merged_with_object(std::vector<shared_value> stack, shared_object fallback)
const;
240 virtual shared_value merged_with_object(shared_object fallback)
const;
242 shared_value merged_with_non_object(std::vector<shared_value> stack, shared_value fallback)
const;
243 shared_value merged_with_non_object(shared_value fallback)
const;
245 virtual shared_value construct_delayed_merge(shared_origin origin, std::vector<shared_value> stack)
const;
247 shared_value to_fallback_value()
const override;
250 static bool equals(
config_value const& other, std::function<
bool(T
const&)> checker)
253 auto other_t =
dynamic_cast<T const*
>(&other);
259 return checker(*other_t);
263 shared_value delay_merge(std::vector<shared_value> stack, shared_value fallback)
const;
265 shared_origin _origin;
An immutable map from config paths to config values.
A ConfigConcatenation represents a list of values to be concatenated (see the spec).
type
The type of a configuration value (following the JSON type schema).
Factory for creating config_document instances.
virtual shared_value relativized(std::string prefix) const
This is used when including one file in another; the included file is relativized to the path it's in...
char const * value_type_name() const
The printable name of the value type.
bool operator==(config_document const &lhs, config_document const &rhs)
Config documents compare via rendered strings.
An immutable value, following the JSON type schema.