rapidyaml  0.16.0
parseandemitYAML,anddoitfast
Emit from nested node id

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<char>-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<char>-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<char>-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<char>-like container. More...
 

Detailed Description

Function Documentation

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<char>-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 35 of file emit_container.hpp.

Referenced by c4::yml::emitrs_yaml(), and sample_emit_to_container().

36 {
37  const size_t startpos = append ? cont->size() : 0u;
38  cont->resize(cont->capacity()); // otherwise the first emit would be certain to fail
39  substr buf = to_substr(*cont).sub(startpos);
40  substr ret = emit_yaml(t, id, opts, buf, /*error_on_excess*/false);
41  cont->resize(startpos + ret.len);
42  if(ret.len && !ret.str)
43  {
44  buf = to_substr(*cont).sub(startpos);
45  ret = emit_yaml(t, id, opts, buf, /*error_on_excess*/true);
46  }
47  return ret;
48 }
substr to_substr(char(&s)[N]) noexcept
Definition: substr.hpp:2376
basic_substring sub(size_t first) const noexcept
return [first,len[
Definition: substr.hpp:502
basic_substring< char > substr
a mutable string view
Definition: substr.hpp:2355
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
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 51 of file emit_container.hpp.

52 {
53  return emitrs_yaml(t, id, EmitOptions{}, cont, append);
54 }
CharOwningContainer emitrs_yaml(ConstNodeRef const &n, EmitOptions const &opts={})
(3) emit+resize: YAML to a newly-created std::string/std::vector-like container.
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<char>-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 63 of file emit_container.hpp.

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

64 {
65  const size_t startpos = append ? cont->size() : 0u;
66  cont->resize(cont->capacity()); // otherwise the first emit would be certain to fail
67  substr buf = to_substr(*cont).sub(startpos);
68  substr ret = emit_json(t, id, opts, buf, /*error_on_excess*/false);
69  cont->resize(startpos + ret.len);
70  if(ret.len && !ret.str)
71  {
72  buf = to_substr(*cont).sub(startpos);
73  ret = emit_json(t, id, opts, buf, /*error_on_excess*/true);
74  }
75  return ret;
76 }
substr to_substr(char(&s)[N]) noexcept
Definition: substr.hpp:2376
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
basic_substring sub(size_t first) const noexcept
return [first,len[
Definition: substr.hpp:502
basic_substring< char > substr
a mutable string view
Definition: substr.hpp:2355
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 79 of file emit_container.hpp.

80 {
81  return emitrs_json(t, id, EmitOptions{}, cont, append);
82 }
CharOwningContainer emitrs_json(ConstNodeRef const &n, EmitOptions const &opts={})
(3) emit+resize: JSON to a newly-created std::string/std::vector-like container.
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<char>-like container.

Definition at line 87 of file emit_container.hpp.

87  {})
88 {
89  CharOwningContainer c;
90  emitrs_yaml(t, id, opts, &c);
91  return c;
92 }
CharOwningContainer emitrs_yaml(ConstNodeRef const &n, EmitOptions const &opts={})
(3) emit+resize: YAML to a newly-created std::string/std::vector-like container.
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<char>-like container.

Definition at line 95 of file emit_container.hpp.

95  {})
96 {
97  CharOwningContainer c;
98  emitrs_json(t, id, opts, &c);
99  return c;
100 }
CharOwningContainer emitrs_json(ConstNodeRef const &n, EmitOptions const &opts={})
(3) emit+resize: JSON to a newly-created std::string/std::vector-like container.