rapidyaml  0.16.0
parseandemitYAML,anddoitfast
emit_buf.cpp
Go to the documentation of this file.
1 #ifndef C4_YML_EMIT_BUF_HPP_
2 #include "c4/yml/emit_buf.hpp"
3 #endif
4 #ifndef C4_YML_WRITER_BUF_HPP_
5 #include "c4/yml/writer_buf.hpp"
6 #endif
7 #ifndef C4_YML_TREE_HPP_
8 #include "c4/yml/tree.hpp"
9 #endif
10 #ifndef C4_YML_NODE_HPP_
11 #include "c4/yml/node.hpp"
12 #endif
13 #ifndef C4_YML_EMITTER_DEF_HPP_
14 #include "c4/yml/emitter.def.hpp"
15 #endif
16 
17 
18 namespace c4 {
19 namespace yml {
20 
21 
22 // instantiate the template class
23 template class RYML_EXPORT Emitter<WriterBuf>;
24 
25 
26 // emit from root -------------------------
27 
28 substr emit_yaml(Tree const& t, EmitOptions const& opts, substr buf, bool error_on_excess)
29 {
30  EmitterBuf em(opts, buf);
31  em.emit_as(EMIT_YAML, &t);
32  return em.get_result(error_on_excess);
33 }
34 
35 substr emit_yaml(Tree const& t, substr buf, bool error_on_excess)
36 {
37  EmitterBuf em(EmitOptions{}, buf);
38  em.emit_as(EMIT_YAML, &t);
39  return em.get_result(error_on_excess);
40 }
41 
42 substr emit_json(Tree const& t, EmitOptions const& opts, substr buf, bool error_on_excess)
43 {
44  EmitterBuf em(opts, buf);
45  em.emit_as(EMIT_JSON, &t);
46  return em.get_result(error_on_excess);
47 }
48 
49 substr emit_json(Tree const& t, substr buf, bool error_on_excess)
50 {
51  EmitterBuf em(EmitOptions{}, buf);
52  em.emit_as(EMIT_JSON, &t);
53  return em.get_result(error_on_excess);
54 }
55 
56 
57 // emit from tree and node id -----------------------
58 
59 substr emit_yaml(Tree const& t, id_type id, EmitOptions const& opts, substr buf, bool error_on_excess)
60 {
61  EmitterBuf em(opts, buf);
62  em.emit_as(EMIT_YAML, &t, id);
63  return em.get_result(error_on_excess);
64 }
65 
66 substr emit_yaml(Tree const& t, id_type id, substr buf, bool error_on_excess)
67 {
68  EmitterBuf em(EmitOptions{}, buf);
69  em.emit_as(EMIT_YAML, &t, id);
70  return em.get_result(error_on_excess);
71 }
72 
73 substr emit_json(Tree const& t, id_type id, EmitOptions const& opts, substr buf, bool error_on_excess)
74 {
75  EmitterBuf em(opts, buf);
76  em.emit_as(EMIT_JSON, &t, id);
77  return em.get_result(error_on_excess);
78 }
79 
80 substr emit_json(Tree const& t, id_type id, substr buf, bool error_on_excess)
81 {
82  EmitterBuf em(EmitOptions{}, buf);
83  em.emit_as(EMIT_JSON, &t, id);
84  return em.get_result(error_on_excess);
85 }
86 
87 
88 // emit from ConstNodeRef ------------------------
89 
90 substr emit_yaml(ConstNodeRef const& r, EmitOptions const& opts, substr buf, bool error_on_excess)
91 {
92  EmitterBuf em(opts, buf);
93  em.emit_as(EMIT_YAML, r.tree(), r.id());
94  return em.get_result(error_on_excess);
95 }
96 
97 substr emit_yaml(ConstNodeRef const& r, substr buf, bool error_on_excess)
98 {
99  EmitterBuf em(EmitOptions{}, buf);
100  em.emit_as(EMIT_YAML, r.tree(), r.id());
101  return em.get_result(error_on_excess);
102 }
103 
104 substr emit_json(ConstNodeRef const& r, EmitOptions const& opts, substr buf, bool error_on_excess)
105 {
106  EmitterBuf em(opts, buf);
107  em.emit_as(EMIT_JSON, r.tree(), r.id());
108  return em.get_result(error_on_excess);
109 }
110 
111 substr emit_json(ConstNodeRef const& r, substr buf, bool error_on_excess)
112 {
113  EmitterBuf em(EmitOptions{}, buf);
114  em.emit_as(EMIT_JSON, r.tree(), r.id());
115  return em.get_result(error_on_excess);
116 }
117 
118 } // namespace yml
119 } // namespace c4
A YAML/JSON emitter, templated on a writer class such as WriterBuf, WriterFile, or WriterOStream...
Definition: emitter.hpp:34
id_type id() const noexcept
Definition: node.hpp:822
substr emit_json(Tree const &t, EmitOptions const &opts, substr buf, bool error_on_excess)
(1) emit JSON to the given buffer.
Definition: emit_buf.cpp:42
RYML_ID_TYPE id_type
The type of a node id in the YAML tree; to override the default type, define the macro RYML_ID_TYPE t...
Definition: common.hpp:124
void emit_as(EmitType_e type, Tree const *tree, id_type id=NONE)
emit!
Definition: emitter.def.hpp:48
Utilities to emit YAML and JSON to buffers or containers.
Holds a pointer to an existing tree, and a node id.
Definition: node.hpp:736
Tree const * tree() const noexcept
Definition: node.hpp:821
substr emit_yaml(Tree const &t, EmitOptions const &opts, substr buf, bool error_on_excess)
(1) emit YAML to the given buffer.
Definition: emit_buf.cpp:28
A lightweight object containing options to be used when emitting.
Node classes.
#define RYML_EXPORT
Definition: export.hpp:18