5
votes

Is there a C++ library for emitting YAML? Wikipedia mentions a c++ wrapper for libyaml, but the link is broken. The official YAML site only offers yaml-cpp, which was also suggested in this SO question, but cpp-yaml is only a parser, not an emitter. Am I out of luck?

Edit: I'm looking for an object oriented interface, hence the C++ requirement. I know I could use libyaml's C interface in C++ code, but that's less than ideal.

2
I'm the author of yaml-cpp, and I've been meaning to write an emitter for some time, but since my own projects don't require one, I haven't been able to think of a good API. What kinds of things would you like to emit, and what would be an ideal user interface for you? If you leave a comment in the google code wiki, I'd be very appreciative! - Jesse Beder
Hi, Jesse. Its good to meet the one daring soul attempting a C++ YAML library. Considering the lack of response to my question, it sounds like you're the last best hope for what I'm looking for. I looked at the page late last night, but struggled with a good API; I'll spend some more time this weekend thinking about it. - Kyle Simek
Great! What kinds of YAML documents are you trying to generate? I haven't yet seen a non-artificially constructed example. - Jesse Beder
I want to use it as a serialization format for, well, everything. I'm starting a new project and I want to be to serialize all of my classes in a human-readable format. I'm not happy with XML's angle bracket tax (thanks, Jeff!), and a raw text output is difficult for human readers to parse. - Kyle Simek
OK, I've given it some thought in terms of serialization, and it gave me some ideas. Check out the wiki and let me know what you think (I tacked on the "Stream method" to the end). - Jesse Beder

2 Answers

7
votes

Per your suggestion, yaml-cpp now has an emitter.

2
votes

How about libyaml ?

LibYAML is a YAML 1.1 parser and emitter written in C.

And, more directly, emitter.c ?