cpp-hocon  0.3.0
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Friends | List of all members
hocon::config_object Class Referenceabstract
Inheritance diagram for hocon::config_object:
hocon::config_value hocon::config_mergeable hocon::config_delayed_merge_object hocon::simple_config_object

Public Types

using iterator = std::unordered_map< std::string, shared_value >::const_iterator
 
enum  type {
  OBJECT, LIST, NUMBER, BOOLEAN,
  CONFIG_NULL, STRING, UNSPECIFIED
}
 The type of a configuration value (following the JSON type schema). More...
 

Public Member Functions

virtual std::shared_ptr< const configto_config () const
 Converts this object to a config instance, enabling you to use path expressions to find values in the object. More...
 
 config_object (shared_origin origin)
 
config_value::type value_type () const override
 The type of the value; matches the JSON type schema. More...
 
virtual shared_object with_value (path raw_path, shared_value value) const =0
 
virtual shared_object with_value (std::string key, shared_value value) const =0
 
virtual shared_value attempt_peek_with_partial_resolve (std::string const &key) const =0
 Look up the key on an only-partially-resolved object, with no transformation or type conversion of any kind; if 'this' is not resolved then try to look up the key anyway if possible. More...
 
virtual std::vector< std::string > key_set () const =0
 Construct a list of keys in the _value map. More...
 
virtual bool is_empty () const =0
 
virtual size_t size () const =0
 
virtual shared_value operator[] (std::string const &key) const =0
 
virtual shared_value get (std::string const &key) const =0
 
virtual iterator begin () const =0
 
virtual iterator end () const =0
 
virtual shared_origin const & origin () const
 The origin of the value (file, line number, etc.), for debugging and error messages. More...
 
char const * value_type_name () const
 The printable name of the value type. More...
 
virtual unwrapped_value unwrapped () const =0
 
virtual std::string render () const
 Renders the config value as a HOCON string. More...
 
virtual std::string render (config_render_options options) const
 Renders the config value to a string, using the provided options. More...
 
shared_config at_key (std::string const &key) const
 Places the value inside a config at the given key. More...
 
shared_config at_path (std::string const &path_expression) const
 Places the value inside a config at the given path. More...
 
virtual shared_value with_origin (shared_origin origin) const
 Returns a. More...
 
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 included into in the parent file. More...
 
virtual resolve_status get_resolve_status () const
 
std::shared_ptr< const config_mergeablewith_fallback (std::shared_ptr< const config_mergeable > other) const override
 Returns a new value computed by merging this value with another, with keys in this value "winning" over the other one. More...
 
virtual bool operator== (config_value const &other) const =0
 
virtual std::string transform_to_string () const
 

Static Public Member Functions

static char const * type_name (type t)
 

Protected Member Functions

shared_value peek_path (path desired_path) const
 
shared_value peek_assuming_resolved (std::string const &key, path original_path) const
 
virtual shared_object new_copy (resolve_status const &status, shared_origin origin) const =0
 
shared_value new_copy (shared_origin origin) const override
 
shared_value construct_delayed_merge (shared_origin origin, std::vector< shared_value > stack) const override
 
virtual std::unordered_map< std::string, shared_value > const & entry_set () const =0
 
virtual shared_object without_path (path raw_path) const =0
 
virtual shared_object with_only_path (path raw_path) const =0
 
virtual shared_object with_only_path_or_null (path raw_path) const =0
 
virtual void render (std::string &result, int indent, bool at_root, std::string const &at_key, config_render_options options) const
 
virtual void render (std::string &result, int indent, bool at_root, config_render_options options) const
 
shared_config at_key (shared_origin origin, std::string const &key) const
 
shared_config at_path (shared_origin origin, path raw_path) const
 
virtual resolve_result< shared_value > resolve_substitutions (resolve_context const &context, resolve_source const &source) const
 
void require_not_ignoring_fallbacks () const
 
