From 983e22978e8792f6248695047ad7cb892c112e18 Mon Sep 17 00:00:00 2001 From: Mark Gillard Date: Wed, 20 May 2020 13:27:06 +0300 Subject: [PATCH] fixed formatter::print_inline causing compilation failures in windows DLL builds --- include/toml++/toml.h | 1 + include/toml++/toml_default_formatter.h | 35 ----- include/toml++/toml_default_formatter.hpp | 39 +++++ include/toml++/toml_json_formatter.h | 40 ----- include/toml++/toml_json_formatter.hpp | 66 ++++++++ toml.hpp | 177 ++++++++++++---------- vs/toml++.vcxproj | 1 + vs/toml++.vcxproj.filters | 3 + 8 files changed, 208 insertions(+), 154 deletions(-) create mode 100644 include/toml++/toml_json_formatter.hpp diff --git a/include/toml++/toml.h b/include/toml++/toml.h index 47b71f3..1fa4bad 100644 --- a/include/toml++/toml.h +++ b/include/toml++/toml.h @@ -38,6 +38,7 @@ #include "toml_array.hpp" #include "toml_table.hpp" #include "toml_default_formatter.hpp" + #include "toml_json_formatter.hpp" #if TOML_PARSER #include "toml_parser.hpp" diff --git a/include/toml++/toml_default_formatter.h b/include/toml++/toml_default_formatter.h index 6f0063d..3fe4d8b 100644 --- a/include/toml++/toml_default_formatter.h +++ b/include/toml++/toml_default_formatter.h @@ -343,41 +343,6 @@ namespace toml default_formatter(const array&) -> default_formatter; template default_formatter(const value&) -> default_formatter; - template - inline void default_formatter::print_inline(const toml::table& tbl) - { - if (tbl.empty()) - impl::print_to_stream("{}"sv, base::stream()); - else - { - impl::print_to_stream("{ "sv, base::stream()); - - bool first = false; - for (auto [k, v] : tbl) - { - if (first) - impl::print_to_stream(", "sv, base::stream()); - first = true; - - print_key_segment(k); - impl::print_to_stream(" = "sv, base::stream()); - - const auto type = v.type(); - TOML_ASSUME(type != node_type::none); - switch (type) - { - case node_type::table: print_inline(*reinterpret_cast(&v)); break; - case node_type::array: print(*reinterpret_cast(&v)); break; - default: - base::print_value(v, type); - } - } - - impl::print_to_stream(" }"sv, base::stream()); - } - base::clear_naked_newline(); - } - /// \brief Prints the bound TOML object out to the stream as formatted TOML. template TOML_EXTERNAL_LINKAGE diff --git a/include/toml++/toml_default_formatter.hpp b/include/toml++/toml_default_formatter.hpp index c400286..fb6a331 100644 --- a/include/toml++/toml_default_formatter.hpp +++ b/include/toml++/toml_default_formatter.hpp @@ -152,6 +152,45 @@ namespace toml::impl } } +namespace toml +{ + template + TOML_EXTERNAL_LINKAGE + void default_formatter::print_inline(const toml::table& tbl) + { + if (tbl.empty()) + impl::print_to_stream("{}"sv, base::stream()); + else + { + impl::print_to_stream("{ "sv, base::stream()); + + bool first = false; + for (auto [k, v] : tbl) + { + if (first) + impl::print_to_stream(", "sv, base::stream()); + first = true; + + print_key_segment(k); + impl::print_to_stream(" = "sv, base::stream()); + + const auto type = v.type(); + TOML_ASSUME(type != node_type::none); + switch (type) + { + case node_type::table: print_inline(*reinterpret_cast(&v)); break; + case node_type::array: print(*reinterpret_cast(&v)); break; + default: + base::print_value(v, type); + } + } + + impl::print_to_stream(" }"sv, base::stream()); + } + base::clear_naked_newline(); + } +} + TOML_POP_WARNINGS // TOML_DISABLE_SWITCH_WARNINGS, TOML_DISABLE_FLOAT_WARNINGS //# {{ diff --git a/include/toml++/toml_json_formatter.h b/include/toml++/toml_json_formatter.h index 9b705c4..657b24e 100644 --- a/include/toml++/toml_json_formatter.h +++ b/include/toml++/toml_json_formatter.h @@ -127,46 +127,6 @@ namespace toml json_formatter(const array&) -> json_formatter; template json_formatter(const value&) -> json_formatter; - template - inline void json_formatter::print(const toml::table& tbl) - { - if (tbl.empty()) - impl::print_to_stream("{}"sv, base::stream()); - else - { - impl::print_to_stream('{', base::stream()); - base::increase_indent(); - bool first = false; - for (auto [k, v] : tbl) - { - if (first) - impl::print_to_stream(", "sv, base::stream()); - first = true; - base::print_newline(true); - base::print_indent(); - - base::print_quoted_string(k); - impl::print_to_stream(" : "sv, base::stream()); - - const auto type = v.type(); - TOML_ASSUME(type != node_type::none); - switch (type) - { - case node_type::table: print(*reinterpret_cast(&v)); break; - case node_type::array: print(*reinterpret_cast(&v)); break; - default: - base::print_value(v, type); - } - - } - base::decrease_indent(); - base::print_newline(true); - base::print_indent(); - impl::print_to_stream('}', base::stream()); - } - base::clear_naked_newline(); - } - /// \brief Prints the bound TOML object out to the stream as JSON. template TOML_EXTERNAL_LINKAGE diff --git a/include/toml++/toml_json_formatter.hpp b/include/toml++/toml_json_formatter.hpp new file mode 100644 index 0000000..f140ad7 --- /dev/null +++ b/include/toml++/toml_json_formatter.hpp @@ -0,0 +1,66 @@ +//# This file is a part of toml++ and is subject to the the terms of the MIT license. +//# Copyright (c) 2019-2020 Mark Gillard +//# See https://github.com/marzer/tomlplusplus/blob/master/LICENSE for the full license text. +// SPDX-License-Identifier: MIT + +#pragma once +#include "toml_json_formatter.h" +//# {{ +#if !TOML_DOXYGEN +#if !defined(TOML_IMPLEMENTATION) || !TOML_IMPLEMENTATION + #error This is an implementation-only header. +#endif +//# }} + +TOML_PUSH_WARNINGS +TOML_DISABLE_SWITCH_WARNINGS + +namespace toml +{ + template + TOML_EXTERNAL_LINKAGE + void json_formatter::print(const toml::table& tbl) + { + if (tbl.empty()) + impl::print_to_stream("{}"sv, base::stream()); + else + { + impl::print_to_stream('{', base::stream()); + base::increase_indent(); + bool first = false; + for (auto [k, v] : tbl) + { + if (first) + impl::print_to_stream(", "sv, base::stream()); + first = true; + base::print_newline(true); + base::print_indent(); + + base::print_quoted_string(k); + impl::print_to_stream(" : "sv, base::stream()); + + const auto type = v.type(); + TOML_ASSUME(type != node_type::none); + switch (type) + { + case node_type::table: print(*reinterpret_cast(&v)); break; + case node_type::array: print(*reinterpret_cast(&v)); break; + default: + base::print_value(v, type); + } + + } + base::decrease_indent(); + base::print_newline(true); + base::print_indent(); + impl::print_to_stream('}', base::stream()); + } + base::clear_naked_newline(); + } +} + +TOML_POP_WARNINGS // TOML_DISABLE_SWITCH_WARNINGS + +//# {{ +#endif // !TOML_DOXYGEN +//# }} diff --git a/toml.hpp b/toml.hpp index 01a4e3c..b98bdc5 100644 --- a/toml.hpp +++ b/toml.hpp @@ -4762,41 +4762,6 @@ namespace toml default_formatter(const array&) -> default_formatter; template default_formatter(const value&) -> default_formatter; - template - inline void default_formatter::print_inline(const toml::table& tbl) - { - if (tbl.empty()) - impl::print_to_stream("{}"sv, base::stream()); - else - { - impl::print_to_stream("{ "sv, base::stream()); - - bool first = false; - for (auto [k, v] : tbl) - { - if (first) - impl::print_to_stream(", "sv, base::stream()); - first = true; - - print_key_segment(k); - impl::print_to_stream(" = "sv, base::stream()); - - const auto type = v.type(); - TOML_ASSUME(type != node_type::none); - switch (type) - { - case node_type::table: print_inline(*reinterpret_cast(&v)); break; - case node_type::array: print(*reinterpret_cast(&v)); break; - default: - base::print_value(v, type); - } - } - - impl::print_to_stream(" }"sv, base::stream()); - } - base::clear_naked_newline(); - } - template TOML_EXTERNAL_LINKAGE std::basic_ostream& operator << (std::basic_ostream& lhs, default_formatter& rhs) @@ -4929,46 +4894,6 @@ namespace toml json_formatter(const array&) -> json_formatter; template json_formatter(const value&) -> json_formatter; - template - inline void json_formatter::print(const toml::table& tbl) - { - if (tbl.empty()) - impl::print_to_stream("{}"sv, base::stream()); - else - { - impl::print_to_stream('{', base::stream()); - base::increase_indent(); - bool first = false; - for (auto [k, v] : tbl) - { - if (first) - impl::print_to_stream(", "sv, base::stream()); - first = true; - base::print_newline(true); - base::print_indent(); - - base::print_quoted_string(k); - impl::print_to_stream(" : "sv, base::stream()); - - const auto type = v.type(); - TOML_ASSUME(type != node_type::none); - switch (type) - { - case node_type::table: print(*reinterpret_cast(&v)); break; - case node_type::array: print(*reinterpret_cast(&v)); break; - default: - base::print_value(v, type); - } - - } - base::decrease_indent(); - base::print_newline(true); - base::print_indent(); - impl::print_to_stream('}', base::stream()); - } - base::clear_naked_newline(); - } - template TOML_EXTERNAL_LINKAGE std::basic_ostream& operator << (std::basic_ostream& lhs, json_formatter& rhs) @@ -6486,14 +6411,108 @@ namespace toml::impl } } +namespace toml +{ + template + TOML_EXTERNAL_LINKAGE + void default_formatter::print_inline(const toml::table& tbl) + { + if (tbl.empty()) + impl::print_to_stream("{}"sv, base::stream()); + else + { + impl::print_to_stream("{ "sv, base::stream()); + + bool first = false; + for (auto [k, v] : tbl) + { + if (first) + impl::print_to_stream(", "sv, base::stream()); + first = true; + + print_key_segment(k); + impl::print_to_stream(" = "sv, base::stream()); + + const auto type = v.type(); + TOML_ASSUME(type != node_type::none); + switch (type) + { + case node_type::table: print_inline(*reinterpret_cast(&v)); break; + case node_type::array: print(*reinterpret_cast(&v)); break; + default: + base::print_value(v, type); + } + } + + impl::print_to_stream(" }"sv, base::stream()); + } + base::clear_naked_newline(); + } +} + TOML_POP_WARNINGS // TOML_DISABLE_SWITCH_WARNINGS, TOML_DISABLE_FLOAT_WARNINGS #pragma endregion //---------- ↑ toml_default_formatter.hpp ---------------------------------------------------------------------------- +//------------------------------------- ↓ toml_json_formatter.hpp ---------------------------------------------------- +#pragma region + +TOML_PUSH_WARNINGS +TOML_DISABLE_SWITCH_WARNINGS + +namespace toml +{ + template + TOML_EXTERNAL_LINKAGE + void json_formatter::print(const toml::table& tbl) + { + if (tbl.empty()) + impl::print_to_stream("{}"sv, base::stream()); + else + { + impl::print_to_stream('{', base::stream()); + base::increase_indent(); + bool first = false; + for (auto [k, v] : tbl) + { + if (first) + impl::print_to_stream(", "sv, base::stream()); + first = true; + base::print_newline(true); + base::print_indent(); + + base::print_quoted_string(k); + impl::print_to_stream(" : "sv, base::stream()); + + const auto type = v.type(); + TOML_ASSUME(type != node_type::none); + switch (type) + { + case node_type::table: print(*reinterpret_cast(&v)); break; + case node_type::array: print(*reinterpret_cast(&v)); break; + default: + base::print_value(v, type); + } + + } + base::decrease_indent(); + base::print_newline(true); + base::print_indent(); + impl::print_to_stream('}', base::stream()); + } + base::clear_naked_newline(); + } +} + +TOML_POP_WARNINGS // TOML_DISABLE_SWITCH_WARNINGS + +#pragma endregion +//------------------------------------- ↑ toml_json_formatter.hpp ---------------------------------------------------- + #if TOML_PARSER -//----------------------------------------- ↓ toml_parser.hpp -------------------------------------------------------- +//------------------------------------------------------------------ ↓ toml_parser.hpp ------------------------------- #pragma region TOML_PUSH_WARNINGS @@ -9330,12 +9349,12 @@ namespace toml TOML_POP_WARNINGS // TOML_DISABLE_SWITCH_WARNINGS, TOML_DISABLE_PADDING_WARNINGS #pragma endregion -//----------------------------------------- ↑ toml_parser.hpp -------------------------------------------------------- +//------------------------------------------------------------------ ↑ toml_parser.hpp ------------------------------- #endif // TOML_PARSER #if !TOML_ALL_INLINE -//-------------------------------------------------------------- ↓ toml_instantiations.hpp --------------------------- +//--------------------------------------------------------------------------------------- ↓ toml_instantiations.hpp -- #pragma region TOML_PUSH_WARNINGS @@ -9423,7 +9442,7 @@ namespace toml } #pragma endregion -//-------------------------------------------------------------- ↑ toml_instantiations.hpp --------------------------- +//--------------------------------------------------------------------------------------- ↑ toml_instantiations.hpp -- #endif // !TOML_ALL_INLINE #endif // TOML_IMPLEMENTATION diff --git a/vs/toml++.vcxproj b/vs/toml++.vcxproj index 88f61df..85a77ae 100644 --- a/vs/toml++.vcxproj +++ b/vs/toml++.vcxproj @@ -65,6 +65,7 @@ + diff --git a/vs/toml++.vcxproj.filters b/vs/toml++.vcxproj.filters index 85984c0..4a6aa21 100644 --- a/vs/toml++.vcxproj.filters +++ b/vs/toml++.vcxproj.filters @@ -79,6 +79,9 @@ include + + include +