Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Feb 08 03:21
    captain-yoshi commented #312
  • Feb 02 19:40
    MartijnKuipers commented #352
  • Feb 01 17:34
    biojppm commented #352
  • Jan 27 15:26
    MartijnKuipers commented #352
  • Jan 27 15:19
    MartijnKuipers reopened #352
  • Jan 27 15:19
    MartijnKuipers commented #352
  • Jan 27 15:07
    MartijnKuipers closed #352
  • Jan 27 15:07
    MartijnKuipers commented #352
  • Jan 23 22:31
    MartijnKuipers commented #352
  • Jan 23 21:17
    biojppm commented #352
  • Jan 23 19:39
    biojppm commented #351
  • Jan 23 19:35
    biojppm commented #351
  • Jan 23 19:35
    biojppm commented #351
  • Jan 23 19:34
    biojppm commented #351
  • Jan 23 18:26
    biojppm commented #351
  • Jan 23 18:26
    biojppm commented #351
  • Jan 23 18:15
    KadeDev commented #351
  • Jan 23 18:12
    biojppm commented #351
  • Jan 23 18:09
    biojppm commented #351
  • Jan 23 18:09
    biojppm commented #351
jpmag
@biojppm

@aitken.tim_gitlab - Thanks for asking. You are correct. Indeed, the reasoning here is different for parse() and emit(). The former always requires an existing YAML string which is indexed into in the tree, whereas emitting is a bit more abstract in that regard, because we're just dumping characters into a sink. So that's why the API reflects this distinction. Maybe it would make sense to create some wrappers like receiving FILE* and doing something like file_get_contents()to pass the buffer to parse(), but then this would beg the question of also providing wrappers for iostreams, and that is something I'd rather not do - #including streams and std::string in parse is absolutely out of question here. Another reason is that the parse()overloads would grow in number even further. Yet another reason is that I also do not want to force the c4fs library on users, and getting the file contents is actually a minor task.

So that's why things are the way they are. But I'm open to opposing view or enabling ideas, as I admit the situation is not ideal.

Caldfir
@aitken.tim_gitlab
Alrighty, thanks for answering. I guess I would advocate for symmetry between parse/emit in this case because seeing the one prototype sent me on a bit of a goose-chase looking for the other, and I suspect this is going to be common. Alternately, showing a file-based input example in the documentation could help guide people in the right direction.
neko
@nkeonkeo
How to convert ryml::Tree to std::map?
map<string,string>
neko
@nkeonkeo
map<std::any,std::any>
jpmag
@biojppm
@zcmimi sorry for the late reply. Does the main README not help you do it?
@aitken.tim_gitlab your point on the documentation is a good; I'll take that up.
Erez Oxman
@erez-o

Hi, I created a documentation with api references at https://rapidyaml.docsforge.com/
Tell me if it's helpful, It's basically a modern version of doxygen.
Disclaimer, I'm the creator of docsforge.

BTW, you're using doxygen groups for preprocess_json & preprocess_rxmap. Is that intended?

14 replies
Riddle
@riddlepl

Hello, I've a problem with the ryml library. Maybe I'm missing something but let me elaborate:
Lets have this simple yaml:

  some_entry: 3
  other_entry_list:
    - first element
    - second element
    - third_element:
       - something_else

What I need to do is to validate such yml. So I wrote code that goes by all children of root, validates its names, then go inside all that has children.. When I approach to "third_element" on the list "other_entry_list" ryml gets weird.. third_element is_map() is true, however is_key() return false

has_children() is true, i can go deeper, but I cant figure out how to get node name of "third_element"
Riddle
@riddlepl
btw why "- third_element" is a map, not a seq?
Riddle
@riddlepl
hmm unexpected.. in sequence.. there is a map with a child of the name -third element
Riddle
@riddlepl
can I somehow print out whole Tree with some debug information about nodes?
1 reply
too see how its actually built
Riddle
@riddlepl

to better show the problem:

some_entry: 3
other_entry_list:
  - first element
  - second element
  - third_element:
     - something_else

and

some_entry: 3
other_entry_list:
  - third_element:
    - something_else

in the second case there is that strange node that is a map but has no key

and in its children there is one child.. and it is "third_element"
but if you change it to the previous example (where it is not alone on the outer list) it looks different
jpmag
@biojppm
This should help clarify:

TEST(seq_of_map, general)
{
    auto tree = parse(R"(
some_entry: 3
other_entry_list:
  - first_element
  - second_element
  - third_element:
    - something_else
)");
    auto r = tree.rootref();
    EXPECT_EQ(r["some_entry"].val(), "3");
    auto other = r["other_entry_list"];
    EXPECT_EQ(other.is_seq(), true);
    EXPECT_EQ(other[0].val(), "first_element");
    EXPECT_EQ(other[1].val(), "second_element");
    EXPECT_EQ(other[2].is_map(), true);
    EXPECT_EQ(other[2]["third_element"].has_key(), true);
    EXPECT_EQ(other[2]["third_element"].has_children(), true);
    EXPECT_EQ(other[2]["third_element"][0].val(), "something_else");
}

The element that is a map is a sequence member. The colon turns it into a map, which has a value that is a sequence.

Welcome to YAMLS's complex simplicity :-)

HTH
And again, there is an unsupported debug header which you can use, in the detail folder
You can also simply emit to stdout, which may clarify what is going on.
Riddle
@riddlepl
well im pretty sure that if you change that yml from example you tested to have only one element in the list, and the element is a map, that map has_key() is false
Riddle
@riddlepl
nevermind i guess i get it now, thank you
Johannes Betz
@johannes90

Hi, I hope it is fine to ask my question here.
I want to use rapidyaml only to save a std::vector to yaml.

If I understood it correctly I can emit something to file but that has to be a tree.
Is it possible to convert a std::vector into a tree and to save that using ryml::emit?

And can I use the library for that conversion?