virtual bool ignores_fallbacks () const
 
virtual shared_value with_fallbacks_ignored () const
 
shared_value merged_with_the_unmergeable (std::vector< shared_value > stack, std::shared_ptr< const unmergeable > fallback) const
 
shared_value merged_with_the_unmergeable (std::shared_ptr< const unmergeable > fallback) const
 
shared_value merged_with_object (std::vector< shared_value > stack, shared_object fallback) const
 
virtual shared_value merged_with_object (shared_object fallback) const
 
shared_value merged_with_non_object (std::vector< shared_value > stack, shared_value fallback) const
 
shared_value merged_with_non_object (shared_value fallback) const
 
shared_value to_fallback_value () const override
 Converts a config to its root object and a config_value to itself. More...
 

Static Protected Member Functions

static shared_value peek_path (const config_object *self, path desired_path)
 
static shared_origin merge_origins (std::vector< shared_value > const &stack)
 
static void indent (std::string &result, int indent, config_render_options const &options)
 
static std::vector< shared_value > replace_child_in_list (std::vector< shared_value > const &values, shared_value const &child, shared_value replacement)
 
static bool has_descendant_in_list (std::vector< shared_value > const &values, shared_value const &descendant)
 
template<typename T >
static bool equals (config_value const &other, std::function< bool(T const &)> checker)
 

Friends

class config
 
class config_value
 
class simple_config_object
 
class resolve_source
 
class config_delayed_merge_object
 

Detailed Description

Definition at line 11 of file config_object.hpp.

Member Enumeration Documentation

◆ type

enum hocon::config_value::type
stronginherited

The type of a configuration value (following the JSON type schema).

Definition at line 56 of file config_value.hpp.

Member Function Documentation

◆ at_key()

shared_config hocon::config_value::at_key ( std::string const &  key) const
inherited

Places the value inside a config at the given key.

See also config_value#at_path(string).

Parameters
keykey to store this value at.
Returns
a
config
instance containing this value at the given key.

◆ at_path()

shared_config hocon::config_value::at_path ( std::string const &  path_expression) const
inherited

Places the value inside a config at the given path.

See also config_value#at_key(String).

Parameters
pathpath to store this value at.
Returns
a
config
instance containing this value at the given path.

◆ attempt_peek_with_partial_resolve()

virtual shared_value hocon::config_object::attempt_peek_with_partial_resolve ( std::string const &  key) const
pure virtual

Look up the key on an only-partially-resolved object, with no transformation or type conversion of any kind; if 'this' is not resolved then try to look up the key anyway if possible.

Parameters
keykey to look up
Returns
the value of the key, or null if known not to exist
Exceptions
config_exceptionif can't figure out key's value (or existence) without more resolving

Implemented in hocon::config_delayed_merge_object, and hocon::simple_config_object.

◆ key_set()

virtual std::vector<std::string> hocon::config_object::key_set ( ) const
pure virtual

Construct a list of keys in the _value map.

Use a vector rather than set, because most of the time we just want to iterate over them.

Implemented in hocon::simple_config_object, and hocon::config_delayed_merge_object.

◆ origin()

virtual shared_origin const& hocon::config_value::origin ( ) const
virtualinherited

The origin of the value (file, line number, etc.), for debugging and error messages.

Returns
where the value came from

◆ relativized()

virtual shared_value hocon::config_value::relativized ( std::string  prefix) const
inlinevirtualinherited

This is used when including one file in another; the included file is relativized to the path it's included into in the parent file.

The point is that if you include a file at foo.bar in the parent, and the included file as a substitution ${a.b.c}, the included substitution now needs to be ${foo.bar.a.b.c} because we resolve substitutions globally only after parsing everything.

Parameters
prefix
Returns
value relativized to the given path or the same value if nothing to do

Reimplemented in hocon::config_concatenation, and hocon::simple_config_list.

