rapidyaml  0.9.0
parse and emit YAML, and do it fast
Emit to resizeable container

Functions

template<class CharOwningContainer >
substr c4::yml::emitrs_yaml (Tree const &t, id_type id, EmitOptions const &opts, CharOwningContainer *cont, bool append=false)
 (1) emit+resize: emit YAML to the given std::string/std::vector-like container, resizing it as needed to fit the emitted YAML. More...
 
template<class CharOwningContainer >
substr c4::yml::emitrs_yaml (Tree const &t, id_type id, CharOwningContainer *cont, bool append=false)
 (2) like (1), but use default emit options More...
 
template<class CharOwningContainer >
substr c4::yml::emitrs_json (Tree const &t, id_type id, EmitOptions const &opts, CharOwningContainer *cont, bool append=false)
 (1) emit+resize: emit JSON to the given std::string/std::vector-like container, resizing it as needed to fit the emitted JSON. More...
 
template<class CharOwningContainer >
substr c4::yml::emitrs_json (Tree const &t, id_type id, CharOwningContainer *cont, bool append=false)
 (2) like (1), but use default emit options More...
 
template<class CharOwningContainer >
CharOwningContainer c4::yml::emitrs_yaml (Tree const &t, id_type id, EmitOptions const &opts={})
 (3) emit+resize: YAML to a newly-created std::string/std::vector-like container. More...
 
template<class CharOwningContainer >
CharOwningContainer c4::yml::emitrs_json (Tree const &t, id_type id, EmitOptions const &opts={})
 (3) emit+resize: JSON to a newly-created std::string/std::vector-like container. More...
 
template<class CharOwningContainer >
substr c4::yml::emitrs_yaml (Tree const &t, EmitOptions const &opts, CharOwningContainer *cont, bool append=false)
 (1) emit+resize: YAML to the given std::string/std::vector-like container, resizing it as needed to fit the emitted YAML. More...
 
template<class CharOwningContainer >
substr c4::yml::emitrs_yaml (Tree const &t, CharOwningContainer *cont, bool append=false)
 (2) like (1), but use default emit options More...
 
template<class CharOwningContainer >
substr c4::yml::emitrs_json (Tree const &t, EmitOptions const &opts, CharOwningContainer *cont, bool append=false)
 (1) emit+resize: JSON to the given std::string/std::vector-like container, resizing it as needed to fit the emitted JSON. More...
 
template<class CharOwningContainer >
substr c4::yml::emitrs_json (Tree const &t, CharOwningContainer *cont, bool append=false)
 (2) like (1), but use default emit options More...
 
template<class CharOwningContainer >
CharOwningContainer c4::yml::emitrs_yaml (Tree const &t, EmitOptions const &opts={})
 (3) emit+resize: YAML to a newly-created std::string/std::vector-like container. More...
 
template<class CharOwningContainer >
CharOwningContainer c4::yml::emitrs_json (Tree const &t, EmitOptions const &opts={})
 (3) emit+resize: JSON to a newly-created std::string/std::vector-like container. More...
 
template<class CharOwningContainer >
substr c4::yml::emitrs_yaml (ConstNodeRef const &n, EmitOptions const &opts, CharOwningContainer *cont, bool append=false)
 (1) emit+resize: YAML to the given std::string/std::vector-like container, resizing it as needed to fit the emitted YAML. More...
 
template<class CharOwningContainer >
substr c4::yml::emitrs_yaml (ConstNodeRef const &n, CharOwningContainer *cont, bool append=false)
 (2) like (1), but use default emit options More...
 
template<class CharOwningContainer >
substr c4::yml::emitrs_json (ConstNodeRef const &n, EmitOptions const &opts, CharOwningContainer *cont, bool append=false)
 (1) emit+resize: JSON to the given std::string/std::vector-like container, resizing it as needed to fit the emitted JSON. More...
 
template<class CharOwningContainer >
substr c4::yml::emitrs_json (ConstNodeRef const &n, CharOwningContainer *cont, bool append=false)
 (2) like (1), but use default emit options More...
 
template<class CharOwningContainer >
CharOwningContainer c4::yml::emitrs_yaml (ConstNodeRef const &n, EmitOptions const &opts={})
 (3) emit+resize: YAML to a newly-created std::string/std::vector-like container. More...
 
