refactoring

This commit is contained in:
Mark Gillard 2021-11-15 09:06:03 +02:00
parent 9066ac7d01
commit 307ebd1f47
8 changed files with 60 additions and 83 deletions

View File

@ -72,7 +72,7 @@ code changes at callsites or in build systems are indicated with ⚠️.
- ⚠️ renamed `TOML_PARSER` option to `TOML_ENABLE_PARSER` (`TOML_PARSER` will continue to work but is deprecated) - ⚠️ renamed `TOML_PARSER` option to `TOML_ENABLE_PARSER` (`TOML_PARSER` will continue to work but is deprecated)
- ⚠️ renamed `TOML_UNRELEASED_FEATURES` to `TOML_ENABLE_UNRELEASED_FEATURES` (`TOML_UNRELEASED_FEATURES` will continue to work but is deprecated) - ⚠️ renamed `TOML_UNRELEASED_FEATURES` to `TOML_ENABLE_UNRELEASED_FEATURES` (`TOML_UNRELEASED_FEATURES` will continue to work but is deprecated)
- ⚠️ renamed `TOML_WINDOWS_COMPAT` to `TOML_ENABLE_WINDOWS_COMPAT` (`TOML_WINDOWS_COMPAT` will continue to work but is deprecated) - ⚠️ renamed `TOML_WINDOWS_COMPAT` to `TOML_ENABLE_WINDOWS_COMPAT` (`TOML_WINDOWS_COMPAT` will continue to work but is deprecated)
- `toml::table::ref()` now supports explicit ref categories and cv-qualifiers - `toml::node::ref()` now supports explicit ref categories and cv-qualifiers
- applied clang-format to all the things 🎉️ - applied clang-format to all the things 🎉️
- improved performance of parser - improved performance of parser
- made date/time constructors accept any integral types - made date/time constructors accept any integral types

View File

@ -58,8 +58,10 @@ int main(int argc, char** argv)
#else #else
const auto result = toml::parse(file_content, file_path); const auto result = toml::parse(file_content, file_path);
if (!result) if (!result)
{
std::cerr << result.error() << "\n"; std::cerr << result.error() << "\n";
return 1; return 1;
}
#endif #endif
} }

View File

