diff --git a/README.md b/README.md index a9066a5..1854019 100644 --- a/README.md +++ b/README.md @@ -86,18 +86,19 @@ The API is the same regardless of how you consume the library. A number of configurable options are exposed in the form of preprocessor `#defines`. Most likely you won't need to mess with these at all, but if you do, set them before including toml++. -| Option | Type | Default | Description | -|----------------------------|:--------------:|-----------------------------------|----------------------------------------------------------------------------------------------------------| -| `TOML_ALL_INLINE` | boolean | `1` | Disable this to explicitly control where toml++'s implementation is compiled (e.g. as part of a static library). | -| `TOML_ASSERT(expr)` | function macro | `assert(expr)`
(or undefined) | Sets the assert function used by the library. | -| `TOML_CHAR_8_STRINGS` | boolean | `0` | Uses C++20 [char8_t]-based strings as the toml string data type. **_Experimental!_** | -| `TOML_CONFIG_HEADER` | string literal | undefined | Includes the given header file before the rest of the library. | -| `TOML_IMPLEMENTATION` | boolean | `0` | Enables the compiling of the library's implemenation. Meaningless if `TOML_ALL_INLINE` is `1`. | -| `TOML_LARGE_FILES` | boolean | `0` | Uses 32-bit integers for line and column indices (instead of 16-bit). | -| `TOML_SMALL_FLOAT_TYPE` | type name | undefined | If your codebase has an additional 'small' float type (e.g. half-precision), this tells toml++ about it. | -| `TOML_SMALL_INT_TYPE` | type name | undefined | If your codebase has an additional 'small' integer type (e.g. 24-bits), this tells toml++ about it. | -| `TOML_UNDEF_MACROS` | boolean | `1` | `#undefs` the library's internal macros at the end of the header. | -| `TOML_UNRELEASED_FEATURES` | boolean | `1` | Enables support for [unreleased TOML language features] not yet part of a [numbered version]. | +| Option | Type | Default | Description | +|----------------------------|:--------------:|-----------------------------------|------------------------------------------------------------------------------------------------------------| +| `TOML_ALL_INLINE` | boolean | `1` | Disable this to explicitly control where toml++'s implementation is compiled (e.g. as part of a library). | +| `TOML_API` | define | undefined | API annotation to add to public symbols (e.g. `__declspec(dllexport) on Windows)`. | +| `TOML_ASSERT(expr)` | function macro | `assert(expr)`
(or undefined) | Sets the assert function used by the library. | +| `TOML_CHAR_8_STRINGS` | boolean | `0` | Uses C++20 [char8_t]-based strings as the toml string data type. **_Experimental!_** | +| `TOML_CONFIG_HEADER` | string literal | undefined | Includes the given header file before the rest of the library. | +| `TOML_IMPLEMENTATION` | define | undefined | Define this to enable compilation of the library's implementation. Meaningless if `TOML_ALL_INLINE` is `1`.| +| `TOML_LARGE_FILES` | boolean | `0` | Uses 32-bit integers for line and column indices (instead of 16-bit). | +| `TOML_SMALL_FLOAT_TYPE` | type name | undefined | If your codebase has an additional 'small' float type (e.g. half-precision), this tells toml++ about it. | +| `TOML_SMALL_INT_TYPE` | type name | undefined | If your codebase has an additional 'small' integer type (e.g. 24-bits), this tells toml++ about it. | +| `TOML_UNDEF_MACROS` | boolean | `1` | `#undefs` the library's internal macros at the end of the header. | +| `TOML_UNRELEASED_FEATURES` | boolean | `1` | Enables support for [unreleased TOML language features] not yet part of a [numbered version]. |
diff --git a/include/toml++/toml.h b/include/toml++/toml.h index 4904fe1..665e92b 100644 --- a/include/toml++/toml.h +++ b/include/toml++/toml.h @@ -18,12 +18,17 @@ #include "toml_formatter.h" #include "toml_default_formatter.h" #include "toml_json_formatter.h" + +#if TOML_IMPLEMENTATION + #include "toml_node_impl.h" #include "toml_value_impl.h" #include "toml_array_impl.h" #include "toml_table_impl.h" #include "toml_parser_impl.h" +#endif + // macro hygiene #if TOML_UNDEF_MACROS #undef TOML_USE_STREAMS_FOR_FLOATS diff --git a/include/toml++/toml_array.h b/include/toml++/toml_array.h index 72f45ad..089c152 100644 --- a/include/toml++/toml_array.h +++ b/include/toml++/toml_array.h @@ -151,10 +151,8 @@ TOML_IMPL_START } }; - #if !TOML_ALL_INLINE - extern template class array_iterator; - extern template class array_iterator; - #endif + template class array_iterator; + template class array_iterator; template [[nodiscard]] TOML_ALWAYS_INLINE @@ -183,7 +181,10 @@ TOML_IMPL_END TOML_START { - [[nodiscard]] bool operator == (const table& lhs, const table& rhs) noexcept; + [[nodiscard]] TOML_API bool operator == (const array& lhs, const array& rhs) noexcept; + [[nodiscard]] TOML_API bool operator != (const array& lhs, const array& rhs) noexcept; + template + std::basic_ostream& operator << (std::basic_ostream&, const array&) TOML_MAY_THROW; /// \brief A TOML array. /// @@ -752,7 +753,6 @@ TOML_START /// \returns True if the arrays did not contain the same values. friend bool operator != (const array& lhs, const array& rhs) noexcept; - private: template @@ -802,25 +802,25 @@ TOML_START } TOML_ASYMMETRICAL_EQUALITY_OPS(const array&, const std::vector&, template ) - /// \brief Flattens this array, recursively hoisting the contents of child arrays up into itself. - /// - /// \detail \cpp - /// - /// auto arr = toml::array{ 1, 2, toml::array{ 3, 4, toml::array{ 5 } }, 6, toml::array{} }; - /// std::cout << arr << std::endl; - /// - /// arr.flatten(); - /// std::cout << arr << std::endl; - /// - /// \ecpp - /// - /// \out - /// [1, 2, [3, 4, [5]], 6, []] - /// [1, 2, 3, 4, 5, 6] - /// \eout - /// - /// \remarks Arrays inside child tables are not flattened. - void flatten() TOML_MAY_THROW; + /// \brief Flattens this array, recursively hoisting the contents of child arrays up into itself. + /// + /// \detail \cpp + /// + /// auto arr = toml::array{ 1, 2, toml::array{ 3, 4, toml::array{ 5 } }, 6, toml::array{} }; + /// std::cout << arr << std::endl; + /// + /// arr.flatten(); + /// std::cout << arr << std::endl; + /// + /// \ecpp + /// + /// \out + /// [1, 2, [3, 4, [5]], 6, []] + /// [1, 2, 3, 4, 5, 6] + /// \eout + /// + /// \remarks Arrays inside child tables are not flattened. + void flatten() TOML_MAY_THROW; template friend std::basic_ostream& operator << (std::basic_ostream&, const array&) TOML_MAY_THROW; diff --git a/include/toml++/toml_array_impl.h b/include/toml++/toml_array_impl.h index fd8cd2e..d5c4f6f 100644 --- a/include/toml++/toml_array_impl.h +++ b/include/toml++/toml_array_impl.h @@ -1,15 +1,6 @@ #pragma once #include "toml_array.h" -#if TOML_IMPLEMENTATION - -TOML_IMPL_START -{ - template class array_iterator; - template class array_iterator; -} -TOML_IMPL_END - TOML_START { TOML_INLINE_FUNC_IMPL @@ -100,7 +91,8 @@ TOML_START return index < values.size() ? values[index].get() : nullptr; } - [[nodiscard]] TOML_INLINE_FUNC_IMPL + TOML_API + TOML_INLINE_FUNC_IMPL bool operator == (const array& lhs, const array& rhs) noexcept { if (&lhs == &rhs) @@ -125,7 +117,8 @@ TOML_START return true; } - [[nodiscard]] TOML_INLINE_FUNC_IMPL + TOML_API + TOML_INLINE_FUNC_IMPL bool operator != (const array& lhs, const array& rhs) noexcept { return !(lhs == rhs); @@ -208,5 +201,3 @@ TOML_START } } TOML_END - -#endif // TOML_IMPLEMENTATION diff --git a/include/toml++/toml_common.h b/include/toml++/toml_common.h index a8c340c..b746153 100644 --- a/include/toml++/toml_common.h +++ b/include/toml++/toml_common.h @@ -11,11 +11,12 @@ #if !defined(TOML_ALL_INLINE) || (defined(TOML_ALL_INLINE) && TOML_ALL_INLINE) #undef TOML_ALL_INLINE #define TOML_ALL_INLINE 1 - #undef TOML_IMPLEMENTATION - #define TOML_IMPLEMENTATION 1 #endif -#ifndef TOML_IMPLEMENTATION +#if defined(TOML_IMPLEMENTATION) || TOML_ALL_INLINE + #undef TOML_IMPLEMENTATION + #define TOML_IMPLEMENTATION 1 +#else #define TOML_IMPLEMENTATION 0 #endif diff --git a/include/toml++/toml_node_impl.h b/include/toml++/toml_node_impl.h index 20fcbde..b50efd4 100644 --- a/include/toml++/toml_node_impl.h +++ b/include/toml++/toml_node_impl.h @@ -1,8 +1,6 @@ #pragma once #include "toml_node.h" -#if TOML_IMPLEMENTATION - TOML_START { TOML_INLINE_FUNC_IMPL @@ -55,5 +53,3 @@ TOML_START TOML_INLINE_FUNC_IMPL const source_region& node::source() const noexcept { return source_; } } TOML_END - -#endif // TOML_IMPLEMENTATION diff --git a/include/toml++/toml_parser.h b/include/toml++/toml_parser.h index 67e1db4..e0a1c1f 100644 --- a/include/toml++/toml_parser.h +++ b/include/toml++/toml_parser.h @@ -179,7 +179,7 @@ TOML_END TOML_IMPL_START { - [[nodiscard]] + [[nodiscard]] TOML_API parse_result do_parse(utf8_reader_interface&&) TOML_MAY_THROW; } TOML_IMPL_END @@ -205,7 +205,7 @@ TOML_START /// /// \returns With exceptions: A toml::table.
/// Without exceptions: A toml::parse_result detailing the parsing outcome. - [[nodiscard]] + [[nodiscard]] TOML_API parse_result parse(std::string_view doc, std::string_view source_path = {}) TOML_MAY_THROW; /// \brief Parses a TOML document from a string view. @@ -225,7 +225,7 @@ TOML_START /// /// \returns With exceptions: A toml::table.
/// Without exceptions: A toml::parse_result detailing the parsing outcome. - [[nodiscard]] + [[nodiscard]] TOML_API parse_result parse(std::string_view doc, std::string&& source_path) TOML_MAY_THROW; #if defined(__cpp_lib_char8_t) @@ -251,7 +251,7 @@ TOML_START /// Without exceptions: A toml::parse_result detailing the parsing outcome. /// /// \attention This overload is not available if your compiler does not support char8_t-based strings. - [[nodiscard]] + [[nodiscard]] TOML_API parse_result parse(std::u8string_view doc, std::string_view source_path = {}) TOML_MAY_THROW; /// \brief Parses a TOML document from a char8_t string view. @@ -273,7 +273,7 @@ TOML_START /// Without exceptions: A toml::parse_result detailing the parsing outcome. /// /// \attention This overload is not available if your compiler does not support char8_t-based strings. - [[nodiscard]] + [[nodiscard]] TOML_API parse_result parse(std::u8string_view doc, std::string&& source_path) TOML_MAY_THROW; #endif // defined(__cpp_lib_char8_t) @@ -423,7 +423,7 @@ TOML_START /// /// \returns With exceptions: A toml::table.
/// Without exceptions: A toml::parse_result detailing the parsing outcome. - [[nodiscard]] + [[nodiscard]] TOML_API parse_result operator"" _toml(const char* str, size_t len) noexcept; #if defined(__cpp_lib_char8_t) @@ -449,7 +449,7 @@ TOML_START /// Without exceptions: A toml::parse_result detailing the parsing outcome. /// /// \attention This overload is not available if your compiler does not support char8_t-based strings. - [[nodiscard]] + [[nodiscard]] TOML_API parse_result operator"" _toml(const char8_t* str, size_t len) noexcept; #endif diff --git a/include/toml++/toml_parser_impl.h b/include/toml++/toml_parser_impl.h index 6da093f..5cc4187 100644 --- a/include/toml++/toml_parser_impl.h +++ b/include/toml++/toml_parser_impl.h @@ -1,8 +1,6 @@ #pragma once #include "toml_parser.h" -#if TOML_IMPLEMENTATION - TOML_IMPL_START { #if TOML_EXCEPTIONS @@ -2903,7 +2901,8 @@ TOML_IMPL_START #undef TOML_ERROR #undef TOML_NORETURN - TOML_INLINE_FUNC_IMPL TOML_API + TOML_API + TOML_INLINE_FUNC_IMPL parse_result do_parse(utf8_reader_interface&& reader) TOML_MAY_THROW { return impl::parser{ std::move(reader) }; @@ -2913,13 +2912,15 @@ TOML_IMPL_END TOML_START { - TOML_INLINE_FUNC_IMPL TOML_API + TOML_API + TOML_INLINE_FUNC_IMPL parse_result parse(std::string_view doc, std::string_view source_path) TOML_MAY_THROW { return impl::do_parse(impl::utf8_reader{ doc, source_path }); } - TOML_INLINE_FUNC_IMPL TOML_API + TOML_API + TOML_INLINE_FUNC_IMPL parse_result parse(std::string_view doc, std::string&& source_path) TOML_MAY_THROW { return impl::do_parse(impl::utf8_reader{ doc, std::move(source_path) }); @@ -2927,13 +2928,15 @@ TOML_START #if defined(__cpp_lib_char8_t) - TOML_INLINE_FUNC_IMPL TOML_API + TOML_API + TOML_INLINE_FUNC_IMPL parse_result parse(std::u8string_view doc, std::string_view source_path) TOML_MAY_THROW { return impl::do_parse(impl::utf8_reader{ doc, source_path }); } - TOML_INLINE_FUNC_IMPL TOML_API + TOML_API + TOML_INLINE_FUNC_IMPL parse_result parse(std::u8string_view doc, std::string&& source_path) TOML_MAY_THROW { return impl::do_parse(impl::utf8_reader{ doc, std::move(source_path) }); @@ -2943,7 +2946,8 @@ TOML_START inline namespace literals { - TOML_INLINE_FUNC_IMPL TOML_API + TOML_API + TOML_INLINE_FUNC_IMPL parse_result operator"" _toml(const char* str, size_t len) noexcept { return parse(std::string_view{ str, len }); @@ -2951,7 +2955,8 @@ TOML_START #if defined(__cpp_lib_char8_t) - TOML_INLINE_FUNC_IMPL TOML_API + TOML_API + TOML_INLINE_FUNC_IMPL parse_result operator"" _toml(const char8_t* str, size_t len) noexcept { return parse(std::u8string_view{ str, len }); @@ -2961,5 +2966,3 @@ TOML_START } } TOML_END - -#endif // TOML_IMPLEMENTATION diff --git a/include/toml++/toml_table.h b/include/toml++/toml_table.h index 97c705e..a71574b 100644 --- a/include/toml++/toml_table.h +++ b/include/toml++/toml_table.h @@ -85,12 +85,10 @@ TOML_IMPL_START } }; - #if !TOML_ALL_INLINE - extern template struct table_proxy_pair; - extern template struct table_proxy_pair; - extern template class table_iterator; - extern template class table_iterator; - #endif + template struct table_proxy_pair; + template struct table_proxy_pair; + template class table_iterator; + template class table_iterator; struct table_init_pair final { @@ -120,6 +118,11 @@ TOML_IMPL_END TOML_START { + [[nodiscard]] TOML_API bool operator == (const table& lhs, const table& rhs) noexcept; + [[nodiscard]] TOML_API bool operator != (const table& lhs, const table& rhs) noexcept; + template + std::basic_ostream& operator << (std::basic_ostream&, const table&) TOML_MAY_THROW; + /// \brief A TOML table. /// /// \remarks The interface of this type is modeled after std::map, with some diff --git a/include/toml++/toml_table_impl.h b/include/toml++/toml_table_impl.h index a52c439..55f3d8a 100644 --- a/include/toml++/toml_table_impl.h +++ b/include/toml++/toml_table_impl.h @@ -2,17 +2,6 @@ #include "toml_table.h" #include "toml_node_view.h" -#if TOML_IMPLEMENTATION - -TOML_IMPL_START -{ - template struct table_proxy_pair; - template struct table_proxy_pair; - template class table_iterator; - template class table_iterator; -} -TOML_IMPL_END - TOML_START { TOML_INLINE_FUNC_IMPL @@ -137,7 +126,8 @@ TOML_START return do_contains(values, key); } - [[nodiscard]] TOML_INLINE_FUNC_IMPL + TOML_API + TOML_INLINE_FUNC_IMPL bool operator == (const table& lhs, const table& rhs) noexcept { if (&lhs == &rhs) @@ -166,12 +156,11 @@ TOML_START return true; } - [[nodiscard]] TOML_INLINE_FUNC_IMPL + TOML_API + TOML_INLINE_FUNC_IMPL bool operator != (const table& lhs, const table& rhs) noexcept { return !(lhs == rhs); } } TOML_END - -#endif // TOML_IMPLEMENTATION diff --git a/include/toml++/toml_value.h b/include/toml++/toml_value.h index 5f0fba7..7157dc3 100644 --- a/include/toml++/toml_value.h +++ b/include/toml++/toml_value.h @@ -15,7 +15,7 @@ TOML_START /// - toml::time /// - toml::date_time template - class value final : public node + class TOML_API value final : public node { static_assert( impl::is_value, @@ -337,6 +337,16 @@ TOML_START value(TOML_SMALL_INT_TYPE) -> value; #endif + #if !TOML_ALL_INLINE + extern template class TOML_API value; + extern template class TOML_API value; + extern template class TOML_API value; + extern template class TOML_API value; + extern template class TOML_API value; + extern template class TOML_API value