NeBuild dev
Loading...
Searching...
No Matches
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
14{
40 class TOML_EXPORTED_CLASS yaml_formatter : impl::formatter
41 {
42 private:
44
45 using base = impl::formatter;
46
48 void print_yaml_string(const value<std::string>&);
49
51 void print(const toml::table&, bool = false);
52
54 void print(const toml::array&, bool = false);
55
57 void print();
58
59 static constexpr impl::formatter_constants constants = {
60 //
61 format_flags::quote_dates_and_times | format_flags::indentation, // mandatory
62 format_flags::allow_multi_line_strings, // ignored
63 ".inf"sv,
64 "-.inf"sv,
65 ".NAN"sv,
66 "true"sv,
67 "false"sv
68 };
69
71
72 public:
74 static constexpr format_flags default_flags = constants.mandatory_flags //
75 | format_flags::allow_literal_strings //
76 | format_flags::allow_unicode_strings //
77 | format_flags::allow_octal_integers //
78 | format_flags::allow_hexadecimal_integers;
79
85 explicit yaml_formatter(const toml::node& source, format_flags flags = default_flags) noexcept
86 : base{ &source, nullptr, constants, { flags, " "sv } }
87 {}
88
89#if TOML_DOXYGEN || (TOML_ENABLE_PARSER && !TOML_EXCEPTIONS)
90
114 explicit yaml_formatter(const toml::parse_result& result, format_flags flags = default_flags) noexcept
115 : base{ nullptr, &result, constants, { flags, " "sv } }
116 {}
117
118#endif
119
121 friend std::ostream& TOML_CALLCONV operator<<(std::ostream& lhs, yaml_formatter& rhs)
122 {
123 rhs.attach(lhs);
124 rhs.print();
125 rhs.detach();
126 return lhs;
127 }
128
130 friend std::ostream& TOML_CALLCONV operator<<(std::ostream& lhs, yaml_formatter&& rhs)
131 {
132 return lhs << rhs; // as lvalue
133 }
134 };
135}
137
138#include "header_end.hpp"
139#endif // TOML_ENABLE_FORMATTERS
enum TOML_CLOSED_FLAGS_ENUM format_flags
Format flags for modifying how TOML data is printed to streams.
Definition forward_declarations.hpp:297
std::basic_ostream< Char > & operator<<(std::basic_ostream< Char > &lhs, node_type rhs)
Pretty-prints the value of a node_type to a stream.
Definition forward_declarations.hpp:256
#define TOML_CALLCONV
Calling convention to apply to exported free/static functions. \detail Not defined by default (let th...
Definition preprocessor.hpp:1134
#define TOML_EXPORTED_CLASS
An 'export' annotation to add to classes. \detail Not defined by default.
Definition preprocessor.hpp:979
#define TOML_EXPORTED_MEMBER_FUNCTION
An 'export' annotation to add to non-static class member functions. \detail Not defined by default.
Definition preprocessor.hpp:982
#define TOML_NODISCARD_CTOR
Definition preprocessor.hpp:446
TOML_NAMESPACE_START
Definition yaml_formatter.hpp:14
TOML_NAMESPACE_END
Definition yaml_formatter.hpp:136