rapidyaml  0.16.0
parseandemitYAML,anddoitfast

A writer to a memory buffer, in the form of a substr . More...

#include <writer_buf.hpp>

Public Member Functions

 WriterBuf (substr sp) noexcept
 
substr get_result (bool error_on_excess) const
 Return the buffer written so far, or optionally throw an error if the buffer was too small. More...
 
template<size_t N>
void append (const char(&a)[N]) noexcept
 
void append (csubstr s) noexcept
 
void append (const char c) noexcept
 
void append (const char c, size_t num_times) noexcept
 

Public Attributes

substr m_buf
 
size_t m_pos
 

Detailed Description

A writer to a memory buffer, in the form of a substr .

No overflow occurs; the buffer size is strictly respected.

Definition at line 20 of file writer_buf.hpp.

Constructor & Destructor Documentation

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

Definition at line 25 of file writer_buf.hpp.

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

Member Function Documentation

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

Return the buffer written so far, or optionally throw an error if the buffer was too small.

Definition at line 31 of file writer_buf.hpp.

32  {
33  if(m_pos <= m_buf.len)
34  {
35  return m_buf.first(m_pos);
36  }
37  else if(!error_on_excess)
38  {
39  substr sp;
40  sp.str = nullptr;
41  sp.len = m_pos;
42  return sp;
43  }
44  else
45  {
46  RYML_ERR_BASIC_("not enough space in the given buffer");
47  }
48  }
C * str
a restricted pointer to the first character of the substring
Definition: substr.hpp:216
basic_substring first(size_t num) const noexcept
return the first num elements: [0,num[
Definition: substr.hpp:529
basic_substring< char > substr
a mutable string view
Definition: substr.hpp:2355
size_t len
the length of the substring
Definition: substr.hpp:218
template<size_t N>
void c4::yml::WriterBuf::append ( const char(&)  a[N])
inlinenoexcept

Definition at line 53 of file writer_buf.hpp.

54  {
55  static_assert(N > 1, "empty string");
56  RYML_ASSERT_BASIC_( ! m_buf.overlaps(a));
57  if(m_pos + N-1 <= m_buf.len)
58  memcpy(m_buf.str + m_pos, a, N-1);
59  m_pos += N-1;
60  }
bool overlaps(ro_substr const that) const noexcept
true if there is overlap of at least one element between that and *this
Definition: substr.hpp:493
C * str
a restricted pointer to the first character of the substring
Definition: substr.hpp:216
size_t len
the length of the substring
Definition: substr.hpp:218
void c4::yml::WriterBuf::append ( csubstr  s)
inlinenoexcept

Definition at line 62 of file writer_buf.hpp.

63  {
64  RYML_ASSERT_BASIC_( ! s.overlaps(m_buf));
65  if(s.len && m_pos + s.len <= m_buf.len)
66  memcpy(m_buf.str + m_pos, s.str, s.len);
67  m_pos += s.len;
68  }
C * str
a restricted pointer to the first character of the substring
Definition: substr.hpp:216
size_t len
the length of the substring
Definition: substr.hpp:218
void c4::yml::WriterBuf::append ( const char  c)
inlinenoexcept

Definition at line 70 of file writer_buf.hpp.

71  {
72  if(m_pos + 1 <= m_buf.len)
73  m_buf.str[m_pos] = c;
74  ++m_pos;
75  }
C * str
a restricted pointer to the first character of the substring
Definition: substr.hpp:216
size_t len
the length of the substring
Definition: substr.hpp:218
void c4::yml::WriterBuf::append ( const char  c,
size_t  num_times 
)
inlinenoexcept

Definition at line 77 of file writer_buf.hpp.

78  {
79  if(m_pos + num_times <= m_buf.len)
80  memset(m_buf.str + m_pos, c, num_times);
81  m_pos += num_times;
82  }
C * str
a restricted pointer to the first character of the substring
Definition: substr.hpp:216
size_t len
the length of the substring
Definition: substr.hpp:218

Member Data Documentation

substr c4::yml::WriterBuf::m_buf

Definition at line 22 of file writer_buf.hpp.

size_t c4::yml::WriterBuf::m_pos

Definition at line 23 of file writer_buf.hpp.


The documentation for this struct was generated from the following file: