rapidyaml  0.16.0
parseandemitYAML,anddoitfast
writer_ostream.hpp
Go to the documentation of this file.
1 #ifndef C4_YML_WRITER_OSTREAM_HPP_
2 #define C4_YML_WRITER_OSTREAM_HPP_
3 
4 /** @file writer_ostream.hpp */
5 
6 #ifndef C4_YML_ERROR_HPP_
7 #include "c4/yml/error.hpp"
8 #endif
9 
10 namespace c4 {
11 namespace yml {
12 
13 /** A writer that outputs to an STL-like ostream.
14  *
15  * @ingroup doc_writers
16  * @ingroup doc_emit_to_ostream
17  */
18 template<class OStream>
20 {
21  OStream* m_stream;
22 
23  WriterOStream(OStream *s) noexcept : m_stream(s) {}
24 
25  template<size_t N>
26  C4_ALWAYS_INLINE void append(const char (&a)[N]) noexcept
27  {
28  static_assert(N > 1, "empty string");
29  m_stream->write(a, N - 1);
30  }
31 
32  C4_ALWAYS_INLINE void append(csubstr s) noexcept
33  {
34  if(s.len)
35  {
36  C4_SUPPRESS_WARNING_GCC_CLANG_WITH_PUSH("-Wsign-conversion")
37  m_stream->write(s.str, s.len);
38  C4_SUPPRESS_WARNING_GCC_CLANG_POP
39  }
40  }
41 
42  C4_ALWAYS_INLINE void append(const char c) noexcept
43  {
44  m_stream->put(c);
45  }
46 
47  C4_ALWAYS_INLINE void append(const char c, size_t num_times) noexcept
48  {
49  for(size_t i = 0; i < num_times; ++i)
50  m_stream->put(c);
51  }
52 };
53 
54 } // namespace yml
55 } // namespace c4
56 
57 #endif /* C4_YML_WRITER_OSTREAM_HPP_ */
A writer that outputs to an STL-like ostream.
void append(const char c, size_t num_times) noexcept
WriterOStream(OStream *s) noexcept
void append(const char(&a)[N]) noexcept
void append(csubstr s) noexcept
Error utilities used by ryml.
void append(const char c) noexcept