rapidyaml  0.7.1
parse and emit YAML, and do it fast
Emit to memory buffer

Modules

 Emit to resizeable container
 

Enumerations

enum  c4::yml::EmitOptions::EmitOptionFlags_e : uint32_t { c4::yml::EmitOptions::DEFAULT_FLAGS = 0 , c4::yml::EmitOptions::JSON_ERR_ON_TAG = 1 << 0 , c4::yml::EmitOptions::JSON_ERR_ON_ANCHOR = 1 << 1 , c4::yml::EmitOptions::_JSON_ERR_MASK = JSON_ERR_ON_TAG|JSON_ERR_ON_ANCHOR }
 

Functions

bool c4::yml::detail::is_set_ (ConstNodeRef n)
 
bool c4::yml::EmitOptions::operator== (const EmitOptions &that) const noexcept
 
template<class ... Args>
 c4::yml::Emitter< Writer >::Emitter (Args &&...args)
 Construct the emitter and its internal Writer state, using default emit options. More...
 
template<class ... Args>
 c4::yml::Emitter< Writer >::Emitter (EmitOptions const &opts, Args &&...args)
 Construct the emitter and its internal Writer state. More...
 
substr c4::yml::Emitter< Writer >::emit_as (EmitType_e type, Tree const &t, id_type id, bool error_on_excess)
 emit! More...
 
substr c4::yml::Emitter< Writer >::emit_as (EmitType_e type, Tree const &t, bool error_on_excess=true)
 emit starting at the root node More...
 
substr c4::yml::Emitter< Writer >::emit_as (EmitType_e type, ConstNodeRef const &n, bool error_on_excess=true)
 emit starting at the given node More...
 
EmitOptions const & c4::yml::Emitter< Writer >::options () const noexcept
 get the emit options for this object More...
 
void c4::yml::Emitter< Writer >::max_depth (id_type max_depth) noexcept
 set the max depth for emitted trees (to prevent a stack overflow) More...
 
id_type c4::yml::Emitter< Writer >::max_depth () const noexcept
 get the max depth for emitted trees (to prevent a stack overflow) More...
 
 c4::yml::as_json::as_json (Tree const &t, EmitOptions const &opts={})
 
 c4::yml::as_json::as_json (Tree const &t, size_t id, EmitOptions const &opts={})
 
 c4::yml::as_json::as_json (ConstNodeRef const &n, EmitOptions const &opts={})
 
 c4::yml::as_yaml::as_yaml (Tree const &t, EmitOptions const &opts={})
 
 c4::yml::as_yaml::as_yaml (Tree const &t, size_t id, EmitOptions const &opts={})
 
 c4::yml::as_yaml::as_yaml (ConstNodeRef const &n, EmitOptions const &opts={})
 
substr c4::yml::emit_yaml (Tree const &t, id_type id, EmitOptions const &opts, substr buf, bool error_on_excess=true)
 (1) emit YAML to the given buffer. More...
 
substr c4::yml::emit_yaml (Tree const &t, id_type id, substr buf, bool error_on_excess=true)
 (2) like (1), but use default emit options More...
 
substr c4::yml::emit_json (Tree const &t, id_type id, EmitOptions const &opts, substr buf, bool error_on_excess=true)
 (1) emit JSON to the given buffer. More...
 
substr c4::yml::emit_json (Tree const &t, id_type id, substr buf, bool error_on_excess=true)
 (2) like (1), but use default emit options More...
 
substr c4::yml::emit_yaml (Tree const &t, EmitOptions const &opts, substr buf, bool error_on_excess=true)
 (1) emit YAML to the given buffer. More...
 
substr c4::yml::emit_yaml (Tree const &t, substr buf, bool error_on_excess=true)
 (2) like (1), but use default emit options More...
 
substr c4::yml::emit_json (Tree const &t, EmitOptions const &opts, substr buf, bool error_on_excess=true)
 (1) emit JSON to the given buffer. More...
 
substr c4::yml::emit_json (Tree const &t, substr buf, bool error_on_excess=true)
 (2) like (1), but use default emit options More...
 
