rapidyaml  0.16.0
parseandemitYAML,anddoitfast
emit.hpp
Go to the documentation of this file.
1 #ifndef C4_YML_EMIT_HPP_
2 #define C4_YML_EMIT_HPP_
3 
4 /** @file emit.hpp Umbrella header with all utilities to emit YAML and JSON. */
5 
6 
7 #ifndef C4_YML_EMIT_BUF_HPP_
8 #include "c4/yml/emit_buf.hpp"
9 #endif
10 #ifndef C4_YML_EMIT_CONTAINER_HPP_
12 #endif
13 #ifndef C4_YML_EMIT_FILE_HPP_
14 #include "c4/yml/emit_file.hpp"
15 #endif
16 #ifndef C4_YML_EMIT_OSTREAM_HPP_
17 #include "c4/yml/emit_ostream.hpp"
18 #endif
19 
20 
21 namespace c4 {
22 namespace yml {
23 
24 
25 //-------------------------------------------------
26 // deprecated code
27 
28 /** @cond dev */ // LCOV_EXCL_START
29 
30 #define RYML_DEPRECATE_EMIT \
31  RYML_DEPRECATED("use emit_yaml() instead. " \
32  "See https://github.com/biojppm/rapidyaml/issues/120")
33 #define RYML_DEPRECATE_EMITRS \
34  RYML_DEPRECATED("use emitrs_yaml() instead. " \
35  "See https://github.com/biojppm/rapidyaml/issues/120")
36 
37 // workaround for Qt emit which is a macro;
38 // see https://github.com/biojppm/rapidyaml/issues/120.
39 // emit is defined in qobjectdefs.h (as an empty define).
40 #ifdef emit
41 #define RYML_TMP_EMIT_ emit
42 #undef emit
43 #endif
44 
45 RYML_DEPRECATE_EMIT inline void emit(Tree const& t, id_type id, FILE *f)
46 {
47  emit_yaml(t, id, f);
48 }
49 RYML_DEPRECATE_EMIT inline void emit(Tree const& t, FILE *f=nullptr)
50 {
51  emit_yaml(t, f);
52 }
53 RYML_DEPRECATE_EMIT inline void emit(ConstNodeRef const& r, FILE *f=nullptr)
54 {
55  emit_yaml(r, f);
56 }
57 
58 RYML_DEPRECATE_EMIT inline substr emit(Tree const& t, id_type id, substr buf, bool error_on_excess=true)
59 {
60  return emit_yaml(t, id, buf, error_on_excess);
61 }
62 RYML_DEPRECATE_EMIT inline substr emit(Tree const& t, substr buf, bool error_on_excess=true)
63 {
64  return emit_yaml(t, buf, error_on_excess);
65 }
66 RYML_DEPRECATE_EMIT inline substr emit(ConstNodeRef const& r, substr buf, bool error_on_excess=true)
67 {
68  return emit_yaml(r, buf, error_on_excess);
69 }
70 
71 #ifdef RYML_TMP_EMIT_
72 #define emit RYML_TMP_EMIT_
73 #undef RYML_TMP_EMIT_
74 #endif
75 
76 template<class CharOwningContainer>
77 RYML_DEPRECATE_EMITRS substr emitrs(Tree const& t, id_type id, CharOwningContainer * cont)
78 {
79  return emitrs_yaml(t, id, cont);
80 }
81 template<class CharOwningContainer>
82 RYML_DEPRECATE_EMITRS CharOwningContainer emitrs(Tree const& t, id_type id)
83 {
84  return emitrs_yaml<CharOwningContainer>(t, id);
85 }
86 template<class CharOwningContainer>
87 RYML_DEPRECATE_EMITRS substr emitrs(Tree const& t, CharOwningContainer * cont)
88 {
89  return emitrs_yaml(t, cont);
90 }
91 template<class CharOwningContainer>
92 RYML_DEPRECATE_EMITRS CharOwningContainer emitrs(Tree const& t)
93 {
94  return emitrs_yaml<CharOwningContainer>(t);
95 }
96 template<class CharOwningContainer>
97 RYML_DEPRECATE_EMITRS substr emitrs(ConstNodeRef const& n, CharOwningContainer * cont)
98 {
99  return emitrs_yaml(n, cont);
100 }
101 template<class CharOwningContainer>
102 RYML_DEPRECATE_EMITRS CharOwningContainer emitrs(ConstNodeRef const& n)
103 {
104  return emitrs_yaml<CharOwningContainer>(n);
105 }
106 
107 #undef RYML_DEPRECATE_EMIT
108 #undef RYML_DEPRECATE_EMITRS
109 
110 /** @endcond */ // LCOV_EXCL_STOP
111 
112 
113 } // namespace yml
114 } // namespace c4
115 
116 #endif /* C4_YML_EMIT_HPP_ */
substr 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.
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...
Definition: common.hpp:124
basic_substring< char > substr
a mutable string view
Definition: substr.hpp:2355
Utilities to emit YAML and JSON to buffers or containers.
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
emit to STL-like ostreams