rapidyaml  0.7.2
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)
 
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)
 
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)
 
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  )
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  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  #if defined(__clang__)
55  # pragma clang diagnostic push
56  # pragma GCC diagnostic ignored "-Wsign-conversion"
57  #elif defined(__GNUC__)
58  # pragma GCC diagnostic push
59  # pragma GCC diagnostic ignored "-Wsign-conversion"
60  #endif
61  if(sp.empty()) return;
62  fwrite(sp.str, sizeof(csubstr::char_type), sp.len, m_file);
63  m_pos += sp.len;
64  #if defined(__clang__)
65  # pragma clang diagnostic pop
66  #elif defined(__GNUC__)
67  # pragma GCC diagnostic pop
68  #endif
69  }

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

72  {
73  fputc(c, m_file);
74  ++m_pos;
75  }

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

78  {
79  for(size_t i = 0; i < num_times; ++i)
80  fputc(c, m_file);
81  m_pos += num_times;
82  }

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

96 : m_stream(s), m_pos(0) {}
OStream & m_stream
Definition: writer.hpp:93

◆ _get() [2/3]

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

Definition at line 98 of file writer.hpp.

99  {
100  substr sp;
101  sp.str = nullptr;
102  sp.len = m_pos;
103  return sp;
104  }

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

108  {
109  m_stream.write(a, N - 1);
110  m_pos += N - 1;
111  }

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

114  {
115  #if defined(__clang__)
116  # pragma clang diagnostic push
117  # pragma GCC diagnostic ignored "-Wsign-conversion"
118  #elif defined(__GNUC__)
119  # pragma GCC diagnostic push
120  # pragma GCC diagnostic ignored "-Wsign-conversion"
121  #endif
122  if(sp.empty()) return;
123  m_stream.write(sp.str, sp.len);
124  m_pos += sp.len;
125  #if defined(__clang__)
126  # pragma clang diagnostic pop
127  #elif defined(__GNUC__)
128  # pragma GCC diagnostic pop
129  #endif
130  }

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

133  {
134  m_stream.put(c);
135  ++m_pos;
136  }

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

139  {
140  for(size_t i = 0; i < num_times; ++i)
141  m_stream.put(c);
142  m_pos += num_times;
143  }

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

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

◆ _get() [3/3]

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

Definition at line 158 of file writer.hpp.

159  {
160  if(m_pos <= m_buf.len)
161  {
162  return m_buf.first(m_pos);
163  }
164  if(error_on_excess)
165  {
166  c4::yml::error("not enough space in the given buffer");
167  }
168  substr sp;
169  sp.str = nullptr;
170  sp.len = m_pos;
171  return sp;
172  }
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 175 of file writer.hpp.

176  {
177  RYML_ASSERT( ! m_buf.overlaps(a));
178  if(m_pos + N-1 <= m_buf.len)
179  {
180  memcpy(&(m_buf[m_pos]), a, N-1);
181  }
182  m_pos += N-1;
183  }

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

186  {
187  if(sp.empty()) return;
188  RYML_ASSERT( ! sp.overlaps(m_buf));
189  if(m_pos + sp.len <= m_buf.len)
190  {
191  memcpy(&(m_buf[m_pos]), sp.str, sp.len);
192  }
193  m_pos += sp.len;
194  }

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

197  {
198  if(m_pos + 1 <= m_buf.len)
199  m_buf[m_pos] = c;
200  ++m_pos;
201  }

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

204  {
205  if(m_pos + num_times <= m_buf.len)
206  for(size_t i = 0; i < num_times; ++i)
207  m_buf[m_pos + i] = c;
208  m_pos += num_times;
209  }

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 93 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 153 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 154 of file writer.hpp.

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