substr c4::yml::emit_yaml (ConstNodeRef const &r, EmitOptions const &opts, substr buf, bool error_on_excess=true)
 (1) emit YAML to the given buffer. More...
 
substr c4::yml::emit_yaml (ConstNodeRef const &r, substr buf, bool error_on_excess=true)
 (2) like (1), but use default emit options More...
 
substr c4::yml::emit_json (ConstNodeRef const &r, EmitOptions const &opts, substr buf, bool error_on_excess=true)
 (1) emit JSON to the given buffer. More...
 
substr c4::yml::emit_json (ConstNodeRef const &r, substr buf, bool error_on_excess=true)
 (2) like (1), but use default emit options More...
 

Variables

Tree const * c4::yml::as_json::tree
 
size_t c4::yml::as_json::node
 
EmitOptions c4::yml::as_json::options
 
Tree const * c4::yml::as_yaml::tree
 
size_t c4::yml::as_yaml::node
 
EmitOptions c4::yml::as_yaml::options
 

max depth for the emitted tree

This makes the emitter fail when emitting trees exceeding the max_depth.

static constexpr const id_type c4::yml::EmitOptions::max_depth_default = 64
 
id_type c4::yml::EmitOptions::max_depth () const noexcept
 
EmitOptionsc4::yml::EmitOptions::max_depth (id_type d) noexcept
 

option flags

EmitOptionFlags_e c4::yml::EmitOptions::json_error_flags () const noexcept
 
EmitOptionsc4::yml::EmitOptions::json_error_flags (EmitOptionFlags_e d) noexcept
 

Detailed Description

Enumeration Type Documentation

◆ EmitOptionFlags_e

Enumerator
DEFAULT_FLAGS 
JSON_ERR_ON_TAG 
JSON_ERR_ON_ANCHOR 
_JSON_ERR_MASK 

Definition at line 77 of file emit.hpp.

Function Documentation

◆ is_set_()

bool c4::yml::detail::is_set_ ( ConstNodeRef  n)
inline

◆ json_error_flags() [1/2]

EmitOptionFlags_e c4::yml::EmitOptions::json_error_flags ( ) const
inlinenoexcept

Definition at line 89 of file emit.hpp.

89 { return m_option_flags; }

◆ json_error_flags() [2/2]

EmitOptions& c4::yml::EmitOptions::json_error_flags ( EmitOptionFlags_e  d)
inlinenoexcept

Definition at line 90 of file emit.hpp.

90 { m_option_flags = (EmitOptionFlags_e)(d & _JSON_ERR_MASK); return *this; }

◆ max_depth() [1/4]

id_type c4::yml::EmitOptions::max_depth ( ) const
inlinenoexcept

Definition at line 101 of file emit.hpp.

101 { return m_max_depth; }

◆ max_depth() [2/4]

EmitOptions& c4::yml::EmitOptions::max_depth ( id_type  d)
inlinenoexcept

Definition at line 102 of file emit.hpp.

102 { m_max_depth = d; return *this; }

◆ operator==()

bool c4::yml::EmitOptions::operator== ( const EmitOptions that) const
inlinenoexcept

Definition at line 108 of file emit.hpp.

109  {
110  return m_max_depth == that.m_max_depth &&
111  m_option_flags == that.m_option_flags;
112  }

◆ Emitter() [1/2]

template<class Writer >
template<class ... Args>
c4::yml::Emitter< Writer >::Emitter ( Args &&...  args)
inline

Construct the emitter and its internal Writer state, using default emit options.

Parameters
argsarguments to be forwarded to the constructor of the writer.

Definition at line 138 of file emit.hpp.

138 : Writer(std::forward<Args>(args)...), m_tree(), m_opts(), m_flow(false) {}

◆ Emitter() [2/2]

template<class Writer >
template<class ... Args>
c4::yml::Emitter< Writer >::Emitter ( EmitOptions const &  opts,
Args &&...  args 
)
inline

Construct the emitter and its internal Writer state.

Parameters
optsEmitOptions
argsarguments to be forwarded to the constructor of the writer.

Definition at line 146 of file emit.hpp.

146 : Writer(std::forward<Args>(args)...), m_tree(), m_opts(opts), m_flow(false) {}

