rapidyaml  0.8.0
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 35 of file writer.hpp.

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

◆ _get() [1/3]

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

Definition at line 37 of file writer.hpp.

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

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 46 of file writer.hpp.

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

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 52 of file writer.hpp.

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

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 62 of file writer.hpp.

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

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 68 of file writer.hpp.

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

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 87 of file writer.hpp.

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

◆ _get() [2/3]

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

Definition at line 89 of file writer.hpp.

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

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 98 of file writer.hpp.

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

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 104 of file writer.hpp.

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

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 114 of file writer.hpp.

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

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 120 of file writer.hpp.

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

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 138 of file writer.hpp.

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

◆ _get() [3/3]

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

Definition at line 140 of file writer.hpp.

141  {
142  if(m_pos <= m_buf.len)
143  return m_buf.first(m_pos);
144  else if(error_on_excess)
145  c4::yml::error("not enough space in the given buffer");
146  substr sp;
147  sp.str = nullptr;
148  sp.len = m_pos;
149  return sp;
150  }
void error(Callbacks const &cb, const char *msg, size_t msg_len, Location loc)
Definition: common.cpp:130

References c4::yml::error(), 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 153 of file writer.hpp.

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

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 161 of file writer.hpp.

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

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 171 of file writer.hpp.

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

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 178 of file writer.hpp.

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

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 32 of file writer.hpp.

Referenced by c4::yml::WriterFile::_do_write().

◆ m_pos [1/3]

size_t c4::yml::WriterFile::m_pos

Definition at line 33 of file writer.hpp.

Referenced by c4::yml::WriterFile::_do_write(), and c4::yml::WriterFile::_get().

◆ m_stream

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

Definition at line 84 of file writer.hpp.

Referenced by c4::yml::WriterOStream< OStream >::_do_write().

◆ m_pos [2/3]

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

◆ m_buf

substr c4::yml::WriterBuf::m_buf

Definition at line 135 of file writer.hpp.

Referenced by c4::yml::WriterBuf::_do_write(), and c4::yml::WriterBuf::_get().

◆ m_pos [3/3]

size_t c4::yml::WriterBuf::m_pos

Definition at line 136 of file writer.hpp.

Referenced by c4::yml::WriterBuf::_do_write(), and c4::yml::WriterBuf::_get().