rapidyaml  0.16.0
parseandemitYAML,anddoitfast
emit_buf.hpp
Go to the documentation of this file.
1 #ifndef C4_YML_EMIT_BUF_HPP_
2 #define C4_YML_EMIT_BUF_HPP_
3 
4 /** @file emit_buf.hpp Utilities to emit YAML and JSON to buffers or containers. */
5 
6 #ifndef C4_YML_COMMON_HPP_
7 #include "c4/yml/common.hpp"
8 #endif
9 
10 namespace c4 {
11 namespace yml {
12 
13 
14 /** @cond dev */
15 // fwd declarations
16 template<class Writer>
17 class Emitter;
18 struct WriterBuf;
19 class Tree;
20 class ConstNodeRef;
21 struct EmitOptions;
22 /** @endcond */
23 
24 
25 /** @ingroup doc_emit_to_buffer */
27 
28 
29 // emit from root -------------------------
30 
31 /** @addtogroup doc_emit_to_buffer_from_root
32  *
33  * @{
34  */
35 
36 /** (1) emit YAML to the given buffer. Return a substr trimmed to the emitted YAML.
37  * @param t the tree; will be emitted from the root node.
38  * @param opts emit options.
39  * @param buf the output buffer.
40  * @param error_on_excess Raise an error if the space in the buffer is insufficient.
41  * @return a substr trimmed to the result in the output buffer. If the
42  * buffer is insufficient (when error_on_excess is false), the string
43  * pointer of the result will be set to null, and the length will
44  * report the required buffer size. For example usage, see @ref
45  * emitrs_yaml() . */
46 RYML_EXPORT substr emit_yaml(Tree const& t, EmitOptions const& opts, substr buf, bool error_on_excess=true);
47 /** (2) like (1), but use default emit options */
48 RYML_EXPORT substr emit_yaml(Tree const& t, substr buf, bool error_on_excess=true);
49 
50 /** (1) emit JSON to the given buffer. Return a substr trimmed to the emitted JSON.
51  * @param t the tree; will be emitted from the root node.
52  * @param opts emit options.
53  * @param buf the output buffer.
54  * @param error_on_excess Raise an error if the space in the buffer is insufficient.
55  * @return a substr trimmed to the result in the output buffer. If the buffer is
56  * insufficient (when error_on_excess is false), the string pointer of the
57  * result will be set to null, and the length will report the required buffer size. */
58 RYML_EXPORT substr emit_json(Tree const& t, EmitOptions const& opts, substr buf, bool error_on_excess=true);
59 /** (2) like (1), but use default emit options */
60 RYML_EXPORT substr emit_json(Tree const& t, substr buf, bool error_on_excess=true);
61 
62 /** @} */
63 
64 
65 // emit from tree and node id -----------------------
66 
67 /** @addtogroup doc_emit_to_buffer_from_node_id
68  *
69  * @{
70  */
71 
72 /** (1) emit YAML to the given buffer. Return a substr trimmed to the emitted YAML.
73  * @param t the tree to emit.
74  * @param id the node where to start emitting.
75  * @param opts emit options.
76  * @param buf the output buffer.
77  * @param error_on_excess Raise an error if the space in the buffer is insufficient.
78  * @return a substr trimmed to the result in the output buffer. If the buffer is
79  * insufficient (when error_on_excess is false), the string pointer of the
80  * result will be set to null, and the length will report the required buffer size. */
81 RYML_EXPORT substr emit_yaml(Tree const& t, id_type id, EmitOptions const& opts, substr buf, bool error_on_excess=true);
82 /** (2) like (1), but use default emit options */
83 RYML_EXPORT substr emit_yaml(Tree const& t, id_type id, substr buf, bool error_on_excess=true);
84 
85 /** (1) emit JSON to the given buffer. Return a substr trimmed to the emitted JSON.
86  * @param t the tree to emit.
87  * @param id the node where to start emitting.
88  * @param opts emit options.
89  * @param buf the output buffer.
90  * @param error_on_excess Raise an error if the space in the buffer is insufficient.
91  * @return a substr trimmed to the result in the output buffer. If the buffer is
92  * insufficient (when error_on_excess is false), the string pointer of the
93  * result will be set to null, and the length will report the required buffer size. */
94 RYML_EXPORT substr emit_json(Tree const& t, id_type id, EmitOptions const& opts, substr buf, bool error_on_excess=true);
95 /** (2) like (1), but use default emit options */
96 RYML_EXPORT substr emit_json(Tree const& t, id_type id, substr buf, bool error_on_excess=true);
97 
98 /** @} */
99 
100 
101 // emit from ConstNodeRef ------------------------
102 
103 /** @addtogroup doc_emit_to_buffer_from_noderef
104  *
105  * @{
106  */
107 
108 /** (1) emit YAML to the given buffer. Return a substr trimmed to the emitted YAML.
109  * @param r the starting node.
110  * @param buf the output buffer.
111  * @param opts emit options.
112  * @param error_on_excess Raise an error if the space in the buffer is insufficient.
113  * @return a substr trimmed to the result in the output buffer. If the buffer is
114  * insufficient (when error_on_excess is false), the string pointer of the
115  * result will be set to null, and the length will report the required buffer size. */
116 RYML_EXPORT substr emit_yaml(ConstNodeRef const& r, EmitOptions const& opts, substr buf, bool error_on_excess=true);
117 /** (2) like (1), but use default emit options */
118 RYML_EXPORT substr emit_yaml(ConstNodeRef const& r, substr buf, bool error_on_excess=true);
119 
120 /** (1) emit JSON to the given buffer. Return a substr trimmed to the emitted JSON.
121  * @param r the starting node.
122  * @param buf the output buffer.
123  * @param opts emit options.
124  * @param error_on_excess Raise an error if the space in the buffer is insufficient.
125  * @return a substr trimmed to the result in the output buffer. If the buffer is
126  * insufficient (when error_on_excess is false), the string pointer of the
127  * result will be set to null, and the length will report the required buffer size. */
128 RYML_EXPORT substr emit_json(ConstNodeRef const& r, EmitOptions const& opts, substr buf, bool error_on_excess=true);
129 /** (2) like (1), but use default emit options */
130 RYML_EXPORT substr emit_json(ConstNodeRef const& r, substr buf, bool error_on_excess=true);
131 
132 /** @} */
133 
134 } // namespace yml
135 } // namespace c4
136 
137 #endif /* C4_YML_EMIT_HPP_ */
A YAML/JSON emitter, templated on a writer class such as WriterBuf, WriterFile, or WriterOStream...
Definition: emitter.hpp:34
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
Common utilities and infrastructure used by ryml.
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
Holds a pointer to an existing tree, and a node id.
Definition: node.hpp:736
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.
#define RYML_EXPORT
Definition: export.hpp:18