template<class CharOwningContainer >
CharOwningContainer c4::yml::emitrs_json (ConstNodeRef const &n, EmitOptions const &opts={})
 (3) emit+resize: JSON to a newly-created std::string/std::vector-like container. More...
 

Detailed Description

Function Documentation

◆ emitrs_yaml() [1/9]

template<class CharOwningContainer >
substr c4::yml::emitrs_yaml ( Tree const &  t,
id_type  id,
EmitOptions const &  opts,
CharOwningContainer *  cont,
bool  append = false 
)

(1) emit+resize: emit YAML to the given std::string/std::vector-like container, resizing it as needed to fit the emitted YAML.

If append is set to true, the emitted YAML is appended at the end of the container.

Returns
a substr trimmed to the emitted YAML (excluding the initial contents, when appending)

Definition at line 606 of file emit.hpp.

607 {
608  size_t startpos = append ? cont->size() : 0u;
609  cont->resize(cont->capacity()); // otherwise the first emit would be certain to fail
610  substr buf = to_substr(*cont).sub(startpos);
611  substr ret = emit_yaml(t, id, opts, buf, /*error_on_excess*/false);
612  if(ret.str == nullptr && ret.len > 0)
613  {
614  cont->resize(startpos + ret.len);
615  buf = to_substr(*cont).sub(startpos);
616  ret = emit_yaml(t, id, opts, buf, /*error_on_excess*/true);
617  }
618  else
619  {
620  cont->resize(startpos + ret.len);
621  }
622  return ret;
623 }
substr emit_yaml(ConstNodeRef const &r, substr buf, bool error_on_excess=true)
(2) like (1), but use default emit options
Definition: emit.hpp:559
substr to_substr(substr s) noexcept
neutral version for use in generic code
Definition: substr.hpp:2184

References c4::yml::emit_yaml(), and c4::to_substr().

Referenced by sample::sample_emit_to_container().

◆ emitrs_yaml() [2/9]

template<class CharOwningContainer >
substr c4::yml::emitrs_yaml ( Tree const &  t,
id_type  id,
CharOwningContainer *  cont,
bool  append = false 
)

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

Definition at line 626 of file emit.hpp.

627 {
628  return emitrs_yaml(t, id, EmitOptions{}, cont, append);
629 }
CharOwningContainer emitrs_yaml(ConstNodeRef const &n, EmitOptions const &opts={})
(3) emit+resize: YAML to a newly-created std::string/std::vector-like container.
Definition: emit.hpp:790

References c4::yml::emitrs_yaml().

◆ emitrs_json() [1/9]

template<class CharOwningContainer >
substr c4::yml::emitrs_json ( Tree const &  t,
id_type  id,
EmitOptions const &  opts,
CharOwningContainer *  cont,
bool  append = false 
)

(1) emit+resize: emit JSON to the given std::string/std::vector-like container, resizing it as needed to fit the emitted JSON.

If append is set to true, the emitted YAML is appended at the end of the container.

Returns
a substr trimmed to the emitted JSON (excluding the initial contents, when appending)

Definition at line 636 of file emit.hpp.

637 {
638  const size_t startpos = append ? cont->size() : 0u;
639  cont->resize(cont->capacity()); // otherwise the first emit would be certain to fail
640  substr buf = to_substr(*cont).sub(startpos);
641  EmitterBuf em(opts, buf);
642  substr ret = emit_json(t, id, opts, buf, /*error_on_excess*/false);
643  if(ret.str == nullptr && ret.len > 0)
644  {
645  cont->resize(startpos + ret.len);
646  buf = to_substr(*cont).sub(startpos);
647  ret = emit_json(t, id, opts, buf, /*error_on_excess*/true);
648  }
649  else
650  {
651  cont->resize(startpos + ret.len);
652  }
653  return ret;
654 }
substr emit_json(ConstNodeRef const &r, substr buf, bool error_on_excess=true)
(2) like (1), but use default emit options
Definition: emit.hpp:582
Emitter< WriterBuf > EmitterBuf
Definition: emit.hpp:39

References c4::yml::emit_json(), and c4::to_substr().

