//# This file is a part of toml++ and is subject to the the terms of the MIT license. //# Copyright (c) Mark Gillard //# See https://github.com/marzer/tomlplusplus/blob/master/LICENSE for the full license text. // SPDX-License-Identifier: MIT #pragma once #include "preprocessor.h" #if TOML_ENABLE_FORMATTERS #include "forward_declarations.h" #include "print_to_stream.h" #include "header_start.h" /// \cond TOML_IMPL_NAMESPACE_START { struct formatter_constants { format_flags mandatory_flags; format_flags ignored_flags; std::string_view float_pos_inf; std::string_view float_neg_inf; std::string_view float_nan; std::string_view bool_true; std::string_view bool_false; }; struct formatter_config { format_flags flags; std::string_view indent; }; class formatter { private: const node* source_; #if TOML_ENABLE_PARSER && !TOML_EXCEPTIONS const parse_result* result_; #endif const formatter_constants* constants_; formatter_config config_; size_t indent_columns_; format_flags int_format_mask_; std::ostream* stream_; // int indent_; // these are set in attach() bool naked_newline_; // protected: TOML_PURE_INLINE_GETTER const node& source() const noexcept { return *source_; } TOML_PURE_INLINE_GETTER std::ostream& stream() const noexcept { return *stream_; } TOML_PURE_INLINE_GETTER int indent() const noexcept { return indent_; } void indent(int level) noexcept { indent_ = level; } void increase_indent() noexcept { indent_++; } void decrease_indent() noexcept { indent_--; } TOML_PURE_INLINE_GETTER size_t indent_columns() const noexcept { return indent_columns_; } TOML_PURE_INLINE_GETTER bool indent_array_elements() const noexcept { return !!(config_.flags & format_flags::indent_array_elements); } TOML_PURE_INLINE_GETTER bool indent_sub_tables() const noexcept { return !!(config_.flags & format_flags::indent_sub_tables); } TOML_PURE_INLINE_GETTER bool literal_strings_allowed() const noexcept { return !!(config_.flags & format_flags::allow_literal_strings); } TOML_API void attach(std::ostream& stream) noexcept; TOML_API void detach() noexcept; TOML_API void print_newline(bool force = false); TOML_API void print_indent(); TOML_API void print_unformatted(char); TOML_API void print_unformatted(std::string_view); TOML_API void print_string(std::string_view str, bool allow_multi_line = true, bool allow_bare = false); TOML_API void print(const value&); TOML_API void print(const value&); TOML_API void print(const value&); TOML_API void print(const value&); TOML_API void print(const value&); TOML_API void print(const value