Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
json_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
45 class TOML_EXPORTED_CLASS json_formatter : impl::formatter {
46 private:
48
49 using base = impl::formatter;
50
52 void print(const toml::table&);
53
55 void print(const toml::array&);
56
58 void print();
59
60 static constexpr impl::formatter_constants constants = {
61 format_flags::quote_dates_and_times, // mandatory
62 format_flags::allow_literal_strings | format_flags::allow_multi_line_strings, // ignored
63 "Infinity"sv,
64 "-Infinity"sv,
65 "NaN"sv,
66 "true"sv,
67 "false"sv};
68
70
71 public:
73 static constexpr format_flags default_flags = constants.mandatory_flags //
74 | format_flags::quote_infinities_and_nans //
75 | format_flags::allow_unicode_strings //
76 | format_flags::indentation;
77
83 explicit json_formatter(const toml::node& source, format_flags flags = default_flags) noexcept
84 : base{&source, nullptr, constants, {flags, " "sv}} {}
85
86#if TOML_DOXYGEN || (TOML_ENABLE_PARSER && !TOML_EXCEPTIONS)
87
114 explicit json_formatter(const toml::parse_result& result,
115 format_flags flags = default_flags) noexcept
116 : base{nullptr, &result, constants, {flags, " "sv}} {}
117
118#endif
119
121 friend std::ostream& operator<<(std::ostream& lhs, json_formatter& rhs) {
122 rhs.attach(lhs);
123 rhs.print();
124 rhs.detach();
125 return lhs;
126 }
127
129 friend std::ostream& operator<<(std::ostream& lhs, json_formatter&& rhs) {
130 return lhs << rhs; // as lvalue
131 }
132 };
133}
135
136#include "header_end.hpp"
137#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.
TOML_NAMESPACE_START
TOML_NAMESPACE_END
#define TOML_NODISCARD_CTOR