◆ emit_as() [1/3]

template<class Writer >
substr c4::yml::Emitter< Writer >::emit_as ( EmitType_e  type,
Tree const &  t,
id_type  id,
bool  error_on_excess 
)

emit!

When writing to a buffer, returns a substr of the emitted YAML. If the given buffer has insufficient space, the returned substr will be null and its size will be the needed space. Whatever the size of the buffer, it is guaranteed that no writes are done past its end.

When writing to a file, the returned substr will be null, but its length will be set to the number of bytes written.

Parameters
typespecify what to emit
tthe tree to emit
idthe id of the node to emit
error_on_excesswhen true, an error is raised when the output buffer is too small for the emitted YAML/JSON

Definition at line 17 of file emit.def.hpp.

18 {
19  if(t.empty())
20  {
21  _RYML_CB_ASSERT(t.callbacks(), id == NONE);
22  return {};
23  }
24  if(id == NONE)
25  id = t.root_id();
26  _RYML_CB_CHECK(t.callbacks(), id < t.capacity());
27  m_tree = &t;
28  m_flow = false;
29  if(type == EMIT_YAML)
30  _emit_yaml(id);
31  else if(type == EMIT_JSON)
32  _do_visit_json(id, 0);
33  else
34  _RYML_CB_ERR(m_tree->callbacks(), "unknown emit type");
35  m_tree = nullptr;
36  return this->Writer::_get(error_on_excess);
37 }
Callbacks const & callbacks() const
Definition: tree.hpp:282
@ EMIT_YAML
emit YAML
Definition: emit.hpp:65
@ EMIT_JSON
emit JSON
Definition: emit.hpp:66

References c4::yml::Tree::callbacks(), c4::yml::Tree::capacity(), c4::yml::EMIT_JSON, c4::yml::EMIT_YAML, c4::yml::Tree::empty(), c4::yml::NONE, and c4::yml::Tree::root_id().

Referenced by c4::yml::emit_json(), c4::yml::emit_yaml(), and c4::yml::operator<<().

◆ emit_as() [2/3]

template<class Writer >
substr c4::yml::Emitter< Writer >::emit_as ( EmitType_e  type,
Tree const &  t,
bool  error_on_excess = true 
)
inline

emit starting at the root node

Definition at line 167 of file emit.hpp.

168  {
169  if(t.empty())
170  return {};
171  return this->emit_as(type, t, t.root_id(), error_on_excess);
172  }
substr emit_as(EmitType_e type, Tree const &t, id_type id, bool error_on_excess)
emit!
Definition: emit.def.hpp:17

References c4::yml::Tree::empty(), and c4::yml::Tree::root_id().

◆ emit_as() [3/3]

template<class Writer >
substr c4::yml::Emitter< Writer >::emit_as ( EmitType_e  type,
ConstNodeRef const &  n,
bool  error_on_excess = true 
)
inline

emit starting at the given node

Definition at line 174 of file emit.hpp.

175  {
176  if(!detail::is_set_(n))
177  return {};
178  _RYML_CB_CHECK(n.tree()->callbacks(), n.readable());
179  return this->emit_as(type, *n.tree(), n.id(), error_on_excess);
180  }
bool is_set_(ConstNodeRef n)
Definition: emit.hpp:55

References c4::yml::Tree::callbacks(), c4::yml::ConstNodeRef::id(), c4::yml::detail::is_set_(), c4::yml::ConstNodeRef::readable(), and c4::yml::ConstNodeRef::tree().

◆ options()

template<class Writer >
EmitOptions const& c4::yml::Emitter< Writer >::options ( ) const
inlinenoexcept

get the emit options for this object

Definition at line 185 of file emit.hpp.

185 { return m_opts; }

◆ max_depth() [3/4]

template<class Writer >
void c4::yml::Emitter< Writer >::max_depth ( id_type  max_depth)
inlinenoexcept

set the max depth for emitted trees (to prevent a stack overflow)

Definition at line 188 of file emit.hpp.

188 { m_opts.max_depth(max_depth); }
id_type max_depth() const noexcept
get the max depth for emitted trees (to prevent a stack overflow)
Definition: emit.hpp:190
id_type max_depth() const noexcept
Definition: emit.hpp:101

