rapidyaml  0.11.1
parse and emit YAML, and do it fast
Writer objects to use with an Emitter

Classes

struct  c4::yml::WriterFile
 A writer that outputs to a file. More...
 
struct  c4::yml::WriterOStream< OStream >
 A writer that outputs to an STL-like ostream. More...
 
struct  c4::yml::WriterBuf
 a writer to a substr More...
 

Functions

 c4::yml::WriterFile::WriterFile (FILE *f=nullptr)
 
substr c4::yml::WriterFile::_get (bool) const
 
template<size_t N>
void c4::yml::WriterFile::_do_write (const char(&a)[N])
 
void c4::yml::WriterFile::_do_write (csubstr sp)
 
void c4::yml::WriterFile::_do_write (const char c)
 
void c4::yml::WriterFile::_do_write (const char c, size_t num_times)
 
 c4::yml::WriterOStream< OStream >::WriterOStream (OStream &s)
 
substr c4::yml::WriterOStream< OStream >::_get (bool) const
 
template<size_t N>
void c4::yml::WriterOStream< OStream >::_do_write (const char(&a)[N])
 
void c4::yml::WriterOStream< OStream >::_do_write (csubstr sp)
 
void c4::yml::WriterOStream< OStream >::_do_write (const char c)
 
void c4::yml::WriterOStream< OStream >::_do_write (const char c, size_t num_times)
 
 c4::yml::WriterBuf::WriterBuf (substr sp)
 
substr c4::yml::WriterBuf::_get (bool error_on_excess) const
 
template<size_t N>
void c4::yml::WriterBuf::_do_write (const char(&a)[N])
 
void c4::yml::WriterBuf::_do_write (csubstr sp)
 
void c4::yml::WriterBuf::_do_write (const char c)
 
void c4::yml::WriterBuf::_do_write (const char c, size_t num_times)
 

Variables

FILE * c4::yml::WriterFile::m_file
 
size_t c4::yml::WriterFile::m_pos
 
OStream * c4::yml::WriterOStream< OStream >::m_stream
 
size_t c4::yml::WriterOStream< OStream >::m_pos
 
substr c4::yml::WriterBuf::m_buf
 
size_t c4::yml::WriterBuf::m_pos
 

Detailed Description

See also
Emitter

Function Documentation

◆ WriterFile()

c4::yml::WriterFile::WriterFile ( FILE *  f = nullptr)
inline

Definition at line 34 of file writer.hpp.

34 : m_file(f ? f : stdout), m_pos(0) {}

◆ _get() [1/3]

substr c4::yml::WriterFile::_get ( bool  ) const
inline

Definition at line 36 of file writer.hpp.

37  {
38  substr sp;
39  sp.str = nullptr;
40  sp.len = m_pos;
41  return sp;
42  }

References c4::yml::WriterFile::m_pos.

◆ _do_write() [1/12]

template<size_t N>
void c4::yml::WriterFile::_do_write ( const char(&)  a[N])
inline

Definition at line 45 of file writer.hpp.

46  {
47  (void)fwrite(a, sizeof(char), N - 1, m_file);
48  m_pos += N - 1;
49  }

References c4::yml::WriterFile::m_file, and c4::yml::WriterFile::m_pos.

◆ _do_write() [2/12]

void c4::yml::WriterFile::_do_write ( csubstr  sp)
inline

Definition at line 51 of file writer.hpp.

52  {
53  C4_SUPPRESS_WARNING_GCC_CLANG_WITH_PUSH("-Wsign-conversion")
54  if(sp.empty())
55  return;
56  (void)fwrite(sp.str, sizeof(csubstr::char_type), sp.len, m_file);
57  m_pos += sp.len;
58  C4_SUPPRESS_WARNING_GCC_CLANG_POP
59  }

References c4::yml::WriterFile::m_file, and c4::yml::WriterFile::m_pos.

◆ _do_write() [3/12]

void c4::yml::WriterFile::_do_write ( const char  c)
inline

Definition at line 61 of file writer.hpp.

62  {
63  (void)fputc(c, m_file);
64  ++m_pos;
65  }

References c4::yml::WriterFile::m_file, and c4::yml::WriterFile::m_pos.

◆ _do_write() [4/12]

void c4::yml::WriterFile::_do_write ( const char  c,
size_t  num_times 
)
inline

Definition at line 67 of file writer.hpp.

68  {
69  for(size_t i = 0; i < num_times; ++i)
70  (void)fputc(c, m_file);
71  m_pos += num_times;
72  }

References c4::yml::WriterFile::m_file, and c4::yml::WriterFile::m_pos.

◆ WriterOStream()

template<class OStream >
c4::yml::WriterOStream< OStream >::WriterOStream ( OStream &  s)
inline

Definition at line 86 of file writer.hpp.

86 : m_stream(&s), m_pos(0) {}
OStream * m_stream
Definition: writer.hpp:83

◆ _get() [2/3]

template<class OStream >
substr c4::yml::WriterOStream< OStream >::_get ( bool  ) const
inline

Definition at line 88 of file writer.hpp.

89  {
90  substr sp;
91  sp.str = nullptr;
92  sp.len = m_pos;
93  return sp;
94  }

References c4::yml::WriterOStream< OStream >::m_pos.

◆ _do_write() [5/12]

template<class OStream >
template<size_t N>
void c4::yml::WriterOStream< OStream >::_do_write ( const char(&)  a[N])
inline

Definition at line 97 of file writer.hpp.

98  {
99  m_stream->write(a, N - 1);
100  m_pos += N - 1;
101  }

