rapidyaml 0.15.2
parse and emit YAML, and do it fast
Loading...
Searching...
No Matches

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.
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

◆ WriterBuf()

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

◆ get_result()

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 }
basic_substring< char > substr
a mutable string view
Definition substr.hpp:2356
C * str
a restricted pointer to the first character of the substring
Definition substr.hpp:216

◆ append() [1/4]

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 }

◆ append() [2/4]

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 }

◆ append() [3/4]

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 }

◆ append() [4/4]

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 }

Member Data Documentation

◆ m_buf

substr c4::yml::WriterBuf::m_buf

Definition at line 22 of file writer_buf.hpp.

◆ m_pos

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:
  • /home/docs/checkouts/readthedocs.org/user_builds/rapidyaml/checkouts/latest/src/c4/yml/writer_buf.hpp