◆ max_depth() [4/4]

template<class Writer >
id_type c4::yml::Emitter< Writer >::max_depth ( ) const
inlinenoexcept

get the max depth for emitted trees (to prevent a stack overflow)

Definition at line 190 of file emit.hpp.

190 { return m_opts.max_depth(); }

◆ as_json() [1/3]

c4::yml::as_json::as_json ( Tree const &  t,
EmitOptions const &  opts = {} 
)
inline

Definition at line 410 of file emit.hpp.

410 {}) : tree(&t), node(t.empty() ? NONE : t.root_id()), options(opts) {}
Tree const * tree
Definition: emit.hpp:407
EmitOptions options
Definition: emit.hpp:409
size_t node
Definition: emit.hpp:408

◆ as_json() [2/3]

c4::yml::as_json::as_json ( Tree const &  t,
size_t  id,
EmitOptions const &  opts = {} 
)
inline

Definition at line 411 of file emit.hpp.

411 {}) : tree(&t), node(id), options(opts) {}

◆ as_json() [3/3]

c4::yml::as_json::as_json ( ConstNodeRef const &  n,
EmitOptions const &  opts = {} 
)
inline

Definition at line 412 of file emit.hpp.

412 {}) : tree(n.tree()), node(n.id()), options(opts) {}

◆ as_yaml() [1/3]

c4::yml::as_yaml::as_yaml ( Tree const &  t,
EmitOptions const &  opts = {} 
)
inline

Definition at line 431 of file emit.hpp.

431 {}) : tree(&t), node(t.empty() ? NONE : t.root_id()), options(opts) {}
Tree const * tree
Definition: emit.hpp:428
size_t node
Definition: emit.hpp:429
EmitOptions options
Definition: emit.hpp:430

◆ as_yaml() [2/3]

c4::yml::as_yaml::as_yaml ( Tree const &  t,
size_t  id,
EmitOptions const &  opts = {} 
)
inline

Definition at line 432 of file emit.hpp.

432 {}) : tree(&t), node(id), options(opts) {}

◆ as_yaml() [3/3]

c4::yml::as_yaml::as_yaml ( ConstNodeRef const &  n,
EmitOptions const &  opts = {} 
)
inline

Definition at line 433 of file emit.hpp.

433 {}) : tree(n.tree()), node(n.id()), options(opts) {}

◆ emit_yaml() [1/6]

substr c4::yml::emit_yaml ( Tree const &  t,
id_type  id,
EmitOptions const &  opts,
substr  buf,
bool  error_on_excess = true 
)
inline

(1) emit YAML to the given buffer.

Return a substr trimmed to the emitted YAML.

Parameters
tthe tree to emit.
idthe node where to start emitting.
optsemit options.
bufthe output buffer.
optsemit options.
error_on_excessRaise an error if the space in the buffer is insufficient.
Returns
a substr trimmed to the result in the output buffer. If the buffer is insufficient (when error_on_excess is false), the string pointer of the result will be set to null, and the length will report the required buffer size.

Definition at line 480 of file emit.hpp.

481 {
482  EmitterBuf em(opts, buf);
483  return em.emit_as(EMIT_YAML, t, id, error_on_excess);
484 }
Emitter< WriterBuf > EmitterBuf
Definition: emit.hpp:52

References c4::yml::Emitter< Writer >::emit_as(), and c4::yml::EMIT_YAML.

◆ emit_yaml() [2/6]

substr c4::yml::emit_yaml ( Tree const &  t,
id_type  id,
substr  buf,
bool  error_on_excess = true 
)
inline

(2) like (1), but use default emit options

Definition at line 486 of file emit.hpp.

487 {
488  EmitterBuf em(buf);
489  return em.emit_as(EMIT_YAML, t, id, error_on_excess);
490 }

References c4::yml::Emitter< Writer >::emit_as(), and c4::yml::EMIT_YAML.

◆ emit_json() [1/6]

substr c4::yml::emit_json ( Tree const &  t,
id_type  id,
EmitOptions const &  opts,
substr  buf,
bool  error_on_excess = true 
)
inline