@ -663,24 +663,7 @@ TOML_NAMESPACE_START
//# TOML_NODISCARD //# TOML_NODISCARD
//# std::vector<T> select() const noexcept; //# std::vector<T> select() const noexcept;
/// \brief Gets a raw reference to a value node's underlying data. /// \brief Gets a raw reference to a node's underlying data.
///
/// \note Providing explicit ref qualifiers acts as an explicit ref-category cast. Providing
/// explicit cv-ref qualifiers 'merges' them with whatever the cv qualification of the node is. Examples:
/// | node | T | return type |
/// |-------------|------------------------|------------------------------|
/// | node& | std::string | std::string& |
/// | node& | std::string& | std::string& |
/// | node& | std::string&& | std::string&& |
/// | node&& | std::string | std::string&& |
/// | node&& | std::string& | std::string& |
/// | node&& | std::string&& | std::string&& |
/// | const node& | std::string | const std::string& |
/// | const node& | std::string& | const std::string& |
/// | const node& | std::string&& | const std::string&& |
/// | const node& | volatile std::string | const volatile std::string& |
/// | const node& | volatile std::string& | const volatile std::string& |
/// | const node& | volatile std::string&& | const volatile std::string&& |
/// ///
/// \warning This function is dangerous if used carelessly and **WILL** break your code if the /// \warning This function is dangerous if used carelessly and **WILL** break your code if the
/// chosen value type doesn't match the node's actual type. In debug builds an assertion /// chosen value type doesn't match the node's actual type. In debug builds an assertion
@ -691,11 +674,21 @@ TOML_NAMESPACE_START
/// max = 45 /// max = 45
/// )"sv); /// )"sv);
/// ///
/// int64_t& min_ref = tbl.get("min")->ref<int64_t>(); // matching type /// int64_t& min_ref = tbl.at("min").ref<int64_t>(); // matching type
/// double& max_ref = tbl.get("max")->ref<double>(); // mismatched type, hits assert() /// double& max_ref = tbl.at("max").ref<double>(); // mismatched type, hits assert()
/// \ecpp /// \ecpp
/// ///
/// \tparam T One of the TOML value types. /// \note Specifying explicit ref qualifiers acts as an explicit ref-category cast,
/// whereas specifying explicit cv-ref qualifiers merges them with whatever
/// the cv qualification of the node is (to ensure cv-correctness is propagated), e.g.:
/// | node | T | return type |
/// |-------------|------------------------|------------------------------|
/// | node& | std::string | std::string& |
/// | node& | std::string&& | std::string&& |
/// | const node& | volatile std::string | const volatile std::string& |
/// | const node& | volatile std::string&& | const volatile std::string&& |
///
/// \tparam T toml::table, toml::array, or one of the TOML value types.
/// ///
/// \returns A reference to the underlying data. /// \returns A reference to the underlying data.
template <typename T> template <typename T>
@ -705,7 +698,7 @@ TOML_NAMESPACE_START
return do_ref<T>(*this); return do_ref<T>(*this);
} }
/// \brief Gets a raw reference to a value node's underlying data (rvalue overload). /// \brief Gets a raw reference to a node's underlying data (rvalue overload).
template <typename T> template <typename T>
TOML_PURE_GETTER TOML_PURE_GETTER
decltype(auto) ref() && noexcept decltype(auto) ref() && noexcept
@ -713,7 +706,7 @@ TOML_NAMESPACE_START
return do_ref<T>(std::move(*this)); return do_ref<T>(std::move(*this));
} }
/// \brief Gets a raw reference to a value node's underlying data (const lvalue overload). /// \brief Gets a raw reference to a node's underlying data (const lvalue overload).
template <typename T> template <typename T>
TOML_PURE_GETTER TOML_PURE_GETTER
decltype(auto) ref() const& noexcept decltype(auto) ref() const& noexcept
@ -721,7 +714,7 @@ TOML_NAMESPACE_START
return do_ref<T>(*this); return do_ref<T>(*this);
} }
/// \brief Gets a raw reference to a value node's underlying data (const rvalue overload). /// \brief Gets a raw reference to a node's underlying data (const rvalue overload).
template <typename T> template <typename T>
TOML_PURE_GETTER TOML_PURE_GETTER
decltype(auto) ref() const&& noexcept decltype(auto) ref() const&& noexcept

View File

@ -526,17 +526,6 @@ TOML_NAMESPACE_START
/// \brief Gets a raw reference to the viewed node's underlying data. /// \brief Gets a raw reference to the viewed node's underlying data.
/// ///
/// /// \note Providing explicit ref qualifiers acts as an explicit ref-category cast. Providing
/// explicit cv-ref qualifiers 'merges' them with whatever the cv qualification of the viewed node is. Examples:
/// | node | T | return type |
/// |-------------|------------------------|------------------------------|
/// | node | std::string | std::string& |
/// | node | std::string& | std::string& |
/// | node | std::string&& | std::string&& |
/// | const node | volatile std::string | const volatile std::string& |
/// | const node | volatile std::string& | const volatile std::string& |
/// | const node | volatile std::string&& | const volatile std::string&& |
///
/// \warning This function is dangerous if used carelessly and **WILL** break your code if the /// \warning This function is dangerous if used carelessly and **WILL** break your code if the
/// node_view didn't reference a node, or the chosen value type doesn't match the node's /// node_view didn't reference a node, or the chosen value type doesn't match the node's
/// actual type. In debug builds an assertion will fire when invalid accesses are attempted: \cpp /// actual type. In debug builds an assertion will fire when invalid accesses are attempted: \cpp
@ -551,6 +540,17 @@ TOML_NAMESPACE_START
/// int64_t& foo_ref = tbl["foo"].ref<int64_t>(); // nonexistent key, hits assert() /// int64_t& foo_ref = tbl["foo"].ref<int64_t>(); // nonexistent key, hits assert()
/// \ecpp /// \ecpp
/// ///
/// \note Specifying explicit ref qualifiers acts as an explicit ref-category cast,
/// whereas specifying explicit cv-ref qualifiers merges them with whatever
/// the cv qualification of the viewed node is (to ensure cv-correctness is propagated), e.g.:
/// | node_view | T | return type |
/// |-----------------------|------------------------|------------------------------|
/// | node_view<node> | std::string | std::string& |
/// | node_view<node> | std::string&& | std::string&& |
/// | node_view<const node> | volatile std::string | const volatile std::string& |
/// | node_view<const node> | volatile std::string&& | const volatile std::string&& |
///
///
/// \tparam T One of the TOML value types. /// \tparam T One of the TOML value types.
/// ///
/// \returns A reference to the underlying data. /// \returns A reference to the underlying data.

