From 1baad21734d6d28a4efeb9ee3288c63487519bdb Mon Sep 17 00:00:00 2001 From: Mark Gillard Date: Wed, 19 May 2021 14:36:25 +0300 Subject: [PATCH] removed `` requirement for `parse_file` also: - fixed false-positive char_8 support detection on older compilers - removed extraneous `TOML_API` declarations --- README.md | 8 +- docs/pages/main_page.dox | 18 +- docs/poxy.toml | 1 + examples/simple_parser.cpp | 1 - examples/toml_to_json_transcoder.cpp | 1 - include/toml++/toml.h | 1 + include/toml++/toml_array.hpp | 2 - include/toml++/toml_common.h | 19 +- include/toml++/toml_default_formatter.hpp | 10 +- include/toml++/toml_instantiations.hpp | 92 +++-- include/toml++/toml_node_view.h | 2 +- include/toml++/toml_parser.h | 165 +++------ include/toml++/toml_parser.hpp | 110 ++++-- include/toml++/toml_preprocessor.h | 10 +- include/toml++/toml_print_to_stream.h | 2 +- include/toml++/toml_table.hpp | 2 - include/toml++/toml_value.h | 22 +- include/toml++/toml_version.h | 4 +- meson.build | 4 +- tests/impl_toml.cpp | 6 +- tests/manipulating_values.cpp | 2 +- toml.hpp | 401 ++++++++++------------ tools/requirements.txt | 2 +- 23 files changed, 423 insertions(+), 462 deletions(-) diff --git a/README.md b/README.md index ecda7af..af5468e 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,6 @@ cpp = 17 Reading it in C++ is easy with toml++: ```cpp #include -#include //required for toml::parse_file() auto config = toml::parse_file( "configuration.toml" ); @@ -98,14 +97,13 @@ You'll find some more code examples in the `examples` directory, and plenty more 2. `#include ` ### Conan -Add `tomlplusplus/2.3.0` to your conanfile.
-This adds the single-header version by default, but you can specify the regular version using `"multiple_headers": True`. +Add `tomlplusplus/2.4.0` to your conanfile. ### DDS Add `tomlpp` to your `package.json5`, e.g.: ``` depends: [ - 'tomlpp^2.3.0', + 'tomlpp^2.4.0', ] ``` > ℹ️ _[What is DDS?](https://dds.pizza/)_ @@ -121,7 +119,7 @@ include(FetchContent) FetchContent_Declare( tomlplusplus GIT_REPOSITORY https://github.com/marzer/tomlplusplus.git - GIT_TAG 0fcbfbe655917738c39321fcbcbdc7b048a40e33 + GIT_TAG v2.4.0 ) FetchContent_MakeAvailable(tomlplusplus) ``` diff --git a/docs/pages/main_page.dox b/docs/pages/main_page.dox index e225634..d9d0382 100644 --- a/docs/pages/main_page.dox +++ b/docs/pages/main_page.dox @@ -34,7 +34,6 @@ /// /// \cpp /// #include -/// #include //required for parse_file() /// #include /// /// int main(int argc, char** argv) @@ -56,15 +55,6 @@ /// /// \ecpp /// -/// \m_class{m-note m-warning} -/// -/// \parblock -///

Don't forget [code]\#include <fstream>[/code]!

