-
I'm trying to use rapidYaml to parse a settings file required by my application.
In set_factory_default I build my full settings tree with default values.
When I return from get_from_settings_file() tree is updated with 'overrides' from my filedata. Unfortunately the first key-val pair read from filedata is corrupted. I think it is due to the substr and/or filetree object being destroyed when returning (i.e. stack is reused for other stuff) Make filetree global too and use Isn't there a way to ensure data follows the tree I'm merging into? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
(Sorry for the late reply, Github's notifications are just broken for me). Indeed, any data added to ryml::Tree tree;
set_factory_default();
{
size_t filesize = ...;
ryml::substr filedata = tree.alloc_arena(filesize); // place the filedata in the destination tree
file_get_contents(file, filedata);
ryml::Tree filetree = ryml::parse_in_place(filedata); // read the temp tree in place
tree.merge_with(&filetree);
}
// at this point, filetree's contents are safely in the final tree. For a similar example, see this note. HTH. |
Beta Was this translation helpful? Give feedback.
-
Also, you may want to take a look at c4conf, which does exactly what you are looking for. |
Beta Was this translation helpful? Give feedback.
(Sorry for the late reply, Github's notifications are just broken for me).
Indeed, any data added to
tree
needs to go on existing for as long astree
does. In this case you are adding fromfiledata
, so you need to make sure that it exists withtree
. There are several ways, but one simple way is to dofiledata = tree.alloc_arena(filesize)
on the destination tree, then still do the parse in place into the temporaryfiletree
.