rapidyaml 0.15.2
parse and emit YAML, and do it fast
Loading...
Searching...
No Matches
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_
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_
15#endif
16
17
18namespace c4 {
19namespace yml {
20
21
22// instantiate the template class
23template class RYML_EXPORT Emitter<WriterBuf>;
24
25
26// emit from root -------------------------
27
28substr 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
35substr 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
42substr 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
49substr 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
59substr 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
66substr 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
73substr 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
80substr 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
90substr 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
97substr 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
104substr 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
111substr 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
Holds a pointer to an existing tree, and a node id.
Definition node.hpp:478
id_type id() const noexcept
Definition node.hpp:564
Tree const * tree() const noexcept
Definition node.hpp:563
A YAML/JSON emitter, templated on a writer class such as WriterBuf, WriterFile, or WriterOStream.
Definition emitter.hpp:35
void emit_as(EmitType_e type, Tree const *tree, id_type id=NONE)
emit!
Utilities to emit YAML and JSON to buffers or containers.
#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
Node classes.
A lightweight object containing options to be used when emitting.
substr get_result(bool error_on_excess) const
Return the buffer written so far, or optionally throw an error if the buffer was too small.