(1) emit JSON to the given buffer.

Return a substr trimmed to the emitted JSON.

Parameters
tthe tree to emit.
idthe node where to start emitting.
optsemit options.
bufthe output buffer.
optsemit options.
error_on_excessRaise an error if the space in the buffer is insufficient.
Returns
a substr trimmed to the result in the output buffer. If the buffer is insufficient (when error_on_excess is false), the string pointer of the result will be set to null, and the length will report the required buffer size.

Definition at line 501 of file emit.hpp.

502 {
503  EmitterBuf em(opts, buf);
504  return em.emit_as(EMIT_JSON, t, id, error_on_excess);
505 }

References c4::yml::Emitter< Writer >::emit_as(), and c4::yml::EMIT_JSON.

◆ emit_json() [2/6]

substr c4::yml::emit_json ( Tree const &  t,
id_type  id,
substr  buf,
bool  error_on_excess = true 
)
inline

(2) like (1), but use default emit options

Definition at line 507 of file emit.hpp.

508 {
509  EmitterBuf em(buf);
510  return em.emit_as(EMIT_JSON, t, id, error_on_excess);
511 }

References c4::yml::Emitter< Writer >::emit_as(), and c4::yml::EMIT_JSON.

◆ emit_yaml() [3/6]

substr c4::yml::emit_yaml ( Tree const &  t,
EmitOptions const &  opts,
substr  buf,
bool  error_on_excess = true 
)
inline

(1) emit YAML to the given buffer.

Return a substr trimmed to the emitted YAML.

Parameters
tthe tree; will be emitted from the root node.
bufthe output buffer.
error_on_excessRaise an error if the space in the buffer is insufficient.
Returns
a substr trimmed to the result in the output buffer. If the buffer is insufficient (when error_on_excess is false), the string pointer of the result will be set to null, and the length will report the required buffer size.

Definition at line 523 of file emit.hpp.

524 {
525  EmitterBuf em(opts, buf);
526  return em.emit_as(EMIT_YAML, t, error_on_excess);
527 }

References c4::yml::Emitter< Writer >::emit_as(), and c4::yml::EMIT_YAML.

◆ emit_yaml() [4/6]

substr c4::yml::emit_yaml ( Tree const &  t,
substr  buf,
bool  error_on_excess = true 
)
inline

(2) like (1), but use default emit options

Definition at line 529 of file emit.hpp.

530 {
531  EmitterBuf em(buf);
532  return em.emit_as(EMIT_YAML, t, error_on_excess);
533 }

References c4::yml::Emitter< Writer >::emit_as(), and c4::yml::EMIT_YAML.

◆ emit_json() [3/6]

substr c4::yml::emit_json ( Tree const &  t,
EmitOptions const &  opts,
substr  buf,
bool  error_on_excess = true 
)
inline

(1) emit JSON to the given buffer.

Return a substr trimmed to the emitted JSON.

Parameters
tthe tree; will be emitted from the root node.
bufthe output buffer.
error_on_excessRaise an error if the space in the buffer is insufficient.
Returns
a substr trimmed to the result in the output buffer. If the buffer is insufficient (when error_on_excess is false), the string pointer of the result will be set to null, and the length will report the required buffer size.

Definition at line 541 of file emit.hpp.

542 {
543  EmitterBuf em(opts, buf);
544  return em.emit_as(EMIT_JSON, t, error_on_excess);
545 }

References c4::yml::Emitter< Writer >::emit_as(), and c4::yml::EMIT_JSON.

◆ emit_json() [4/6]

substr c4::yml::emit_json ( Tree const &  t,
substr  buf,
bool  error_on_excess = true 
)
inline

(2) like (1), but use default emit options

Definition at line 547 of file emit.hpp.

548 {
549  EmitterBuf em(buf);
550  return em.emit_as(EMIT_JSON, t, error_on_excess);
551 }

References c4::yml::Emitter< Writer >::emit_as(), and c4::yml::EMIT_JSON.

◆ emit_yaml() [5/6]

substr c4::yml::emit_yaml ( ConstNodeRef const &  r,
EmitOptions const &  opts,
substr  buf,
bool  error_on_excess = true 
)
inline

