rapidyaml 0.15.2
parse and emit YAML, and do it fast
Loading...
Searching...
No Matches
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
10namespace c4 {
11namespace yml {
12
13
14/** @cond dev */
15// fwd declarations
16template<class Writer>
17class Emitter;
18struct WriterBuf;
19class Tree;
20class ConstNodeRef;
21struct 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() . */
46RYML_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 */
48RYML_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. */
58RYML_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 */
60RYML_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. */
81RYML_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 */
83RYML_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. */
94RYML_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 */
96RYML_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. */
116RYML_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 */
118RYML_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. */
128RYML_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 */
130RYML_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_ */
Holds a pointer to an existing tree, and a node id.
Definition node.hpp:478
A YAML/JSON emitter, templated on a writer class such as WriterBuf, WriterFile, or WriterOStream.
Definition emitter.hpp:35
Common utilities and infrastructure used by ryml.
#define RYML_EXPORT
Definition export.hpp:18
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
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
Emitter< WriterBuf > EmitterBuf
Definition emit_buf.hpp:26
basic_substring< char > substr
a mutable string view
Definition substr.hpp:2356
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:305
(Undefined by default) Use shorter error message from checks/asserts: do not show the check condition...
Definition common.cpp:14
A lightweight object containing options to be used when emitting.
A writer to a memory buffer, in the form of a substr .