View File

@ -486,14 +486,6 @@
#error toml++ requires C++17 or higher. For a TOML library supporting pre-C++11 see https://github.com/ToruNiina/Boost.toml #error toml++ requires C++17 or higher. For a TOML library supporting pre-C++11 see https://github.com/ToruNiina/Boost.toml
#elif TOML_CPP_VERSION < 201703L #elif TOML_CPP_VERSION < 201703L
#error toml++ requires C++17 or higher. For a TOML library supporting C++11 see https://github.com/ToruNiina/toml11 #error toml++ requires C++17 or higher. For a TOML library supporting C++11 see https://github.com/ToruNiina/toml11
#elif TOML_CPP_VERSION >= 202600L
#define TOML_CPP 26
#elif TOML_CPP_VERSION >= 202300L
#define TOML_CPP 23
#elif TOML_CPP_VERSION >= 202002L
#define TOML_CPP 20
#elif TOML_CPP_VERSION >= 201703L
#define TOML_CPP 17
#endif #endif
#undef TOML_CPP_VERSION #undef TOML_CPP_VERSION
@ -809,24 +801,24 @@
#define TOML_LIB_SINGLE_HEADER 0 #define TOML_LIB_SINGLE_HEADER 0
#define TOML_MAKE_VERSION(maj, min, rev) \ #define TOML_MAKE_VERSION(major, minor, patch) \
((maj) * 1000 + (min) * 25 + (rev)) ((major) * 10000 + (minor) * 100 + (patch))
#if TOML_ENABLE_UNRELEASED_FEATURES #if TOML_ENABLE_UNRELEASED_FEATURES
#define TOML_LANG_EFFECTIVE_VERSION \ #define TOML_LANG_EFFECTIVE_VERSION \
TOML_MAKE_VERSION(TOML_LANG_MAJOR, TOML_LANG_MINOR, TOML_LANG_PATCH+1) TOML_MAKE_VERSION(TOML_LANG_MAJOR, TOML_LANG_MINOR, TOML_LANG_PATCH+1)
#else #else
#define TOML_LANG_EFFECTIVE_VERSION \ #define TOML_LANG_EFFECTIVE_VERSION \
TOML_MAKE_VERSION(TOML_LANG_MAJOR, TOML_LANG_MINOR, TOML_LANG_PATCH) TOML_MAKE_VERSION(TOML_LANG_MAJOR, TOML_LANG_MINOR, TOML_LANG_PATCH)
#endif #endif
#define TOML_LANG_HIGHER_THAN(maj, min, rev) \ #define TOML_LANG_HIGHER_THAN(major, minor, patch) \
(TOML_LANG_EFFECTIVE_VERSION > TOML_MAKE_VERSION(maj, min, rev)) (TOML_LANG_EFFECTIVE_VERSION > TOML_MAKE_VERSION(major, minor, patch))
#define TOML_LANG_AT_LEAST(maj, min, rev) \ #define TOML_LANG_AT_LEAST(major, minor, patch) \
(TOML_LANG_EFFECTIVE_VERSION >= TOML_MAKE_VERSION(maj, min, rev)) (TOML_LANG_EFFECTIVE_VERSION >= TOML_MAKE_VERSION(major, minor, patch))
#define TOML_LANG_UNRELEASED \ #define TOML_LANG_UNRELEASED \
TOML_LANG_HIGHER_THAN(TOML_LANG_MAJOR, TOML_LANG_MINOR, TOML_LANG_PATCH) TOML_LANG_HIGHER_THAN(TOML_LANG_MAJOR, TOML_LANG_MINOR, TOML_LANG_PATCH)
#ifndef TOML_ABI_NAMESPACES #ifndef TOML_ABI_NAMESPACES

