Replies: 1 comment 1 reply
-
Sorry for the late reply, missed this notification. There are several different ways to do that, and they are documented in the quickstart, so have a look over there. Specifically, in these sample functions: void sample_user_scalar_types(); ///< serialize/deserialize scalar (leaf/string) types
void sample_user_container_types(); ///< serialize/deserialize container (map or seq) types
void sample_std_types(); ///< serialize/deserialize STL containers A couple of notes about your code. root_ref[child.key()] >> remap[key];
// Don't do this, you are doing a double lookup.
// root_ref[child.key()] resolves to child, so just do the following instead:
child >> remap[key]; Now to get the key, use the child >> ryml::key(key); And reuse the key string to save you n allocations/deallocations: std::string key;
for (auto child: root_ref.children()) {
if (child.has_key() && child.has_val()) {
child >> ryml::key(key);
child >> remap[key];
}
} As for deserializing into the container, after reading the quickstart, you should look at the c4/yml/std/map.hpp header providing interop with |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm trying to extract a number of variables stored in a yaml file. As the number of values/names is unknown beforehand, I'm transversing through the yaml tree. (In this case, it happens to be a flat tree)
Is there a way to deserialize a child node to a c++ type? I've managed with a direct tree['key'] access, but not from ryml::Node type.
This is the best I've come up with, but it's a bit clunky..
As a bonus, is there a simpler way to convert a csubstr to a std::string?
Beta Was this translation helpful? Give feedback.
All reactions