rapidyaml  0.7.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 619 of file emit.hpp.

620 {
621  size_t startpos = append ? cont->size() : 0u;
622  cont->resize(cont->capacity()); // otherwise the first emit would be certain to fail
623  substr buf = to_substr(*cont).sub(startpos);
624  substr ret = emit_yaml(t, id, opts, buf, /*error_on_excess*/false);
625  if(ret.str == nullptr && ret.len > 0)
626  {
627  cont->resize(startpos + ret.len);
628  buf = to_substr(*cont).sub(startpos);
629  ret = emit_yaml(t, id, opts, buf, /*error_on_excess*/true);
630  }
631  else
632  {
633  cont->resize(startpos + ret.len);
634  }
635  return ret;
636 }
substr emit_yaml(ConstNodeRef const &r, substr buf, bool error_on_excess=true)
(2) like (1), but use default emit options
Definition: emit.hpp:572
substr to_substr(substr s) noexcept
neutral version for use in generic code
Definition: substr.hpp:2187

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 639 of file emit.hpp.

640 {
641  return emitrs_yaml(t, id, EmitOptions{}, cont, append);
642 }
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:803

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 649 of file emit.hpp.

650 {
651  const size_t startpos = append ? cont->size() : 0u;
652  cont->resize(cont->capacity()); // otherwise the first emit would be certain to fail
653  substr buf = to_substr(*cont).sub(startpos);
654  EmitterBuf em(opts, buf);
655  substr ret = emit_json(t, id, opts, buf, /*error_on_excess*/false);
656  if(ret.str == nullptr && ret.len > 0)
657  {
658  cont->resize(startpos + ret.len);
659  buf = to_substr(*cont).sub(startpos);
660  ret = emit_json(t, id, opts, buf, /*error_on_excess*/true);
661  }
662  else
663  {
664  cont->resize(startpos + ret.len);
665  }
666  return ret;
667 }
substr emit_json(ConstNodeRef const &r, substr buf, bool error_on_excess=true)
(2) like (1), but use default emit options
Definition: emit.hpp:595
Emitter< WriterBuf > EmitterBuf
Definition: emit.hpp:52

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 670 of file emit.hpp.

671 {
672  return emitrs_json(t, id, EmitOptions{}, cont, append);
673 }
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:814

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 678 of file emit.hpp.

678  {})
679 {
680  CharOwningContainer c;
681  emitrs_yaml(t, id, opts, &c);
682  return c;
683 }

◆ 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 686 of file emit.hpp.

686  {})
687 {
688  CharOwningContainer c;
689  emitrs_json(t, id, opts, &c);
690  return c;
691 }

◆ 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 700 of file emit.hpp.

701 {
702  if(t.empty())
703  return {};
704  return emitrs_yaml(t, t.root_id(), opts, cont, append);
705 }

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 708 of file emit.hpp.

709 {
710  if(t.empty())
711  return {};
712  return emitrs_yaml(t, t.root_id(), EmitOptions{}, cont, append);
713 }

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 718 of file emit.hpp.

719 {
720  if(t.empty())
721  return {};
722  return emitrs_json(t, t.root_id(), opts, cont, append);
723 }

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 726 of file emit.hpp.

727 {
728  if(t.empty())
729  return {};
730  return emitrs_json(t, t.root_id(), EmitOptions{}, cont, append);
731 }

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 736 of file emit.hpp.

736  {})
737 {
738  CharOwningContainer c;
739  if(t.empty())
740  return c;
741  emitrs_yaml(t, t.root_id(), opts, &c);
742  return c;
743 }

◆ 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 746 of file emit.hpp.

746  {})
747 {
748  CharOwningContainer c;
749  if(t.empty())
750  return c;
751  emitrs_json(t, t.root_id(), opts, &c);
752  return c;
753 }

◆ 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 763 of file emit.hpp.

764 {
765  if(!detail::is_set_(n))
766  return {};
767  _RYML_CB_CHECK(n.tree()->callbacks(), n.readable());
768  return emitrs_yaml(*n.tree(), n.id(), opts, cont, append);
769 }
bool is_set_(ConstNodeRef n)
Definition: emit.hpp:55

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 772 of file emit.hpp.

773 {
774  if(!detail::is_set_(n))
775  return {};
776  _RYML_CB_CHECK(n.tree()->callbacks(), n.readable());
777  return emitrs_yaml(*n.tree(), n.id(), EmitOptions{}, cont, append);
778 }

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 783 of file emit.hpp.

784 {
785  if(!detail::is_set_(n))
786  return {};
787  _RYML_CB_CHECK(n.tree()->callbacks(), n.readable());
788  return emitrs_json(*n.tree(), n.id(), opts, cont, append);
789 }

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 792 of file emit.hpp.

793 {
794  if(!detail::is_set_(n))
795  return {};
796  _RYML_CB_CHECK(n.tree()->callbacks(), n.readable());
797  return emitrs_json(*n.tree(), n.id(), EmitOptions{}, cont, append);
798 }

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 803 of file emit.hpp.

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

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 814 of file emit.hpp.

814  {})
815 {
816  if(!detail::is_set_(n))
817  return {};
818  _RYML_CB_CHECK(n.tree()->callbacks(), n.readable());
819  CharOwningContainer c;
820  emitrs_json(*n.tree(), n.id(), opts, &c);
821  return c;
822 }

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