View File

@ -779,12 +779,12 @@ TOML_NAMESPACE_START
{ {
if constexpr (std::is_same_v<value_type, double>) if constexpr (std::is_same_v<value_type, double>)
{ {
const auto lhs_class = impl::fpclassify(lhs.val_); const auto lhs_nan = impl::fpclassify(lhs.val_) == impl::fp_class::nan;
const auto rhs_class = impl::fpclassify(rhs); const auto rhs_nan = impl::fpclassify(rhs) == impl::fp_class::nan;
if (lhs_class == impl::fp_class::nan && rhs_class == impl::fp_class::nan) if (lhs_nan != rhs_nan)
return true;
if ((lhs_class == impl::fp_class::nan) != (rhs_class == impl::fp_class::nan))
return false; return false;
if (lhs_nan)
return true;
} }
return lhs.val_ == rhs; return lhs.val_ == rhs;
} }

View File

@ -90,7 +90,6 @@ TOML_POP_WARNINGS;
#undef TOML_CONST_GETTER #undef TOML_CONST_GETTER
#undef TOML_CONST_INLINE_GETTER #undef TOML_CONST_INLINE_GETTER
#undef TOML_CONSTRAINED_TEMPLATE #undef TOML_CONSTRAINED_TEMPLATE
#undef TOML_CPP
#undef TOML_DISABLE_ARITHMETIC_WARNINGS #undef TOML_DISABLE_ARITHMETIC_WARNINGS
#undef TOML_DISABLE_CODE_ANALYSIS_WARNINGS #undef TOML_DISABLE_CODE_ANALYSIS_WARNINGS
#undef TOML_DISABLE_SPAM_WARNINGS #undef TOML_DISABLE_SPAM_WARNINGS

View File

