cpp-hocon  0.3.0
Public Member Functions | Protected Member Functions | Friends | List of all members
hocon::config_mergeable Class Referenceabstract
Inheritance diagram for hocon::config_mergeable:
hocon::config hocon::config_value hocon::config_boolean hocon::config_concatenation hocon::config_delayed_merge hocon::config_list hocon::config_null hocon::config_number hocon::config_object hocon::config_reference hocon::config_string

Public Member Functions

virtual std::shared_ptr< const config_mergeablewith_fallback (std::shared_ptr< const config_mergeable > other) const =0
 Returns a new value computed by merging this value with another, with keys in this value "winning" over the other one. More...
 

Protected Member Functions

virtual shared_value to_fallback_value () const =0
 Converts a config to its root object and a config_value to itself. More...
 

Friends

class config_value
 

Detailed Description

Definition at line 8 of file config_mergeable.hpp.

Member Function Documentation

◆ to_fallback_value()

virtual shared_value hocon::config_mergeable::to_fallback_value ( ) const
protectedpure virtual

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

Implemented in hocon::config, and hocon::config_value.

◆ with_fallback()

virtual std::shared_ptr<const config_mergeable> hocon::config_mergeable::with_fallback ( std::shared_ptr< const config_mergeable other) const
pure virtual

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)

Implemented in hocon::config, and hocon::config_value.


The documentation for this class was generated from the following file: