rapidyaml 0.15.2
parse and emit YAML, and do it fast
Loading...
Searching...
No Matches
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
10namespace c4 {
11namespace yml {
12
13/** A writer that outputs to an STL-like ostream.
14 *
15 * @ingroup doc_writers
16 * @ingroup doc_emit_to_ostream
17 */
18template<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_ */
Error utilities used by ryml.
basic_substring< const char > csubstr
an immutable string view
Definition substr.hpp:2357
(Undefined by default) Use shorter error message from checks/asserts: do not show the check condition...
Definition common.cpp:14
void append(const char c, size_t num_times) noexcept
void append(csubstr s) noexcept
void append(const char(&a)[N]) noexcept
void append(const char c) noexcept
WriterOStream(OStream *s) noexcept