-/// Not everyone who uses the library is going to work directly from files, so not everybody is forced to pay -/// the compilation overhead of including ``. You need to explicitly include it if you're going to be calling -/// toml::parse_file(). -/// \endparblock -/// /// \see /// - toml::parse_file() /// - toml::table @@ -144,7 +134,6 @@ /// /// \cpp /// #include -/// #include /// /// #define TOML_EXCEPTIONS 0 // only necessary if you've left them enabled in your compiler /// #include @@ -437,8 +426,7 @@ ////////////////////////////////// /// /// \subsection mainpage-adding-lib-conan Conan -/// Add `tomlplusplus/2.3.0` to your conanfile. This adds the single-header version by default, but you can specify the -/// regular version using `"multiple_headers": True`. +/// Add `tomlplusplus/2.4.0` to your conanfile. /// ////////////////////////////////// /// @@ -446,7 +434,7 @@ /// Add `tomlpp` to your `package.json5`, e.g.: /// \bash /// depends: [ -/// 'tomlpp^2.3.0', +/// 'tomlpp^2.4.0', /// ] /// \ebash /// @@ -472,7 +460,7 @@ /// FetchContent_Declare( /// tomlplusplus /// GIT_REPOSITORY https://github.com/marzer/tomlplusplus.git -/// GIT_TAG 0fcbfbe655917738c39321fcbcbdc7b048a40e33 +/// GIT_TAG v2.4.0 /// ) /// FetchContent_MakeAvailable(tomlplusplus) /// \ebash diff --git a/docs/poxy.toml b/docs/poxy.toml index 32f24bd..1ba2247 100644 --- a/docs/poxy.toml +++ b/docs/poxy.toml @@ -2,6 +2,7 @@ # https://github.com/marzer/poxy name = 'toml++' +author = 'Mark Gillard' description = 'TOML for modern C++' cpp = 17 github = 'marzer/tomlplusplus' diff --git a/examples/simple_parser.cpp b/examples/simple_parser.cpp index cc5c206..67d44c5 100644 --- a/examples/simple_parser.cpp +++ b/examples/simple_parser.cpp @@ -9,7 +9,6 @@ */ #include -#include #include "utf8_console.h" #define TOML_UNRELEASED_FEATURES 1 diff --git a/examples/toml_to_json_transcoder.cpp b/examples/toml_to_json_transcoder.cpp index 51ea08c..6832d13 100644 --- a/examples/toml_to_json_transcoder.cpp +++ b/examples/toml_to_json_transcoder.cpp @@ -9,7 +9,6 @@ */ #include -#include #include "utf8_console.h" #define TOML_UNRELEASED_FEATURES 1 diff --git a/include/toml++/toml.h b/include/toml++/toml.h index b2e5e78..6e91d4e 100644 --- a/include/toml++/toml.h +++ b/include/toml++/toml.h @@ -93,6 +93,7 @@ TOML_POP_WARNINGS; // TOML_DISABLE_SPAM_WARNINGS #undef TOML_GCC #undef TOML_HAS_ATTR #undef TOML_HAS_CUSTOM_OPTIONAL_TYPE + #undef TOML_HAS_CHAR8 #undef TOML_HAS_INCLUDE #undef TOML_ICC #undef TOML_ICC_CL diff --git a/include/toml++/toml_array.hpp b/include/toml++/toml_array.hpp index ef5b7dd..7c61b80 100644 --- a/include/toml++/toml_array.hpp +++ b/include/toml++/toml_array.hpp @@ -238,7 +238,6 @@ TOML_NAMESPACE_START return index < elements.size() ? elements[index].get() : nullptr; } - TOML_API TOML_EXTERNAL_LINKAGE bool operator == (const array& lhs, const array& rhs) noexcept { @@ -264,7 +263,6 @@ TOML_NAMESPACE_START return true; } - TOML_API TOML_EXTERNAL_LINKAGE bool operator != (const array& lhs, const array& rhs) noexcept { diff --git a/include/toml++/toml_common.h b/include/toml++/toml_common.h index 28cb83a..a53f3f5 100644 --- a/include/toml++/toml_common.h +++ b/include/toml++/toml_common.h @@ -24,20 +24,25 @@ TOML_DISABLE_WARNINGS; #include #include #include +#include #if !TOML_HAS_CUSTOM_OPTIONAL_TYPE #include #endif -#if TOML_HAS_INCLUDE() - #include -#endif TOML_ENABLE_WARNINGS; -#ifdef __cpp_lib_launder +#if defined(__cpp_lib_launder) && __cpp_lib_launder >= 201606 #define TOML_LAUNDER(x) std::launder(x) #else #define TOML_LAUNDER(x) x #endif +#if defined(__cpp_char8_t) && __cpp_char8_t >= 201811 \ + && defined(__cpp_lib_char8_t) && __cpp_lib_char8_t >= 201907 + #define TOML_HAS_CHAR8 1 +#else + #define TOML_HAS_CHAR8 0 +#endif + //#==================================================================================================================== //# ENVIRONMENT GROUND-TRUTHS //#==================================================================================================================== @@ -174,7 +179,7 @@ TOML_NAMESPACE_START // abi namespace #if TOML_WINDOWS_COMPAT [[nodiscard]] TOML_API std::string narrow(std::wstring_view) noexcept; [[nodiscard]] TOML_API std::wstring widen(std::string_view) noexcept; - #ifdef __cpp_lib_char8_t + #if TOML_HAS_CHAR8 [[nodiscard]] TOML_API std::wstring widen(std::u8string_view) noexcept; #endif #endif // TOML_WINDOWS_COMPAT @@ -460,7 +465,7 @@ TOML_IMPL_NAMESPACE_START template struct value_traits : string_value_traits {}; template <> struct value_traits : string_value_traits {}; template struct value_traits : string_value_traits {}; - #ifdef __cpp_lib_char8_t + #if TOML_HAS_CHAR8 template <> struct value_traits : string_value_traits {}; template <> struct value_traits : string_value_traits {}; template <> struct value_traits : string_value_traits {}; @@ -795,8 +800,6 @@ TOML_NAMESPACE_START /// \brief A source document region. /// /// \detail \cpp - /// #include - /// /// auto tbl = toml::parse_file("config.toml"sv); /// if (auto server = tbl.get("server")) /// { diff --git a/include/toml++/toml_default_formatter.hpp b/include/toml++/toml_default_formatter.hpp index 5e09742..0602fd1 100644 --- a/include/toml++/toml_default_formatter.hpp +++ b/include/toml++/toml_default_formatter.hpp @@ -24,7 +24,6 @@ TOML_IMPL_NAMESPACE_START { inline constexpr size_t default_formatter_line_wrap = 120_sz; - TOML_API TOML_EXTERNAL_LINKAGE std::string default_formatter_make_key_segment(const std::string& str) noexcept { @@ -69,7 +68,6 @@ TOML_IMPL_NAMESPACE_START } } - TOML_API TOML_EXTERNAL_LINKAGE size_t default_formatter_inline_columns(const node& node) noexcept { @@ -153,7 +151,6 @@ TOML_IMPL_NAMESPACE_START TOML_UNREACHABLE; } - TOML_API TOML_EXTERNAL_LINKAGE bool default_formatter_forces_multiline(const node& node, size_t starting_column_bias) noexcept { @@ -230,7 +227,6 @@ extern "C" TOML_IMPL_NAMESPACE_START { - TOML_API TOML_EXTERNAL_LINKAGE std::string narrow(std::wstring_view str) noexcept { @@ -249,7 +245,6 @@ TOML_IMPL_NAMESPACE_START return s; } - TOML_API TOML_EXTERNAL_LINKAGE std::wstring widen(std::string_view str) noexcept { @@ -266,9 +261,8 @@ TOML_IMPL_NAMESPACE_START return s; } - #ifdef __cpp_lib_char8_t + #if TOML_HAS_CHAR8 - TOML_API TOML_EXTERNAL_LINKAGE std::wstring widen(std::u8string_view str) noexcept { @@ -278,7 +272,7 @@ TOML_IMPL_NAMESPACE_START return widen(std::string_view{ reinterpret_cast(str.data()), str.length() }); } - #endif // __cpp_lib_char8_t + #endif // TOML_HAS_CHAR8 } TOML_IMPL_NAMESPACE_END; diff --git a/include/toml++/toml_instantiations.hpp b/include/toml++/toml_instantiations.hpp index 90fd5d8..49d95d8 100644 --- a/include/toml++/toml_instantiations.hpp +++ b/include/toml++/toml_instantiations.hpp @@ -17,7 +17,6 @@ TOML_DISABLE_WARNINGS; #include #include -#include TOML_ENABLE_WARNINGS; #include "toml_node_view.h" @@ -31,10 +30,10 @@ TOML_ENABLE_WARNINGS; TOML_IMPL_NAMESPACE_START { // formatters - template class TOML_API formatter; + template class formatter; // print to stream machinery - template TOML_API void print_floating_point_to_stream(double, std::ostream&, bool); + template void print_floating_point_to_stream(double, std::ostream&, bool); } TOML_IMPL_NAMESPACE_END; @@ -42,51 +41,51 @@ TOML_IMPL_NAMESPACE_END; TOML_NAMESPACE_START { // value<> - template class TOML_API value; - template class TOML_API value; - template class TOML_API value; - template class TOML_API value; - template class TOML_API value; - template class TOML_API value