Definition at line 181 of file config_value.hpp.

◆ render() [1/2]

virtual std::string hocon::config_value::render ( ) const
virtualinherited

Renders the config value as a HOCON string.

This method is primarily intended for debugging, so it tries to add helpful comments and whitespace.

If the config value has not been resolved (see config#resolve), it's possible that it can't be rendered as valid HOCON. In that case the rendering should still be useful for debugging but you might not be able to parse it. If the value has been resolved, it will always be parseable.

This method is equivalent to

render(config_render_options())

.

Returns
the rendered value

◆ render() [2/2]

virtual std::string hocon::config_value::render ( config_render_options  options) const
virtualinherited

Renders the config value to a string, using the provided options.

If the config value has not been resolved (see config#resolve), it's possible that it can't be rendered as valid HOCON. In that case the rendering should still be useful for debugging but you might not be able to parse it. If the value has been resolved, it will always be parseable.

If the config value has been resolved and the options disable all HOCON-specific features (such as comments), the rendering will be valid JSON. If you enable HOCON-only features such as comments, the rendering will not be valid JSON.

Parameters
optionsthe rendering options
Returns
the rendered value

◆ to_config()

virtual std::shared_ptr<const config> hocon::config_object::to_config ( ) const
virtual

Converts this object to a config instance, enabling you to use path expressions to find values in the object.

This is a constant-time operation (it is not proportional to the size of the object).

Returns
a config with this object as its root

◆ to_fallback_value()

shared_value hocon::config_value::to_fallback_value ( ) const
overrideprotectedvirtualinherited

Converts a config to its root object and a config_value to itself.

Originally in the MergeableValue interface, squashing to ease C++ public API separation

Implements hocon::config_mergeable.

◆ value_type()

config_value::type hocon::config_object::value_type ( ) const
overridevirtual

The type of the value; matches the JSON type schema.

Returns
value's type

Implements hocon::config_value.

◆ value_type_name()

char const* hocon::config_value::value_type_name ( ) const
inlineinherited

The printable name of the value type.

Returns
value's type's name

Definition at line 92 of file config_value.hpp.

◆ with_fallback()

std::shared_ptr<const config_mergeable> hocon::config_value::with_fallback ( std::shared_ptr< const config_mergeable other) const
overridevirtualinherited

Returns a new value computed by merging this value with another, with keys in this value "winning" over the other one.

This associative operation may be used to combine configurations from multiple sources (such as multiple configuration files).

The semantics of merging are described in the spec for HOCON. Merging typically occurs when either the same object is created twice in the same file, or two config files are both loaded. For example:

 foo = { a: 42 }
 foo = { b: 43 }

Here, the two objects are merged as if you had written:

 foo = { a: 42, b: 43 }

Only config_object and config instances do anything in this method (they need to merge the fallback keys into themselves). All other values just return the original value, since they automatically override any fallback. This means that objects do not merge "across" non-objects; if you write object.withFallback(nonObject).withFallback(otherObject), then otherObject will simply be ignored. This is an intentional part of how merging works, because non-objects such as strings and integers replace (rather than merging with) any prior value:

foo = { a: 42 }
foo = 10

Here, the number 10 "wins" and the value of foo would be simply 10. Again, for details see the spec.

Parameters
otheran object whose keys should be used as fallbacks, if the keys are not present in this one
Returns
a new object (or the original one, if the fallback doesn't get used)

Implements hocon::config_mergeable.

◆ with_origin()

virtual shared_value hocon::config_value::with_origin ( shared_origin  origin) const
virtualinherited

Returns a.

config_value

based on this one, but with the given origin. This is useful when you are parsing a new format of file or setting comments for a single config_value.

Parameters
originthe origin set on the returned value
Returns
the new config_value with the given origin

The documentation for this class was generated from the following file:
hocon::config_value::render
virtual std::string render() const
Renders the config value as a HOCON string.