References c4::yml::WriterOStream< OStream >::m_pos, and c4::yml::WriterOStream< OStream >::m_stream.

◆ _do_write() [6/12]

template<class OStream >
void c4::yml::WriterOStream< OStream >::_do_write ( csubstr  sp)
inline

Definition at line 103 of file writer.hpp.

104  {
105  C4_SUPPRESS_WARNING_GCC_CLANG_WITH_PUSH("-Wsign-conversion")
106  if(sp.empty())
107  return;
108  m_stream->write(sp.str, sp.len);
109  m_pos += sp.len;
110  C4_SUPPRESS_WARNING_GCC_CLANG_POP
111  }
void write(NodeRef *n, T const &v)
Definition: node.hpp:1626

References c4::yml::WriterOStream< OStream >::m_pos, and c4::yml::WriterOStream< OStream >::m_stream.

◆ _do_write() [7/12]

template<class OStream >
void c4::yml::WriterOStream< OStream >::_do_write ( const char  c)
inline

Definition at line 113 of file writer.hpp.

114  {
115  m_stream->put(c);
116  ++m_pos;
117  }

References c4::yml::WriterOStream< OStream >::m_pos, and c4::yml::WriterOStream< OStream >::m_stream.

◆ _do_write() [8/12]

template<class OStream >
void c4::yml::WriterOStream< OStream >::_do_write ( const char  c,
size_t  num_times 
)
inline

Definition at line 119 of file writer.hpp.

120  {
121  for(size_t i = 0; i < num_times; ++i)
122  m_stream->put(c);
123  m_pos += num_times;
124  }

References c4::yml::WriterOStream< OStream >::m_pos, and c4::yml::WriterOStream< OStream >::m_stream.

◆ WriterBuf()

c4::yml::WriterBuf::WriterBuf ( substr  sp)
inline

Definition at line 137 of file writer.hpp.

137 : m_buf(sp), m_pos(0) {}

◆ _get() [3/3]

substr c4::yml::WriterBuf::_get ( bool  error_on_excess) const
inline

Definition at line 139 of file writer.hpp.

140  {
141  if(m_pos <= m_buf.len)
142  return m_buf.first(m_pos);
143  else if(error_on_excess)
144  c4::yml::err_basic(RYML_LOC_HERE(), "not enough space in the given buffer");
145  substr sp;
146  sp.str = nullptr;
147  sp.len = m_pos;
148  return sp;
149  }
void err_basic(ErrorDataBasic const &errdata, const char *msg)
trigger a basic error to its respective handler, with a non-formatted error message.
Definition: common.cpp:196

References c4::yml::err_basic(), c4::yml::WriterBuf::m_buf, and c4::yml::WriterBuf::m_pos.

◆ _do_write() [9/12]

template<size_t N>
void c4::yml::WriterBuf::_do_write ( const char(&)  a[N])
inline

Definition at line 152 of file writer.hpp.

153  {
154  _RYML_ASSERT_BASIC( ! m_buf.overlaps(a));
155  if(m_pos + N-1 <= m_buf.len)
156  memcpy(&(m_buf[m_pos]), a, N-1);
157  m_pos += N-1;
158  }

References c4::yml::WriterBuf::m_buf, and c4::yml::WriterBuf::m_pos.

◆ _do_write() [10/12]

void c4::yml::WriterBuf::_do_write ( csubstr  sp)
inline

Definition at line 160 of file writer.hpp.

161  {
162  if(sp.empty())
163  return;
164  _RYML_ASSERT_BASIC( ! sp.overlaps(m_buf));
165  if(m_pos + sp.len <= m_buf.len)
166  memcpy(&(m_buf[m_pos]), sp.str, sp.len);
167  m_pos += sp.len;
168  }

References c4::yml::WriterBuf::m_buf, and c4::yml::WriterBuf::m_pos.

◆ _do_write() [11/12]

void c4::yml::WriterBuf::_do_write ( const char  c)
inline

Definition at line 170 of file writer.hpp.

171  {
172  if(m_pos + 1 <= m_buf.len)
173  m_buf[m_pos] = c;
174  ++m_pos;
175  }

References c4::yml::WriterBuf::m_buf, and c4::yml::WriterBuf::m_pos.

◆ _do_write() [12/12]

void c4::yml::WriterBuf::_do_write ( const char  c,
size_t  num_times 
)
inline

Definition at line 177 of file writer.hpp.

178  {
179  if(m_pos + num_times <= m_buf.len)
180  for(size_t i = 0; i < num_times; ++i)
181  m_buf[m_pos + i] = c;
182  m_pos += num_times;
183  }

References c4::yml::WriterBuf::m_buf, and c4::yml::WriterBuf::m_pos.

Variable Documentation

◆ m_file

FILE* c4::yml::WriterFile::m_file

Definition at line 31 of file writer.hpp.

◆ m_pos [1/3]

size_t c4::yml::WriterFile::m_pos

Definition at line 32 of file writer.hpp.

◆ m_stream

template<class OStream >
OStream* c4::yml::WriterOStream< OStream >::m_stream

Definition at line 83 of file writer.hpp.

◆ m_pos [2/3]

template<class OStream >
size_t c4::yml::WriterOStream< OStream >::m_pos

Definition at line 84 of file writer.hpp.

◆ m_buf

substr c4::yml::WriterBuf::m_buf

Definition at line 134 of file writer.hpp.

◆ m_pos [3/3]

size_t c4::yml::WriterBuf::m_pos

Definition at line 135 of file writer.hpp.