cpp-hocon icon indicating copy to clipboard operation
cpp-hocon copied to clipboard

How can I merge two configs?

Open VictorQueiroz opened this issue 4 years ago • 2 comments

I'm able to create parse one existing config using hocon::config::parse_string, but when I use with_fallback so I can merge it with other config, it returns config_mergeable which doesn't contain any public methods to be rendered to std::string. I also could not find any example of how to do that here. Maybe it's not supported by this library?

Appreciate all the help!

VictorQueiroz avatar May 27 '21 23:05 VictorQueiroz

I don't recall exactly how this works; you may need to attempt dynamic_cast to config_value, which has a render method.

MikaelSmith avatar Jun 01 '21 16:06 MikaelSmith

I think this is a case where being a port of a Java library gets messy. The interface - https://github.com/lightbend/config/blob/f92a4ee2f672c8254d87b27831d0903d3d0d6cc2/config/src/main/java/com/typesafe/config/ConfigMergeable.java - returns ConfigMergeable, but specific implementations can have more specific return values. In C++ I don't believe that's possible, so you need to attempt to cast to what you expect to get back. You should get back a config or config_value: https://puppetlabs.github.io/cpp-hocon/classhocon_1_1config__mergeable.html#a7b52c8c1cca8e617b34ea9eb439c8f59

MikaelSmith avatar Jun 01 '21 16:06 MikaelSmith