◆ emitrs_json() [2/9]

template<class CharOwningContainer >
substr c4::yml::emitrs_json ( Tree const &  t,
id_type  id,
CharOwningContainer *  cont,
bool  append = false 
)

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

Definition at line 657 of file emit.hpp.

658 {
659  return emitrs_json(t, id, EmitOptions{}, cont, append);
660 }
CharOwningContainer emitrs_json(ConstNodeRef const &n, EmitOptions const &opts={})
(3) emit+resize: JSON to a newly-created std::string/std::vector-like container.
Definition: emit.hpp:801

References c4::yml::emitrs_json().

◆ emitrs_yaml() [3/9]

template<class CharOwningContainer >
CharOwningContainer c4::yml::emitrs_yaml ( Tree const &  t,
id_type  id,
EmitOptions const &  opts = {} 
)

(3) emit+resize: YAML to a newly-created std::string/std::vector-like container.

Definition at line 665 of file emit.hpp.

665  {})
666 {
667  CharOwningContainer c;
668  emitrs_yaml(t, id, opts, &c);
669  return c;
670 }

◆ emitrs_json() [3/9]

template<class CharOwningContainer >
CharOwningContainer c4::yml::emitrs_json ( Tree const &  t,
id_type  id,
EmitOptions const &  opts = {} 
)

(3) emit+resize: JSON to a newly-created std::string/std::vector-like container.

Definition at line 673 of file emit.hpp.

673  {})
674 {
675  CharOwningContainer c;
676  emitrs_json(t, id, opts, &c);
677  return c;
678 }

◆ emitrs_yaml() [4/9]

template<class CharOwningContainer >
substr c4::yml::emitrs_yaml ( Tree const &  t,
EmitOptions const &  opts,
CharOwningContainer *  cont,
bool  append = false 
)

(1) emit+resize: YAML to the given std::string/std::vector-like container, resizing it as needed to fit the emitted YAML.

Returns
a substr trimmed to the new emitted contents.

Definition at line 687 of file emit.hpp.

688 {
689  if(t.empty())
690  return {};
691  return emitrs_yaml(t, t.root_id(), opts, cont, append);
692 }

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

◆ emitrs_yaml() [5/9]

template<class CharOwningContainer >
substr c4::yml::emitrs_yaml ( Tree const &  t,
CharOwningContainer *  cont,
bool  append = false 
)

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

Definition at line 695 of file emit.hpp.

696 {
697  if(t.empty())
698  return {};
699  return emitrs_yaml(t, t.root_id(), EmitOptions{}, cont, append);
700 }

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

◆ emitrs_json() [4/9]

template<class CharOwningContainer >
substr c4::yml::emitrs_json ( Tree const &  t,
EmitOptions const &  opts,
CharOwningContainer *  cont,
bool  append = false 
)

(1) emit+resize: JSON to the given std::string/std::vector-like container, resizing it as needed to fit the emitted JSON.

Returns
a substr trimmed to the new emitted contents.

Definition at line 705 of file emit.hpp.

706 {
707  if(t.empty())
708  return {};
709  return emitrs_json(t, t.root_id(), opts, cont, append);
710 }

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

◆ emitrs_json() [5/9]

template<class CharOwningContainer >
substr c4::yml::emitrs_json ( Tree const &  t,
CharOwningContainer *  cont,
bool  append = false 
)

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

Definition at line 713 of file emit.hpp.

714 {
715  if(t.empty())
716  return {};
717  return emitrs_json(t, t.root_id(), EmitOptions{}, cont, append);
718 }

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

◆ emitrs_yaml() [6/9]

template<class CharOwningContainer >
CharOwningContainer c4::yml::emitrs_yaml ( Tree const &  t,
EmitOptions const &  opts = {} 
)

(3) emit+resize: YAML to a newly-created std::string/std::vector-like container.

Definition at line 723 of file emit.hpp.

723  {})
724 {
725  CharOwningContainer c;
726  if(t.empty())
727  return c;
728  emitrs_yaml(t, t.root_id(), opts, &c);
729  return c;
730 }

◆ emitrs_json() [6/9]