@ -501,14 +501,6 @@
#error toml++ requires C++17 or higher. For a TOML library supporting pre-C++11 see https://github.com/ToruNiina/Boost.toml #error toml++ requires C++17 or higher. For a TOML library supporting pre-C++11 see https://github.com/ToruNiina/Boost.toml
#elif TOML_CPP_VERSION < 201703L #elif TOML_CPP_VERSION < 201703L
#error toml++ requires C++17 or higher. For a TOML library supporting C++11 see https://github.com/ToruNiina/toml11 #error toml++ requires C++17 or higher. For a TOML library supporting C++11 see https://github.com/ToruNiina/toml11
#elif TOML_CPP_VERSION >= 202600L
#define TOML_CPP 26
#elif TOML_CPP_VERSION >= 202300L
#define TOML_CPP 23
#elif TOML_CPP_VERSION >= 202002L
#define TOML_CPP 20
#elif TOML_CPP_VERSION >= 201703L
#define TOML_CPP 17
#endif #endif
#undef TOML_CPP_VERSION #undef TOML_CPP_VERSION
@ -808,24 +800,24 @@
#define TOML_LIB_SINGLE_HEADER 1 #define TOML_LIB_SINGLE_HEADER 1
#define TOML_MAKE_VERSION(maj, min, rev) \ #define TOML_MAKE_VERSION(major, minor, patch) \
((maj) * 1000 + (min) * 25 + (rev)) ((major) * 10000 + (minor) * 100 + (patch))
#if TOML_ENABLE_UNRELEASED_FEATURES #if TOML_ENABLE_UNRELEASED_FEATURES
#define TOML_LANG_EFFECTIVE_VERSION \ #define TOML_LANG_EFFECTIVE_VERSION \
TOML_MAKE_VERSION(TOML_LANG_MAJOR, TOML_LANG_MINOR, TOML_LANG_PATCH+1) TOML_MAKE_VERSION(TOML_LANG_MAJOR, TOML_LANG_MINOR, TOML_LANG_PATCH+1)
#else #else
#define TOML_LANG_EFFECTIVE_VERSION \ #define TOML_LANG_EFFECTIVE_VERSION \
TOML_MAKE_VERSION(TOML_LANG_MAJOR, TOML_LANG_MINOR, TOML_LANG_PATCH) TOML_MAKE_VERSION(TOML_LANG_MAJOR, TOML_LANG_MINOR, TOML_LANG_PATCH)
#endif #endif
#define TOML_LANG_HIGHER_THAN(maj, min, rev) \ #define TOML_LANG_HIGHER_THAN(major, minor, patch) \
(TOML_LANG_EFFECTIVE_VERSION > TOML_MAKE_VERSION(maj, min, rev)) (TOML_LANG_EFFECTIVE_VERSION > TOML_MAKE_VERSION(major, minor, patch))
#define TOML_LANG_AT_LEAST(maj, min, rev) \ #define TOML_LANG_AT_LEAST(major, minor, patch) \
(TOML_LANG_EFFECTIVE_VERSION >= TOML_MAKE_VERSION(maj, min, rev)) (TOML_LANG_EFFECTIVE_VERSION >= TOML_MAKE_VERSION(major, minor, patch))
#define TOML_LANG_UNRELEASED \ #define TOML_LANG_UNRELEASED \
TOML_LANG_HIGHER_THAN(TOML_LANG_MAJOR, TOML_LANG_MINOR, TOML_LANG_PATCH) TOML_LANG_HIGHER_THAN(TOML_LANG_MAJOR, TOML_LANG_MINOR, TOML_LANG_PATCH)
#ifndef TOML_ABI_NAMESPACES #ifndef TOML_ABI_NAMESPACES
@ -4278,12 +4270,12 @@ TOML_NAMESPACE_START
{ {
if constexpr (std::is_same_v<value_type, double>) if constexpr (std::is_same_v<value_type, double>)
{ {
const auto lhs_class = impl::fpclassify(lhs.val_); const auto lhs_nan = impl::fpclassify(lhs.val_) == impl::fp_class::nan;
const auto rhs_class = impl::fpclassify(rhs); const auto rhs_nan = impl::fpclassify(rhs) == impl::fp_class::nan;
if (lhs_class == impl::fp_class::nan && rhs_class == impl::fp_class::nan) if (lhs_nan != rhs_nan)
return true;
if ((lhs_class == impl::fp_class::nan) != (rhs_class == impl::fp_class::nan))
return false; return false;
if (lhs_nan)
return true;
} }
return lhs.val_ == rhs; return lhs.val_ == rhs;
} }
@ -15320,7 +15312,6 @@ TOML_POP_WARNINGS;
#undef TOML_CONST_GETTER #undef TOML_CONST_GETTER
#undef TOML_CONST_INLINE_GETTER #undef TOML_CONST_INLINE_GETTER
#undef TOML_CONSTRAINED_TEMPLATE #undef TOML_CONSTRAINED_TEMPLATE
#undef TOML_CPP
#undef TOML_DISABLE_ARITHMETIC_WARNINGS #undef TOML_DISABLE_ARITHMETIC_WARNINGS
#undef TOML_DISABLE_CODE_ANALYSIS_WARNINGS #undef TOML_DISABLE_CODE_ANALYSIS_WARNINGS
#undef TOML_DISABLE_SPAM_WARNINGS #undef TOML_DISABLE_SPAM_WARNINGS