rapidyaml 0.15.2
parse and emit YAML, and do it fast
Loading...
Searching...
No Matches
writer_file.hpp
Go to the documentation of this file.
1#ifndef _C4_YML_WRITER_FILE_HPP_
2#define _C4_YML_WRITER_FILE_HPP_
3
4/** @file writer_file.hpp */
5
6#ifndef _C4_YML_ERROR_HPP_
7#include "c4/yml/error.hpp"
8#endif
9
10#include <stdio.h> // fwrite(), fputc()
11
12namespace c4 {
13namespace yml {
14
15/** A writer that outputs to a C file handle, defaulting to
16 * stdout. This writer is *much* faster than @ref WriterOStream and
17 * should be preferred to it.
18 * @ingroup doc_writers
19 * @ingroup doc_emit_to_file
20 */
22{
23 FILE * m_file;
24
25 WriterFile(FILE *f = nullptr) noexcept : m_file(f ? f : stdout) {}
26
27 template<size_t N>
28 C4_ALWAYS_INLINE void append(const char (&a)[N]) noexcept // NOLINT(*-make-member-function-const)
29 {
30 static_assert(N > 1, "empty string");
31 (void)fwrite(a, sizeof(char), N - 1, m_file);
32 }
33
34 C4_ALWAYS_INLINE void append(csubstr s) noexcept // NOLINT(*-make-member-function-const)
35 {
36 if(s.len)
37 {
38 C4_SUPPRESS_WARNING_GCC_CLANG_WITH_PUSH("-Wsign-conversion")
39 (void)fwrite(s.str, sizeof(csubstr::char_type), s.len, m_file);
40 C4_SUPPRESS_WARNING_GCC_CLANG_POP
41 }
42 }
43
44 C4_ALWAYS_INLINE void append(const char c) noexcept // NOLINT(*-make-member-function-const)
45 {
46 (void)fputc(c, m_file);
47 }
48
49 C4_ALWAYS_INLINE void append(const char c, size_t num_times) noexcept // NOLINT(*-make-member-function-const)
50 {
51 for(size_t i = 0; i < num_times; ++i)
52 (void)fputc(c, m_file);
53 }
54};
55
56} // namespace yml
57} // namespace c4
58
59#endif /* _C4_YML_WRITER_FILE_HPP_ */
Error utilities used by ryml.
#define RYML_EXPORT
Definition export.hpp:18
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(csubstr s) noexcept
void append(const char c) noexcept
WriterFile(FILE *f=nullptr) noexcept
void append(const char c, size_t num_times) noexcept
void append(const char(&a)[N]) noexcept