template<class CharOwningContainer >
CharOwningContainer c4::yml::emitrs_json ( Tree const &  t,
EmitOptions const &  opts = {} 
)

(3) emit+resize: JSON to a newly-created std::string/std::vector-like container.

Definition at line 733 of file emit.hpp.

733  {})
734 {
735  CharOwningContainer c;
736  if(t.empty())
737  return c;
738  emitrs_json(t, t.root_id(), opts, &c);
739  return c;
740 }

◆ emitrs_yaml() [7/9]

template<class CharOwningContainer >
substr c4::yml::emitrs_yaml ( ConstNodeRef const &  n,
EmitOptions const &  opts,
CharOwningContainer *  cont,
bool  append = false 
)

(1) emit+resize: YAML to the given std::string/std::vector-like container, resizing it as needed to fit the emitted YAML.

Returns
a substr trimmed to the new emitted contents

Definition at line 750 of file emit.hpp.

751 {
752  if(!detail::is_set_(n))
753  return {};
754  _RYML_CB_CHECK(n.tree()->callbacks(), n.readable());
755  return emitrs_yaml(*n.tree(), n.id(), opts, cont, append);
756 }
bool is_set_(ConstNodeRef n)
Definition: emit.hpp:42

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

◆ emitrs_yaml() [8/9]

template<class CharOwningContainer >
substr c4::yml::emitrs_yaml ( ConstNodeRef const &  n,
CharOwningContainer *  cont,
bool  append = false 
)

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

Definition at line 759 of file emit.hpp.

760 {
761  if(!detail::is_set_(n))
762  return {};
763  _RYML_CB_CHECK(n.tree()->callbacks(), n.readable());
764  return emitrs_yaml(*n.tree(), n.id(), EmitOptions{}, cont, append);
765 }

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

◆ emitrs_json() [7/9]

template<class CharOwningContainer >
substr c4::yml::emitrs_json ( ConstNodeRef const &  n,
EmitOptions const &  opts,
CharOwningContainer *  cont,
bool  append = false 
)

(1) emit+resize: JSON to the given std::string/std::vector-like container, resizing it as needed to fit the emitted JSON.

Returns
a substr trimmed to the new emitted contents

Definition at line 770 of file emit.hpp.

771 {
772  if(!detail::is_set_(n))
773  return {};
774  _RYML_CB_CHECK(n.tree()->callbacks(), n.readable());
775  return emitrs_json(*n.tree(), n.id(), opts, cont, append);
776 }

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

◆ emitrs_json() [8/9]

template<class CharOwningContainer >
substr c4::yml::emitrs_json ( ConstNodeRef const &  n,
CharOwningContainer *  cont,
bool  append = false 
)

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

Definition at line 779 of file emit.hpp.

780 {
781  if(!detail::is_set_(n))
782  return {};
783  _RYML_CB_CHECK(n.tree()->callbacks(), n.readable());
784  return emitrs_json(*n.tree(), n.id(), EmitOptions{}, cont, append);
785 }

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

◆ emitrs_yaml() [9/9]

template<class CharOwningContainer >
CharOwningContainer c4::yml::emitrs_yaml ( ConstNodeRef const &  n,
EmitOptions const &  opts = {} 
)

(3) emit+resize: YAML to a newly-created std::string/std::vector-like container.

Definition at line 790 of file emit.hpp.

790  {})
791 {
792  if(!detail::is_set_(n))
793  return {};
794  _RYML_CB_CHECK(n.tree()->callbacks(), n.readable());
795  CharOwningContainer c;
796  emitrs_yaml(*n.tree(), n.id(), opts, &c);
797  return c;
798 }

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

◆ emitrs_json() [9/9]

template<class CharOwningContainer >
CharOwningContainer c4::yml::emitrs_json ( ConstNodeRef const &  n,
EmitOptions const &  opts = {} 
)

(3) emit+resize: JSON to a newly-created std::string/std::vector-like container.

Definition at line 801 of file emit.hpp.

801  {})
802 {
803  if(!detail::is_set_(n))
804  return {};
805  _RYML_CB_CHECK(n.tree()->callbacks(), n.readable());
806  CharOwningContainer c;
807  emitrs_json(*n.tree(), n.id(), opts, &c);
808  return c;
809 }

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