Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
toml_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#include "std_vector.hpp"
13
43 class TOML_EXPORTED_CLASS toml_formatter : impl::formatter {
44 private:
46
47 using base = impl::formatter;
48 std::vector<const key*> key_path_;
49 bool pending_table_separator_ = false;
50
52 void print_pending_table_separator();
53
55 void print(const key&);
56
58 void print_inline(const toml::table&);
59
61 void print(const toml::array&);
62
64 void print(const toml::table&);
65
67 void print();
68
69 static constexpr impl::formatter_constants constants = {format_flags::none, // mandatory
70 format_flags::none, // ignored
71 "inf"sv,
72 "-inf"sv,
73 "nan"sv,
74 "true"sv,
75 "false"sv};
76
78
79 public:
81 static constexpr format_flags default_flags = constants.mandatory_flags //
82 | format_flags::allow_literal_strings //
83 | format_flags::allow_multi_line_strings //
84 | format_flags::allow_unicode_strings //
85 | format_flags::allow_real_tabs_in_strings //
86 | format_flags::allow_binary_integers //
87 | format_flags::allow_octal_integers //
88 | format_flags::allow_hexadecimal_integers //
89 | format_flags::indentation;
90
96 explicit toml_formatter(const toml::node& source, format_flags flags = default_flags) noexcept
97 : base{&source, nullptr, constants, {flags, " "sv}} {}
98
99#if TOML_DOXYGEN || (TOML_ENABLE_PARSER && !TOML_EXCEPTIONS)
100
125 explicit toml_formatter(const toml::parse_result& result,
126 format_flags flags = default_flags) noexcept
127 : base{nullptr, &result, constants, {flags, " "sv}} {}
128
129#endif
130
132 friend std::ostream& operator<<(std::ostream& lhs, toml_formatter& rhs) {
133 rhs.attach(lhs);
134 rhs.key_path_.clear();
135 rhs.print();
136 rhs.detach();
137 return lhs;
138 }
139
141 friend std::ostream& operator<<(std::ostream& lhs, toml_formatter&& rhs) {
142 return lhs << rhs; // as lvalue
143 }
144 };
145}
147
148#include "header_end.hpp"
149#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_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