//# 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_preprocessor.h" //#==================================================================================================================== //# INCLUDES //#==================================================================================================================== TOML_PUSH_WARNINGS TOML_DISABLE_ALL_WARNINGS #include #include #include #include #include #include #include #include #include #include #include #include #if !TOML_HAS_CUSTOM_OPTIONAL_TYPE #include #endif #if TOML_HAS_INCLUDE() #include #endif TOML_POP_WARNINGS #ifdef __cpp_lib_launder #define TOML_LAUNDER(x) std::launder(x) #else #define TOML_LAUNDER(x) x #endif //#==================================================================================================================== //# ENVIRONMENT GROUND-TRUTHS //#==================================================================================================================== #ifndef DOXYGEN #ifndef TOML_DISABLE_ENVIRONMENT_CHECKS #define TOML_ENV_MESSAGE \ "If you're seeing this error it's because you're building toml++ for an environment that doesn't conform to " \ "one of the 'ground truths' assumed by the library. Essentially this just means that I don't have the " \ "resources to test on more esoteric platforms, but I wish I did! You can try disabling the checks by defining " \ "TOML_DISABLE_ENVIRONMENT_CHECKS, but your mileage may vary. Please consider filing an issue at " \ "https://github.com/marzer/tomlplusplus/issues to help me improve support for your target environment. Thanks!" static_assert(CHAR_BIT == 8, TOML_ENV_MESSAGE); static_assert(FLT_RADIX == 2, TOML_ENV_MESSAGE); static_assert('A' == 65, TOML_ENV_MESSAGE); static_assert(sizeof(double) == 8, TOML_ENV_MESSAGE); static_assert(std::numeric_limits::is_iec559, TOML_ENV_MESSAGE); static_assert(std::numeric_limits::digits == 53, TOML_ENV_MESSAGE); static_assert(std::numeric_limits::digits10 == 15, TOML_ENV_MESSAGE); #undef TOML_ENV_MESSAGE #endif // !TOML_DISABLE_ENVIRONMENT_CHECKS #endif // !DOXYGEN //#==================================================================================================================== //# UNDOCUMENTED TYPEDEFS AND FORWARD DECLARATIONS //#==================================================================================================================== #ifndef DOXYGEN // undocumented forward declarations are hidden from doxygen because they fuck it up =/ TOML_PUSH_WARNINGS TOML_DISABLE_PADDING_WARNINGS namespace toml // non-abi namespace; this is not an error { using namespace std::string_literals; using namespace std::string_view_literals; using ::std::size_t; using ::std::intptr_t; using ::std::uintptr_t; using ::std::ptrdiff_t; using ::std::nullptr_t; using ::std::int8_t; using ::std::int16_t; using ::std::int32_t; using ::std::int64_t; using ::std::uint8_t; using ::std::uint16_t; using ::std::uint32_t; using ::std::uint64_t; // legacy typedefs using string_char = char; using string = std::string; using string_view = std::string_view; } TOML_NAMESPACE_START // abi namespace { struct date; struct time; struct time_offset; TOML_ABI_NAMESPACE_BOOL(TOML_HAS_CUSTOM_OPTIONAL_TYPE, custopt, stdopt) struct date_time; TOML_ABI_NAMESPACE_END class node; class array; class table; template class node_view; template class value; template class default_formatter; template class json_formatter; [[nodiscard]] TOML_API bool operator == (const array& lhs, const array& rhs) noexcept; [[nodiscard]] TOML_API bool operator != (const array& lhs, const array& rhs) noexcept; [[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 array&); template std::basic_ostream& operator << (std::basic_ostream&, const value&); template std::basic_ostream& operator << (std::basic_ostream&, const table&); template std::basic_ostream& operator << (std::basic_ostream&, default_formatter&); template std::basic_ostream& operator << (std::basic_ostream&, default_formatter&&); template std::basic_ostream& operator << (std::basic_ostream&, json_formatter&); template std::basic_ostream& operator << (std::basic_ostream&, json_formatter&&); template inline std::basic_ostream& operator << (std::basic_ostream&, const node_view&); namespace impl { template using string_map = std::map>; // heterogeneous lookup template using remove_cvref_t = std::remove_cv_t>; template inline constexpr bool is_one_of = (false || ... || std::is_same_v); template inline constexpr bool is_cvref = std::is_reference_v || std::is_const_v || std::is_volatile_v; template inline constexpr bool is_wide_string = is_one_of< std::decay_t, const wchar_t*, wchar_t*, std::wstring_view, std::wstring >; template inline constexpr bool dependent_false = false; #define TOML_P2S_DECL(Type) \ template \ inline void print_to_stream(Type, std::basic_ostream&) TOML_P2S_DECL(int8_t); TOML_P2S_DECL(int16_t); TOML_P2S_DECL(int32_t); TOML_P2S_DECL(int64_t); TOML_P2S_DECL(uint8_t); TOML_P2S_DECL(uint16_t); TOML_P2S_DECL(uint32_t); TOML_P2S_DECL(uint64_t); TOML_P2S_DECL(float); TOML_P2S_DECL(const date&); TOML_P2S_DECL(const time&); TOML_P2S_DECL(time_offset); TOML_P2S_DECL(const date_time&); #undef TOML_P2S_DECL #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 [[nodiscard]] TOML_API std::wstring widen(std::u8string_view) noexcept; #endif #endif // TOML_WINDOWS_COMPAT #if TOML_ABI_NAMESPACES #if TOML_EXCEPTIONS TOML_ABI_NAMESPACE_START(ex) #define TOML_PARSER_TYPENAME TOML_NAMESPACE::impl::ex::parser #else TOML_ABI_NAMESPACE_START(noex) #define TOML_PARSER_TYPENAME TOML_NAMESPACE::impl::noex::parser #endif #else #define TOML_PARSER_TYPENAME TOML_NAMESPACE::impl::parser #endif class parser; TOML_ABI_NAMESPACE_END // TOML_EXCEPTIONS } } TOML_NAMESPACE_END TOML_POP_WARNINGS // TOML_DISABLE_PADDING_WARNINGS #endif // !DOXYGEN //#==================================================================================================================== //# TYPEDEFS AND FORWARD DECLARATIONS //#==================================================================================================================== /// \brief The root namespace for all toml++ functions and types. namespace toml { } TOML_NAMESPACE_START // abi namespace { /// \brief Convenience literal operators for working with toml++. /// /// \detail This namespace exists so you can safely hoist the toml++ literal operators into another scope /// without dragging in everything from the toml namespace: \cpp /// /// #include /// using namespace toml::literals; /// /// int main() /// { /// toml::table tbl = "vals = [1, 2, 3]"_toml; /// /// // ... do stuff with the table generated by the "_toml" literal ... /// /// return 0; /// } /// \ecpp /// inline namespace literals {} #if TOML_HAS_CUSTOM_OPTIONAL_TYPE template using optional = TOML_OPTIONAL_TYPE; #else /// \brief The 'optional' type used throughout the library. /// /// \remarks By default this will be an alias for std::optional, but you can change the optional type /// used by the library by defining #TOML_OPTIONAL_TYPE. template using optional = std::optional; #endif /// \brief TOML node type identifiers. enum class node_type : uint8_t { none, ///< Not-a-node. table, ///< The node is a toml::table. array, ///< The node is a toml::array. string, ///< The node is a toml::value. integer, ///< The node is a toml::value. floating_point, ///< The node is a toml::value. boolean, ///< The node is a toml::value. date, ///< The node is a toml::value. time, ///< The node is a toml::value