(1) emit YAML to the given buffer.

Return a substr trimmed to the emitted YAML.

Parameters
rthe starting node.
bufthe output buffer.
optsemit options.
error_on_excessRaise an error if the space in the buffer is insufficient.
Returns
a substr trimmed to the result in the output buffer. If the buffer is insufficient (when error_on_excess is false), the string pointer of the result will be set to null, and the length will report the required buffer size.

Definition at line 564 of file emit.hpp.

565 {
566  if(!detail::is_set_(r))
567  return {};
568  EmitterBuf em(opts, buf);
569  return em.emit_as(EMIT_YAML, r, error_on_excess);
570 }

References c4::yml::Emitter< Writer >::emit_as(), c4::yml::EMIT_YAML, and c4::yml::detail::is_set_().

◆ emit_yaml() [6/6]

substr c4::yml::emit_yaml ( ConstNodeRef const &  r,
substr  buf,
bool  error_on_excess = true 
)
inline

(2) like (1), but use default emit options

Definition at line 572 of file emit.hpp.

573 {
574  if(!detail::is_set_(r))
575  return {};
576  EmitterBuf em(buf);
577  return em.emit_as(EMIT_YAML, r, error_on_excess);
578 }

References c4::yml::Emitter< Writer >::emit_as(), c4::yml::EMIT_YAML, and c4::yml::detail::is_set_().

Referenced by c4::yml::emitrs_yaml().

◆ emit_json() [5/6]

substr c4::yml::emit_json ( ConstNodeRef const &  r,
EmitOptions const &  opts,
substr  buf,
bool  error_on_excess = true 
)
inline

(1) emit JSON to the given buffer.

Return a substr trimmed to the emitted JSON.

Parameters
rthe starting node.
bufthe output buffer.
optsemit options.
error_on_excessRaise an error if the space in the buffer is insufficient.
Returns
a substr trimmed to the result in the output buffer. If the buffer is insufficient (when error_on_excess is false), the string pointer of the result will be set to null, and the length will report the required buffer size.

Definition at line 587 of file emit.hpp.

588 {
589  if(!detail::is_set_(r))
590  return {};
591  EmitterBuf em(opts, buf);
592  return em.emit_as(EMIT_JSON, r, error_on_excess);
593 }

References c4::yml::Emitter< Writer >::emit_as(), c4::yml::EMIT_JSON, and c4::yml::detail::is_set_().

◆ emit_json() [6/6]

substr c4::yml::emit_json ( ConstNodeRef const &  r,
substr  buf,
bool  error_on_excess = true 
)
inline

(2) like (1), but use default emit options

Definition at line 595 of file emit.hpp.

596 {
597  if(!detail::is_set_(r))
598  return {};
599  EmitterBuf em(buf);
600  return em.emit_as(EMIT_JSON, r, error_on_excess);
601 }

References c4::yml::Emitter< Writer >::emit_as(), c4::yml::EMIT_JSON, and c4::yml::detail::is_set_().

Referenced by c4::yml::emitrs_json().

Variable Documentation

◆ max_depth_default

constexpr const id_type c4::yml::EmitOptions::max_depth_default = 64
staticconstexpr

Definition at line 103 of file emit.hpp.

◆ tree [1/2]

Tree const* c4::yml::as_json::tree

Definition at line 407 of file emit.hpp.

Referenced by c4::yml::operator<<().

◆ node [1/2]

size_t c4::yml::as_json::node

Definition at line 408 of file emit.hpp.

Referenced by c4::yml::operator<<().

◆ options [1/2]

EmitOptions c4::yml::as_json::options

Definition at line 409 of file emit.hpp.

Referenced by c4::yml::operator<<().

◆ tree [2/2]

Tree const* c4::yml::as_yaml::tree

Definition at line 428 of file emit.hpp.

Referenced by c4::yml::operator<<().

◆ node [2/2]

size_t c4::yml::as_yaml::node

Definition at line 429 of file emit.hpp.

Referenced by c4::yml::operator<<().

◆ options [2/2]

EmitOptions c4::yml::as_yaml::options

Definition at line 430 of file emit.hpp.

Referenced by c4::yml::operator<<().