Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
yaml_formatter.hpp
Go to the documentation of this file.
1// # This file is a part of toml++ and is subject to the the terms of the MIT license.
2// # Copyright (c) Mark Gillard <mark.gillard@outlook.com.au>
3// # See https://github.com/marzer/tomlplusplus/blob/master/LICENSE for the full license text.
4// SPDX-License-Identifier: MIT
5#pragma once
6
7#include "preprocessor.hpp"
8#if TOML_ENABLE_FORMATTERS
9
10#include "formatter.hpp"
11#include "header_start.hpp"
12
39 class TOML_EXPORTED_CLASS yaml_formatter : impl::formatter {
40 private:
42
43 using base = impl::formatter;
44
46 void print_yaml_string(const value<std::string>&);
47
49 void print(const toml::table&, bool = false);
50
52 void print(const toml::array&, bool = false);
53
55 void print();
56
57 static constexpr impl::formatter_constants constants = {
58 //
59 format_flags::quote_dates_and_times | format_flags::indentation, // mandatory
60 format_flags::allow_multi_line_strings, // ignored
61 ".inf"sv,
62 "-.inf"sv,
63 ".NAN"sv,
64 "true"sv,
65 "false"sv};
66
68
69 public:
71 static constexpr format_flags default_flags = constants.mandatory_flags //
72 | format_flags::allow_literal_strings //
73 | format_flags::allow_unicode_strings //
74 | format_flags::allow_octal_integers //
75 | format_flags::allow_hexadecimal_integers;
76
82 explicit yaml_formatter(const toml::node& source, format_flags flags = default_flags) noexcept
83 : base{&source, nullptr, constants, {flags, " "sv}} {}
84
85#if TOML_DOXYGEN || (TOML_ENABLE_PARSER && !TOML_EXCEPTIONS)
86
111 explicit yaml_formatter(const toml::parse_result& result,
112 format_flags flags = default_flags) noexcept
113 : base{nullptr, &result, constants, {flags, " "sv}} {}
114
115#endif
116
118 friend std::ostream& TOML_CALLCONV operator<<(std::ostream& lhs, yaml_formatter& rhs) {
119 rhs.attach(lhs);
120 rhs.print();
121 rhs.detach();
122 return lhs;
123 }
124
126 friend std::ostream& TOML_CALLCONV operator<<(std::ostream& lhs, yaml_formatter&& rhs) {
127 return lhs << rhs; // as lvalue
128 }
129 };
130}
132
133#include "header_end.hpp"
134#endif // TOML_ENABLE_FORMATTERS
const char print[]
#define rhs
Definition 17.names.cpp:536
#define lhs
Definition 17.names.cpp:489
volatile int result
#define flags
enum TOML_CLOSED_FLAGS_ENUM format_flags
Format flags for modifying how TOML data is printed to streams.
std::basic_ostream< Char > & operator<<(std::basic_ostream< Char > &lhs, node_type rhs)
Pretty-prints the value of a node_type to a stream.
#define TOML_CALLCONV
Calling convention to apply to exported free/static functions. \detail Not defined by default (let th...
#define TOML_EXPORTED_CLASS
An 'export' annotation to add to classes. \detail Not defined by default.
#define TOML_EXPORTED_MEMBER_FUNCTION
An 'export' annotation to add to non-static class member functions. \detail Not defined by default.
#define TOML_NODISCARD_CTOR
TOML_NAMESPACE_START
TOML_NAMESPACE_END