1 #ifndef C4_YML_EMITTER_HPP_
2 #define C4_YML_EMITTER_HPP_
6 #ifndef C4_YML_EMIT_OPTIONS_HPP_
9 #ifndef C4_YML_NODE_TYPE_HPP_
33 template<
class Writer>
43 template<
class ...WriterArgs>
45 : Writer(std::forward<WriterArgs>(args)...)
73 typedef enum : uint32_t { PWS_NONE_ = 0u, PWS_SPACE_ = 1u, PWS_NEWL_ = 2u } Pws_e;
76 C4_ALWAYS_INLINE
void pend_none_() noexcept
81 C4_ALWAYS_INLINE
void pend_newl_() noexcept
86 C4_ALWAYS_INLINE
void pend_space_() noexcept
91 C4_ALWAYS_INLINE
void write_pws_and_pend_(Pws_e next=PWS_NONE_) noexcept
93 if(m_pws == PWS_SPACE_)
97 else if(m_pws == PWS_NEWL_)
109 Pws_e pend_after_comma = PWS_NONE_;
111 C4_ALWAYS_INLINE Pws_e next_pws(
size_t col)
const noexcept
113 return (active && col >= max_cols) ? PWS_NEWL_ : pend_after_comma;
115 void start(NodeType ty,
size_t max_cols_) noexcept;
116 void stop() noexcept { active =
false; }
119 C4_NODISCARD
bool maybe_start_flow_pws_ml_(
id_type node) noexcept;
120 C4_NODISCARD flow_pws setup_flow_pws_sl_(
id_type node) noexcept;
126 void visit_stream_(
id_type id);
128 void visit_doc_val_(
id_type id);
129 void visit_blck_container_(
id_type id);
130 void visit_flow_container_(
id_type id);
132 void visit_flow_sl_(
id_type id);
133 void visit_flow_sl_seq_(
id_type id);
134 void visit_flow_sl_map_(
id_type id);
136 void visit_flow_ml_(
id_type id);
137 void visit_flow_ml_seq_(
id_type id);
138 void visit_flow_ml_map_(
id_type id);
141 void visit_blck_seq_(
id_type id);
142 void visit_blck_map_(
id_type id);
144 void top_open_entry_(
id_type id);
145 void top_close_entry_(
id_type id);
146 void blck_seq_open_entry_(
id_type id);
147 void blck_map_open_entry_(
id_type id);
148 void blck_close_entry_(
id_type id);
151 void flow_seq_open_entry_(
id_type id);
152 void flow_map_open_entry_(
id_type id);
153 void flow_close_entry_sl_(
id_type id,
id_type last_sibling, Pws_e pend_after);
154 void flow_close_entry_ml_(
id_type id,
id_type last_sibling, Pws_e pend_after);
166 size_t write_escaped_newlines_(
csubstr s,
size_t i);
173 bool json_maybe_write_naninf_(
csubstr s);
174 void json_writek_(
id_type id, NodeType ty);
175 void json_writev_(
id_type id, NodeType ty);
176 void json_write_scalar_dquo_(
csubstr s);
177 void json_write_number_(
csubstr s);
183 if(!tag.begins_with(
'!'))
191 if(!ref.begins_with(
'*'))
200 C4_ALWAYS_INLINE
void write_(
const char (&a)[N])
202 this->Writer::append(std::forward<
const char (&)[N]>(a));
205 C4_ALWAYS_INLINE
void write_(
csubstr s)
207 this->Writer::append(s);
210 C4_ALWAYS_INLINE
void write_(
char c)
212 this->Writer::append(c);
216 C4_ALWAYS_INLINE
void indent_(
id_type level)
218 C4_SUPPRESS_WARNING_GCC_WITH_PUSH(
"-Wuseless-cast")
219 size_t num = static_cast<
size_t>(2u * level);
220 this->Writer::append(' ', num);
222 C4_SUPPRESS_WARNING_GCC_POP
226 C4_ALWAYS_INLINE
void newl_()
228 this->Writer::append(
'\n');
234 Tree
const* C4_RESTRICT m_tree;
245 RYML_DEPRECATED(
"create a new emitter") void
options(EmitOptions) noexcept { ; }
246 RYML_DEPRECATED(
"use .options()") void max_depth(
id_type max_depth) noexcept { m_opts.
max_depth(max_depth); }
247 RYML_DEPRECATED(
"use .options()")
id_type max_depth() const noexcept {
return m_opts.max_depth(); }
EmitOptions const & options() const noexcept
get the emit options for this object
A YAML/JSON emitter, templated on a writer class such as WriterBuf, WriterFile, or WriterOStream...
Emitter(EmitOptions const &opts, WriterArgs &&...args) noexcept
Construct the emitter and its internal Writer state.
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...
void emit_as(EmitType_e type, Tree const *tree, id_type id=NONE)
emit!
basic_substring< const char > csubstr
an immutable string view
A lightweight object containing options to be used when emitting.
uint32_t type_bits
the integral type necessary to cover all the bits for NodeType_e
id_type max_depth() const noexcept