From 4aaf009dbbabbf16953af130c9edef3253c5902f Mon Sep 17 00:00:00 2001 From: BearOso Date: Wed, 28 Jun 2023 13:59:37 -0500 Subject: [PATCH] Use Qt ini file implementation. --- qt/src/EmuConfig.cpp | 91 +- qt/src/toml.hpp | 11869 ----------------------------------------- 2 files changed, 29 insertions(+), 11931 deletions(-) delete mode 100644 qt/src/toml.hpp diff --git a/qt/src/EmuConfig.cpp b/qt/src/EmuConfig.cpp index 5be54b10..a87843b4 100644 --- a/qt/src/EmuConfig.cpp +++ b/qt/src/EmuConfig.cpp @@ -1,15 +1,13 @@ #include #include -#define TOML_LARGE_FILES 1 -#define TOML_IMPLEMENTATION 1 #include -#include "toml.hpp" #include namespace fs = std::filesystem; #include "EmuConfig.hpp" #include "EmuBinding.hpp" #include +#include static const char *shortcut_names[] = { @@ -307,9 +305,7 @@ void EmuConfig::setDefaults(int section) void EmuConfig::config(std::string filename, bool write) { - toml::table root; - toml::table *table = nullptr; - std::string section; + QSettings settings(QString::fromStdString(filename), QSettings::IniFormat); std::function Bool; std::function Int; @@ -323,76 +319,63 @@ void EmuConfig::config(std::string filename, bool write) if (write) { Bool = [&](std::string key, bool &value) { - table->insert_or_assign(key, value); + settings.setValue(key, value); }; Int = [&](std::string key, int &value) { - table->insert_or_assign(key, value); + settings.setValue(key, value); }; String = [&](std::string key, std::string &value) { - table->insert_or_assign(key, value); + settings.setValue(key, QString::fromStdString(value)); }; Enum = [&](std::string key, int &value, std::vector map) { - table->insert_or_assign(key, map[value]); + settings.setValue(key, map[value]); }; Double = [&](std::string key, double &value) { - table->insert_or_assign(key, value); + settings.setValue(key, value); }; Binding = [&](std::string key, EmuBinding &binding) { - table->insert_or_assign(key, binding.to_config_string()); + settings.setValue(key, QString::fromStdString(binding.to_config_string())); }; BeginSection = [&](std::string str) { - section = str; - table = new toml::table; + settings.beginGroup(str); }; - EndSection = [&]() { - root.insert_or_assign(section, *table); - delete table; + settings.endGroup(); }; - - root.clear(); } else { Bool = [&](std::string key, bool &value) { - if (table && table->contains(key) && table->get(key)->is_boolean()) - value = table->get(key)->as_boolean()->get(); + if (settings.contains(key)) + value = settings.value(key).toBool(); }; Int = [&](std::string key, int &value) { - if (table && table->contains(key) && table->get(key)->is_integer()) - value = table->get(key)->as_integer()->get(); + if (settings.contains(key)) + value = settings.value(key).toInt(); }; String = [&](std::string key, std::string &value) { - if (table && table->contains(key) && table->get(key)->is_string()) - value = table->get(key)->as_string()->get(); + if (settings.contains(key)) + value = settings.value(key).toString().toStdString(); }; Binding = [&](std::string key, EmuBinding &binding) { - if (table && table->contains(key) && table->get(key)->is_string()) - binding = EmuBinding::from_config_string(table->get(key)->as_string()->get()); + if (settings.contains(key)) + binding = EmuBinding::from_config_string(settings.value(key).toString().toStdString()); }; Double = [&](std::string key, double &value) { - if (table && table->contains(key) && table->get(key)->is_floating_point()) - value = table->get(key)->as_floating_point()->get(); + if (settings.contains(key)) + value = settings.value(key).toDouble(); }; Enum = [&](std::string key, int &value, std::vector map) { - std::string entry; + QString entry; - if (table && table->contains(key) && table->get(key)->is_string()) - entry = table->get(key)->as_string()->get(); - else + if (settings.contains(key)) + entry = settings.value(key).toString().toLower(); + else return; - auto tolower = [](std::string str) -> std::string { - for (auto &c : str) - if (c >= 'A' && c <= 'Z') - c += ('a' - 'A'); - return str; - }; - - entry = tolower(entry); for (size_t i = 0; i < map.size(); i++) { - if (tolower(map[i]) == entry) + if (QString(map[i]).toLower() == entry) { value = i; return; @@ -400,20 +383,11 @@ void EmuConfig::config(std::string filename, bool write) } }; BeginSection = [&](std::string str) { - section = str; - auto root_section = root.get(section); - if (root_section) - table = root_section->as_table(); - else - table = nullptr; + settings.beginGroup(QString::fromStdString(str)); }; EndSection = [&]() { + settings.endGroup(); }; - - auto parse_result = toml::parse_file(filename); - if (parse_result.failed()) - return; - root = std::move(parse_result.table()); } BeginSection("Operational"); @@ -494,10 +468,10 @@ void EmuConfig::config(std::string filename, bool write) Enum("SoundFilter", sound_filter, { "Gaussian", "Nearest", "Linear", "Cubic", "Sinc" }); EndSection(); - const char *names[] = { "Up", "Down", "Left", "Right", "A", "B", "X", "Y", "L", "R", "Start", "Select", "Turbo A", "Turbo B", "Turbo X", "Turbo Y", "Turbo L", "Turbo R" }; + const char *names[] = { "Up", "Down", "Left", "Right", "A", "B", "X", "Y", "L", "R", "Start", "Select", "Turbo_A", "Turbo_B", "Turbo_X", "Turbo_Y", "Turbo_L", "Turbo_R" }; for (int c = 0; c < 5; c++) { - BeginSection("Controller " + std::to_string(c)); + BeginSection("Controller_" + std::to_string(c)); for (int y = 0; y < num_controller_bindings; y++) for (int x = 0; x < allowed_bindings; x++) @@ -534,13 +508,6 @@ void EmuConfig::config(std::string filename, bool write) Int("SRAMSaveInterval", sram_save_interval); EndSection(); - - if (write) - { - std::ofstream ofs(filename); - ofs << root; - ofs.close(); - } } void EmuConfig::setVRRConfig(bool enable) diff --git a/qt/src/toml.hpp b/qt/src/toml.hpp deleted file mode 100644 index 6ce4617d..00000000 --- a/qt/src/toml.hpp +++ /dev/null @@ -1,11869 +0,0 @@ -//---------------------------------------------------------------------------------------------------------------------- -// -// toml++ v2.1.0 -// https://github.com/marzer/tomlplusplus -// SPDX-License-Identifier: MIT -// -//---------------------------------------------------------------------------------------------------------------------- -// -// - THIS FILE WAS ASSEMBLED FROM MULTIPLE HEADER FILES BY A SCRIPT - PLEASE DON'T EDIT IT DIRECTLY - -// -// If you wish to submit a contribution to toml++, hooray and thanks! Before you crack on, please be aware that this -// file was assembled from a number of smaller files by a python script, and code contributions should not be made -// against it directly. You should instead make your changes in the relevant source file(s). The file names of the files -// that contributed to this header can be found at the beginnings and ends of the corresponding sections of this file. -// -//---------------------------------------------------------------------------------------------------------------------- -// -// TOML Language Specifications: -// latest: https://github.com/toml-lang/toml/blob/master/README.md -// v1.0.0-rc.2: https://toml.io/en/v1.0.0-rc.2 -// v1.0.0-rc.1: https://toml.io/en/v1.0.0-rc.1 -// v0.5.0: https://toml.io/en/v0.5.0 -// changelog: https://github.com/toml-lang/toml/blob/master/CHANGELOG.md -// -//---------------------------------------------------------------------------------------------------------------------- -// -// MIT License -// -// Copyright (c) 2019-2020 Mark Gillard -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated -// documentation files (the "Software"), to deal in the Software without restriction, including without limitation the -// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the -// Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE -// WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -// -//---------------------------------------------------------------------------------------------------------------------- -#ifndef INCLUDE_TOMLPLUSPLUS_H -#define INCLUDE_TOMLPLUSPLUS_H - -#if 1 //------ ↓ toml_preprocessor.h -------------------------------------------------------------------------------- - -#ifndef __cplusplus - #error toml++ is a C++ library. -#endif - -#ifdef __INTELLISENSE__ - #define TOML_INTELLISENSE 1 -#else - #define TOML_INTELLISENSE 0 -#endif -#ifdef __clang__ - #define TOML_CLANG __clang_major__ -#else - #define TOML_CLANG 0 -#endif -#ifdef __INTEL_COMPILER - #define TOML_ICC __INTEL_COMPILER - #ifdef __ICL - #define TOML_ICC_CL TOML_ICC - #else - #define TOML_ICC_CL 0 - #endif -#else - #define TOML_ICC 0 - #define TOML_ICC_CL 0 -#endif -#if defined(_MSC_VER) && !TOML_CLANG && !TOML_ICC - #define TOML_MSVC _MSC_VER -#else - #define TOML_MSVC 0 -#endif -#if defined(__GNUC__) && !TOML_CLANG && !TOML_ICC - #define TOML_GCC __GNUC__ -#else - #define TOML_GCC 0 -#endif - -#if TOML_CLANG - - #define TOML_PUSH_WARNINGS _Pragma("clang diagnostic push") - #define TOML_DISABLE_SWITCH_WARNINGS _Pragma("clang diagnostic ignored \"-Wswitch\"") - #define TOML_DISABLE_INIT_WARNINGS _Pragma("clang diagnostic ignored \"-Wmissing-field-initializers\"") - #define TOML_DISABLE_ARITHMETIC_WARNINGS _Pragma("clang diagnostic ignored \"-Wfloat-equal\"") \ - _Pragma("clang diagnostic ignored \"-Wdouble-promotion\"") \ - _Pragma("clang diagnostic ignored \"-Wchar-subscripts\"") \ - _Pragma("clang diagnostic ignored \"-Wshift-sign-overflow\"") - #define TOML_DISABLE_SHADOW_WARNINGS _Pragma("clang diagnostic ignored \"-Wshadow\"") - #define TOML_DISABLE_SPAM_WARNINGS _Pragma("clang diagnostic ignored \"-Wweak-vtables\"") \ - _Pragma("clang diagnostic ignored \"-Wweak-template-vtables\"") \ - _Pragma("clang diagnostic ignored \"-Wpadded\"") - #define TOML_POP_WARNINGS _Pragma("clang diagnostic pop") - #define TOML_DISABLE_WARNINGS TOML_PUSH_WARNINGS \ - _Pragma("clang diagnostic ignored \"-Weverything\"") - #define TOML_ENABLE_WARNINGS TOML_POP_WARNINGS - #define TOML_ASSUME(cond) __builtin_assume(cond) - #define TOML_UNREACHABLE __builtin_unreachable() - #define TOML_ATTR(...) __attribute__((__VA_ARGS__)) - #if defined(_MSC_VER) // msvc compat mode - #ifdef __has_declspec_attribute - #if __has_declspec_attribute(novtable) - #define TOML_INTERFACE __declspec(novtable) - #endif - #if __has_declspec_attribute(empty_bases) - #define TOML_EMPTY_BASES __declspec(empty_bases) - #endif - #ifndef TOML_ALWAYS_INLINE - #define TOML_ALWAYS_INLINE __forceinline - #endif - #if __has_declspec_attribute(noinline) - #define TOML_NEVER_INLINE __declspec(noinline) - #endif - #endif - #endif - #ifdef __has_attribute - #if !defined(TOML_ALWAYS_INLINE) && __has_attribute(always_inline) - #define TOML_ALWAYS_INLINE __attribute__((__always_inline__)) inline - #endif - #if !defined(TOML_NEVER_INLINE) && __has_attribute(noinline) - #define TOML_NEVER_INLINE __attribute__((__noinline__)) - #endif - #if !defined(TOML_TRIVIAL_ABI) && __has_attribute(trivial_abi) - #define TOML_TRIVIAL_ABI __attribute__((__trivial_abi__)) - #endif - #endif - #define TOML_LIKELY(...) (__builtin_expect(!!(__VA_ARGS__), 1) ) - #define TOML_UNLIKELY(...) (__builtin_expect(!!(__VA_ARGS__), 0) ) - - //floating-point from_chars and to_chars are not implemented in any version of clang as of 1/1/2020 - #ifndef TOML_FLOAT_CHARCONV - #define TOML_FLOAT_CHARCONV 0 - #endif - - #define TOML_SIMPLE_STATIC_ASSERT_MESSAGES 1 - -#endif // clang - -#if TOML_MSVC || TOML_ICC_CL - - #define TOML_CPP_VERSION _MSVC_LANG - #define TOML_PUSH_WARNINGS __pragma(warning(push)) - #if TOML_MSVC // !intel-cl - #define TOML_PUSH_WARNINGS __pragma(warning(push)) - #define TOML_DISABLE_SWITCH_WARNINGS __pragma(warning(disable: 4063)) - #define TOML_POP_WARNINGS __pragma(warning(pop)) - #define TOML_DISABLE_WARNINGS __pragma(warning(push, 0)) - #define TOML_ENABLE_WARNINGS TOML_POP_WARNINGS - #endif - #ifndef TOML_ALWAYS_INLINE - #define TOML_ALWAYS_INLINE __forceinline - #endif - #define TOML_NEVER_INLINE __declspec(noinline) - #define TOML_ASSUME(cond) __assume(cond) - #define TOML_UNREACHABLE __assume(0) - #define TOML_INTERFACE __declspec(novtable) - #define TOML_EMPTY_BASES __declspec(empty_bases) - #if !defined(TOML_RELOPS_REORDERING) && defined(__cpp_impl_three_way_comparison) - #define TOML_RELOPS_REORDERING 1 - #endif - -#endif // msvc - -#if TOML_ICC - - #define TOML_PUSH_WARNINGS __pragma(warning(push)) - #define TOML_DISABLE_SPAM_WARNINGS __pragma(warning(disable: 82)) /* storage class is not first */ \ - __pragma(warning(disable: 111)) /* statement unreachable (false-positive) */ \ - __pragma(warning(disable: 1011)) /* missing return (false-positive) */ \ - __pragma(warning(disable: 2261)) /* assume expr side-effects discarded */ - #define TOML_POP_WARNINGS __pragma(warning(pop)) - #define TOML_DISABLE_WARNINGS __pragma(warning(push, 0)) - #define TOML_ENABLE_WARNINGS TOML_POP_WARNINGS - -#endif // icc - -#if TOML_GCC - - #define TOML_PUSH_WARNINGS _Pragma("GCC diagnostic push") - #define TOML_DISABLE_SWITCH_WARNINGS _Pragma("GCC diagnostic ignored \"-Wswitch\"") \ - _Pragma("GCC diagnostic ignored \"-Wswitch-enum\"") \ - _Pragma("GCC diagnostic ignored \"-Wswitch-default\"") - #define TOML_DISABLE_INIT_WARNINGS _Pragma("GCC diagnostic ignored \"-Wmissing-field-initializers\"") \ - _Pragma("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") \ - _Pragma("GCC diagnostic ignored \"-Wuninitialized\"") - #define TOML_DISABLE_ARITHMETIC_WARNINGS _Pragma("GCC diagnostic ignored \"-Wfloat-equal\"") \ - _Pragma("GCC diagnostic ignored \"-Wsign-conversion\"") \ - _Pragma("GCC diagnostic ignored \"-Wchar-subscripts\"") - #define TOML_DISABLE_SHADOW_WARNINGS _Pragma("GCC diagnostic ignored \"-Wshadow\"") - #define TOML_DISABLE_SPAM_WARNINGS _Pragma("GCC diagnostic ignored \"-Wpadded\"") \ - _Pragma("GCC diagnostic ignored \"-Wcast-align\"") \ - _Pragma("GCC diagnostic ignored \"-Wcomment\"") \ - _Pragma("GCC diagnostic ignored \"-Wtype-limits\"") \ - _Pragma("GCC diagnostic ignored \"-Wsuggest-attribute=const\"") \ - _Pragma("GCC diagnostic ignored \"-Wsuggest-attribute=pure\"") - #define TOML_POP_WARNINGS _Pragma("GCC diagnostic pop") - #define TOML_DISABLE_WARNINGS TOML_PUSH_WARNINGS \ - _Pragma("GCC diagnostic ignored \"-Wall\"") \ - _Pragma("GCC diagnostic ignored \"-Wextra\"") \ - _Pragma("GCC diagnostic ignored \"-Wpedantic\"") \ - TOML_DISABLE_SWITCH_WARNINGS \ - TOML_DISABLE_INIT_WARNINGS \ - TOML_DISABLE_ARITHMETIC_WARNINGS \ - TOML_DISABLE_SHADOW_WARNINGS \ - TOML_DISABLE_SPAM_WARNINGS - #define TOML_ENABLE_WARNINGS TOML_POP_WARNINGS - - #define TOML_ATTR(...) __attribute__((__VA_ARGS__)) - #ifndef TOML_ALWAYS_INLINE - #define TOML_ALWAYS_INLINE __attribute__((__always_inline__)) inline - #endif - #define TOML_NEVER_INLINE __attribute__((__noinline__)) - #define TOML_UNREACHABLE __builtin_unreachable() - #if !defined(TOML_RELOPS_REORDERING) && defined(__cpp_impl_three_way_comparison) - #define TOML_RELOPS_REORDERING 1 - #endif - #define TOML_LIKELY(...) (__builtin_expect(!!(__VA_ARGS__), 1) ) - #define TOML_UNLIKELY(...) (__builtin_expect(!!(__VA_ARGS__), 0) ) - - // floating-point from_chars and to_chars are not implemented in any version of gcc as of 1/1/2020 - #ifndef TOML_FLOAT_CHARCONV - #define TOML_FLOAT_CHARCONV 0 - #endif - -#endif - -#ifdef TOML_CONFIG_HEADER - #include TOML_CONFIG_HEADER -#endif - -#ifdef DOXYGEN - #define TOML_HEADER_ONLY 0 - #define TOML_WINDOWS_COMPAT 1 -#endif - -#if defined(TOML_ALL_INLINE) && !defined(TOML_HEADER_ONLY) - #define TOML_HEADER_ONLY TOML_ALL_INLINE -#endif - -#if !defined(TOML_HEADER_ONLY) || (defined(TOML_HEADER_ONLY) && TOML_HEADER_ONLY) || TOML_INTELLISENSE - #undef TOML_HEADER_ONLY - #define TOML_HEADER_ONLY 1 -#endif - -#if defined(TOML_IMPLEMENTATION) || TOML_HEADER_ONLY - #undef TOML_IMPLEMENTATION - #define TOML_IMPLEMENTATION 1 -#else - #define TOML_IMPLEMENTATION 0 -#endif - -#ifndef TOML_API - #define TOML_API -#endif - -#ifndef TOML_UNRELEASED_FEATURES - #define TOML_UNRELEASED_FEATURES 0 -#endif - -#ifndef TOML_LARGE_FILES - #define TOML_LARGE_FILES 0 -#endif - -#ifndef TOML_UNDEF_MACROS - #define TOML_UNDEF_MACROS 1 -#endif - -#ifndef TOML_PARSER - #define TOML_PARSER 1 -#endif - -#ifndef DOXYGEN - #if defined(_WIN32) && !defined(TOML_WINDOWS_COMPAT) - #define TOML_WINDOWS_COMPAT 1 - #endif - #if !defined(_WIN32) || !defined(TOML_WINDOWS_COMPAT) - #undef TOML_WINDOWS_COMPAT - #define TOML_WINDOWS_COMPAT 0 - #endif -#endif - -#ifdef TOML_OPTIONAL_TYPE - #define TOML_HAS_CUSTOM_OPTIONAL_TYPE 1 -#else - #define TOML_HAS_CUSTOM_OPTIONAL_TYPE 0 -#endif - -#ifdef TOML_CHAR_8_STRINGS - #if TOML_CHAR_8_STRINGS - #error TOML_CHAR_8_STRINGS was removed in toml++ 2.0.0; \ -all value setters and getters can now work with char8_t strings implicitly so changing the underlying string type \ -is no longer necessary. - #endif -#endif - -#ifndef TOML_CPP_VERSION - #define TOML_CPP_VERSION __cplusplus -#endif -#if TOML_CPP_VERSION < 201103L - #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 - #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 -#undef TOML_CPP_VERSION - -#ifdef __has_include - #define TOML_HAS_INCLUDE(header) __has_include(header) -#else - #define TOML_HAS_INCLUDE(header) 0 -#endif - -#define TOML_COMPILER_EXCEPTIONS 0 -#if TOML_COMPILER_EXCEPTIONS - #if !defined(TOML_EXCEPTIONS) || (defined(TOML_EXCEPTIONS) && TOML_EXCEPTIONS) - #undef TOML_EXCEPTIONS - #define TOML_EXCEPTIONS 1 - #endif -#else - #if defined(TOML_EXCEPTIONS) && TOML_EXCEPTIONS - #error TOML_EXCEPTIONS was explicitly enabled but exceptions are disabled/unsupported by the compiler. - #endif - #undef TOML_EXCEPTIONS - #define TOML_EXCEPTIONS 0 -#endif - -#if TOML_EXCEPTIONS - #define TOML_MAY_THROW -#else - #define TOML_MAY_THROW noexcept -#endif - -#ifndef TOML_INT_CHARCONV - #define TOML_INT_CHARCONV 1 -#endif -#ifndef TOML_FLOAT_CHARCONV - #define TOML_FLOAT_CHARCONV 1 -#endif -#if (TOML_INT_CHARCONV || TOML_FLOAT_CHARCONV) && !TOML_HAS_INCLUDE() - #undef TOML_INT_CHARCONV - #undef TOML_FLOAT_CHARCONV - #define TOML_INT_CHARCONV 0 - #define TOML_FLOAT_CHARCONV 0 -#endif - -#ifndef TOML_PUSH_WARNINGS - #define TOML_PUSH_WARNINGS -#endif -#ifndef TOML_DISABLE_SWITCH_WARNINGS - #define TOML_DISABLE_SWITCH_WARNINGS -#endif -#ifndef TOML_DISABLE_INIT_WARNINGS - #define TOML_DISABLE_INIT_WARNINGS -#endif -#ifndef TOML_DISABLE_SPAM_WARNINGS - #define TOML_DISABLE_SPAM_WARNINGS -#endif -#ifndef TOML_DISABLE_ARITHMETIC_WARNINGS - #define TOML_DISABLE_ARITHMETIC_WARNINGS -#endif -#ifndef TOML_DISABLE_SHADOW_WARNINGS - #define TOML_DISABLE_SHADOW_WARNINGS -#endif -#ifndef TOML_POP_WARNINGS - #define TOML_POP_WARNINGS -#endif -#ifndef TOML_DISABLE_WARNINGS - #define TOML_DISABLE_WARNINGS -#endif -#ifndef TOML_ENABLE_WARNINGS - #define TOML_ENABLE_WARNINGS -#endif - -#ifndef TOML_ATTR - #define TOML_ATTR(...) -#endif - -#ifndef TOML_INTERFACE - #define TOML_INTERFACE -#endif - -#ifndef TOML_EMPTY_BASES - #define TOML_EMPTY_BASES -#endif - -#ifndef TOML_NEVER_INLINE - #define TOML_NEVER_INLINE -#endif - -#ifndef TOML_ASSUME - #define TOML_ASSUME(cond) (void)0 -#endif - -#ifndef TOML_UNREACHABLE - #define TOML_UNREACHABLE TOML_ASSERT(false) -#endif - -#define TOML_NO_DEFAULT_CASE default: TOML_UNREACHABLE - -#ifdef __cpp_consteval - #define TOML_CONSTEVAL consteval -#else - #define TOML_CONSTEVAL constexpr -#endif - -#ifdef __has_cpp_attribute - #define TOML_HAS_ATTR(...) __has_cpp_attribute(__VA_ARGS__) -#else - #define TOML_HAS_ATTR(...) 0 -#endif - -#if !defined(DOXYGEN) && !TOML_INTELLISENSE - #if !defined(TOML_LIKELY) && TOML_HAS_ATTR(likely) - #define TOML_LIKELY(...) (__VA_ARGS__) [[likely]] - #endif - #if !defined(TOML_UNLIKELY) && TOML_HAS_ATTR(unlikely) - #define TOML_UNLIKELY(...) (__VA_ARGS__) [[unlikely]] - #endif - #if TOML_HAS_ATTR(nodiscard) >= 201907L - #define TOML_NODISCARD_CTOR [[nodiscard]] - #endif -#endif - -#ifndef TOML_LIKELY - #define TOML_LIKELY(...) (__VA_ARGS__) -#endif -#ifndef TOML_UNLIKELY - #define TOML_UNLIKELY(...) (__VA_ARGS__) -#endif -#ifndef TOML_NODISCARD_CTOR - #define TOML_NODISCARD_CTOR -#endif - -#ifndef TOML_TRIVIAL_ABI - #define TOML_TRIVIAL_ABI -#endif - -#ifndef TOML_RELOPS_REORDERING - #define TOML_RELOPS_REORDERING 0 -#endif -#if TOML_RELOPS_REORDERING - #define TOML_ASYMMETRICAL_EQUALITY_OPS(...) -#else - #define TOML_ASYMMETRICAL_EQUALITY_OPS(LHS, RHS, ...) \ - __VA_ARGS__ [[nodiscard]] friend bool operator == (RHS rhs, LHS lhs) noexcept { return lhs == rhs; } \ - __VA_ARGS__ [[nodiscard]] friend bool operator != (LHS lhs, RHS rhs) noexcept { return !(lhs == rhs); } \ - __VA_ARGS__ [[nodiscard]] friend bool operator != (RHS rhs, LHS lhs) noexcept { return !(lhs == rhs); } -#endif - -#ifndef TOML_SIMPLE_STATIC_ASSERT_MESSAGES - #define TOML_SIMPLE_STATIC_ASSERT_MESSAGES 0 -#endif - -#define TOML_CONCAT_1(x, y) x##y -#define TOML_CONCAT(x, y) TOML_CONCAT_1(x, y) - -#define TOML_EVAL_BOOL_1(T, F) T -#define TOML_EVAL_BOOL_0(T, F) F - -#if defined(__aarch64__) || defined(__ARM_ARCH_ISA_A64) || defined(_M_ARM64) || defined(__ARM_64BIT_STATE) \ - || defined(__arm__) || defined(_M_ARM) || defined(__ARM_32BIT_STATE) - #define TOML_ARM 1 -#else - #define TOML_ARM 0 -#endif - -#define TOML_MAKE_BITOPS(type) \ - [[nodiscard]] \ - TOML_ALWAYS_INLINE \ - TOML_ATTR(const) \ - TOML_ATTR(flatten) \ - constexpr type operator & (type lhs, type rhs) noexcept \ - { \ - return static_cast(::toml::impl::unwrap_enum(lhs) & ::toml::impl::unwrap_enum(rhs)); \ - } \ - [[nodiscard]] \ - TOML_ALWAYS_INLINE \ - TOML_ATTR(const) \ - TOML_ATTR(flatten) \ - constexpr type operator | (type lhs, type rhs) noexcept \ - { \ - return static_cast(::toml::impl::unwrap_enum(lhs) | ::toml::impl::unwrap_enum(rhs)); \ - } - -#ifdef __FLT16_MANT_DIG__ - #if __FLT_RADIX__ == 2 \ - && __FLT16_MANT_DIG__ == 11 \ - && __FLT16_DIG__ == 3 \ - && __FLT16_MIN_EXP__ == -13 \ - && __FLT16_MIN_10_EXP__ == -4 \ - && __FLT16_MAX_EXP__ == 16 \ - && __FLT16_MAX_10_EXP__ == 4 - #if (TOML_ARM && TOML_GCC) || TOML_CLANG - #define TOML_FP16 __fp16 - #endif - #if TOML_ARM && TOML_CLANG // not present in g++ - #define TOML_FLOAT16 _Float16 - #endif - #endif -#endif - -#if defined(__SIZEOF_FLOAT128__) \ - && defined(__FLT128_MANT_DIG__) \ - && defined(__LDBL_MANT_DIG__) \ - && __FLT128_MANT_DIG__ > __LDBL_MANT_DIG__ - #define TOML_FLOAT128 __float128 -#endif - -#ifdef __SIZEOF_INT128__ - #define TOML_INT128 __int128_t - #define TOML_UINT128 __uint128_t -#endif - -#define TOML_LIB_MAJOR 2 -#define TOML_LIB_MINOR 1 -#define TOML_LIB_PATCH 0 - -#define TOML_LANG_MAJOR 1 -#define TOML_LANG_MINOR 0 -#define TOML_LANG_PATCH 0 - -#define TOML_LIB_SINGLE_HEADER 1 - -#define TOML_MAKE_VERSION(maj, min, rev) \ - ((maj) * 1000 + (min) * 25 + (rev)) - -#if TOML_UNRELEASED_FEATURES - #define TOML_LANG_EFFECTIVE_VERSION \ - TOML_MAKE_VERSION(TOML_LANG_MAJOR, TOML_LANG_MINOR, TOML_LANG_PATCH+1) -#else - #define TOML_LANG_EFFECTIVE_VERSION \ - TOML_MAKE_VERSION(TOML_LANG_MAJOR, TOML_LANG_MINOR, TOML_LANG_PATCH) -#endif - -#define TOML_LANG_HIGHER_THAN(maj, min, rev) \ - (TOML_LANG_EFFECTIVE_VERSION > TOML_MAKE_VERSION(maj, min, rev)) - -#define TOML_LANG_AT_LEAST(maj, min, rev) \ - (TOML_LANG_EFFECTIVE_VERSION >= TOML_MAKE_VERSION(maj, min, rev)) - -#define TOML_LANG_UNRELEASED \ - TOML_LANG_HIGHER_THAN(TOML_LANG_MAJOR, TOML_LANG_MINOR, TOML_LANG_PATCH) - -#ifndef TOML_ABI_NAMESPACES - #ifdef DOXYGEN - #define TOML_ABI_NAMESPACES 0 - #else - #define TOML_ABI_NAMESPACES 1 - #endif -#endif -#if TOML_ABI_NAMESPACES - #define TOML_NAMESPACE_START namespace toml { inline namespace TOML_CONCAT(v, TOML_LIB_MAJOR) - #define TOML_NAMESPACE_END } - #define TOML_NAMESPACE ::toml::TOML_CONCAT(v, TOML_LIB_MAJOR) - #define TOML_ABI_NAMESPACE_START(name) inline namespace name { - #define TOML_ABI_NAMESPACE_BOOL(cond, T, F) TOML_ABI_NAMESPACE_START(TOML_CONCAT(TOML_EVAL_BOOL_, cond)(T, F)) - #define TOML_ABI_NAMESPACE_END } -#else - #define TOML_NAMESPACE_START namespace toml - #define TOML_NAMESPACE_END - #define TOML_NAMESPACE toml - #define TOML_ABI_NAMESPACE_START(...) - #define TOML_ABI_NAMESPACE_BOOL(...) - #define TOML_ABI_NAMESPACE_END -#endif -#define TOML_IMPL_NAMESPACE_START TOML_NAMESPACE_START { namespace impl -#define TOML_IMPL_NAMESPACE_END } TOML_NAMESPACE_END -#if TOML_HEADER_ONLY - #define TOML_ANON_NAMESPACE_START TOML_IMPL_NAMESPACE_START - #define TOML_ANON_NAMESPACE_END TOML_IMPL_NAMESPACE_END - #define TOML_ANON_NAMESPACE TOML_NAMESPACE::impl - #define TOML_USING_ANON_NAMESPACE using namespace TOML_ANON_NAMESPACE - #define TOML_EXTERNAL_LINKAGE inline - #define TOML_INTERNAL_LINKAGE inline -#else - #define TOML_ANON_NAMESPACE_START namespace - #define TOML_ANON_NAMESPACE_END - #define TOML_ANON_NAMESPACE - #define TOML_USING_ANON_NAMESPACE (void)0 - #define TOML_EXTERNAL_LINKAGE - #define TOML_INTERNAL_LINKAGE static -#endif - -TOML_DISABLE_WARNINGS -#ifndef TOML_ASSERT - #if defined(NDEBUG) || !defined(_DEBUG) - #define TOML_ASSERT(expr) (void)0 - #else - #ifndef assert - #include - #endif - #define TOML_ASSERT(expr) assert(expr) - #endif -#endif -TOML_ENABLE_WARNINGS - -#endif //------ ↑ toml_preprocessor.h -------------------------------------------------------------------------------- - -TOML_PUSH_WARNINGS -TOML_DISABLE_SPAM_WARNINGS - -#if 1 //---------------------------------- ↓ toml_common.h ---------------------------------------------------------- - -TOML_DISABLE_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_ENABLE_WARNINGS - -#ifdef __cpp_lib_launder - #define TOML_LAUNDER(x) std::launder(x) -#else - #define TOML_LAUNDER(x) x -#endif - -#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 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 - -#ifndef DOXYGEN // undocumented forward declarations are hidden from doxygen because they fuck it up =/ - -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; - using ::std::uint_least32_t; - using ::std::uint_least64_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; - - #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 - -#endif // !DOXYGEN - -namespace toml { } - -TOML_NAMESPACE_START // abi namespace -{ - inline namespace literals {} - - #if TOML_HAS_CUSTOM_OPTIONAL_TYPE - template - using optional = TOML_OPTIONAL_TYPE; - #else - template - using optional = std::optional; - #endif - - enum class node_type : uint8_t - { - none, - table, - array, - string, - integer, - floating_point, - boolean, - date, - time, - date_time - }; - - using source_path_ptr = std::shared_ptr; - - template - struct TOML_TRIVIAL_ABI inserter - { - T&& value; - }; - template inserter(T&&) -> inserter; -} -TOML_NAMESPACE_END - -TOML_IMPL_NAMESPACE_START -{ - // general value traits - // (as they relate to their equivalent native TOML type) - template - struct value_traits - { - using native_type = void; - static constexpr bool is_native = false; - static constexpr bool is_losslessly_convertible_to_native = false; - static constexpr bool can_represent_native = false; - static constexpr bool can_partially_represent_native = false; - static constexpr auto type = node_type::none; - }; - template struct value_traits : value_traits {}; - template struct value_traits : value_traits {}; - template struct value_traits : value_traits {}; - template struct value_traits : value_traits {}; - template struct value_traits : value_traits {}; - - // integer value traits - template - struct integer_value_limits - { - static constexpr auto min = (std::numeric_limits::min)(); - static constexpr auto max = (std::numeric_limits::max)(); - }; - template - struct integer_value_traits_base : integer_value_limits - { - using native_type = int64_t; - static constexpr bool is_native = std::is_same_v; - static constexpr bool is_signed = static_cast(-1) < T{}; // for impls not specializing std::is_signed - static constexpr auto type = node_type::integer; - static constexpr bool can_partially_represent_native = true; - }; - template - struct unsigned_integer_value_traits : integer_value_traits_base - { - static constexpr bool is_losslessly_convertible_to_native - = integer_value_limits::max <= 9223372036854775807ULL; - static constexpr bool can_represent_native = false; - - }; - template - struct signed_integer_value_traits : integer_value_traits_base - { - using native_type = int64_t; - static constexpr bool is_losslessly_convertible_to_native - = integer_value_limits::min >= (-9223372036854775807LL - 1LL) - && integer_value_limits::max <= 9223372036854775807LL; - static constexpr bool can_represent_native - = integer_value_limits::min <= (-9223372036854775807LL - 1LL) - && integer_value_limits::max >= 9223372036854775807LL; - }; - template ::is_signed> - struct integer_value_traits : signed_integer_value_traits {}; - template - struct integer_value_traits : unsigned_integer_value_traits {}; - template <> struct value_traits : integer_value_traits {}; - template <> struct value_traits : integer_value_traits {}; - template <> struct value_traits : integer_value_traits {}; - template <> struct value_traits : integer_value_traits {}; - template <> struct value_traits : integer_value_traits {}; - template <> struct value_traits : integer_value_traits {}; - template <> struct value_traits : integer_value_traits {}; - template <> struct value_traits : integer_value_traits {}; - template <> struct value_traits : integer_value_traits {}; - template <> struct value_traits : integer_value_traits {}; - #ifdef TOML_INT128 - template <> - struct integer_value_limits - { - static constexpr TOML_INT128 max = static_cast( - (TOML_UINT128{ 1u } << ((__SIZEOF_INT128__ * CHAR_BIT) - 1)) - 1 - ); - static constexpr TOML_INT128 min = -max - TOML_INT128{ 1 }; - }; - template <> - struct integer_value_limits - { - static constexpr TOML_UINT128 min = TOML_UINT128{}; - static constexpr TOML_UINT128 max = (2u * static_cast(integer_value_limits::max)) + 1u; - }; - template <> struct value_traits : integer_value_traits {}; - template <> struct value_traits : integer_value_traits {}; - #endif - #ifdef TOML_SMALL_INT_TYPE - template <> struct value_traits : signed_integer_value_traits {}; - #endif - static_assert(value_traits::is_native); - static_assert(value_traits::is_signed); - static_assert(value_traits::is_losslessly_convertible_to_native); - static_assert(value_traits::can_represent_native); - static_assert(value_traits::can_partially_represent_native); - - // float value traits - template - struct float_value_limits - { - static constexpr bool is_iec559 = std::numeric_limits::is_iec559; - static constexpr int digits = std::numeric_limits::digits; - static constexpr int digits10 = std::numeric_limits::digits10; - }; - template - struct float_value_traits : float_value_limits - { - using native_type = double; - static constexpr bool is_native = std::is_same_v; - static constexpr bool is_signed = true; - static constexpr bool is_losslessly_convertible_to_native - = float_value_limits::is_iec559 - && float_value_limits::digits <= 53 - && float_value_limits::digits10 <= 15; - static constexpr bool can_represent_native - = float_value_limits::is_iec559 - && float_value_limits::digits >= 53 // DBL_MANT_DIG - && float_value_limits::digits10 >= 15; // DBL_DIG - static constexpr bool can_partially_represent_native //32-bit float values - = float_value_limits::is_iec559 - && float_value_limits::digits >= 24 - && float_value_limits::digits10 >= 6; - static constexpr auto type = node_type::floating_point; - }; - template <> struct value_traits : float_value_traits {}; - template <> struct value_traits : float_value_traits {}; - template <> struct value_traits : float_value_traits {}; - template - struct extended_float_value_limits - { - static constexpr bool is_iec559 = true; - static constexpr int digits = mant_dig; - static constexpr int digits10 = dig; - }; - #ifdef TOML_FP16 - template <> struct float_value_limits : extended_float_value_limits<__FLT16_MANT_DIG__, __FLT16_DIG__> {}; - template <> struct value_traits : float_value_traits {}; - #endif - #ifdef TOML_FLOAT16 - template <> struct float_value_limits : extended_float_value_limits<__FLT16_MANT_DIG__, __FLT16_DIG__> {}; - template <> struct value_traits : float_value_traits {}; - #endif - #ifdef TOML_FLOAT128 - template <> struct float_value_limits : extended_float_value_limits<__FLT128_MANT_DIG__, __FLT128_DIG__> {}; - template <> struct value_traits : float_value_traits {}; - #endif - #ifdef TOML_SMALL_FLOAT_TYPE - template <> struct value_traits : float_value_traits {}; - #endif - static_assert(value_traits::is_native); - static_assert(value_traits::is_losslessly_convertible_to_native); - static_assert(value_traits::can_represent_native); - static_assert(value_traits::can_partially_represent_native); - - // string value traits - template - struct string_value_traits - { - using native_type = std::string; - static constexpr bool is_native = std::is_same_v; - static constexpr bool is_losslessly_convertible_to_native = true; - static constexpr bool can_represent_native - = !std::is_array_v - && (!std::is_pointer_v || std::is_const_v>); - static constexpr bool can_partially_represent_native = can_represent_native; - static constexpr auto type = node_type::string; - }; - template <> struct value_traits : string_value_traits {}; - template <> struct value_traits : string_value_traits {}; - template <> struct value_traits : string_value_traits {}; - 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 - template <> struct value_traits : string_value_traits {}; - template <> struct value_traits : string_value_traits {}; - template <> struct value_traits : string_value_traits {}; - template struct value_traits : string_value_traits {}; - template <> struct value_traits : string_value_traits {}; - template struct value_traits : string_value_traits {}; - #endif - #if TOML_WINDOWS_COMPAT - template - struct wstring_value_traits - { - using native_type = std::string; - static constexpr bool is_native = false; - static constexpr bool is_losslessly_convertible_to_native = true; //narrow - static constexpr bool can_represent_native = std::is_same_v; //widen - static constexpr bool can_partially_represent_native = can_represent_native; - static constexpr auto type = node_type::string; - }; - template <> struct value_traits : wstring_value_traits {}; - template <> struct value_traits : wstring_value_traits {}; - template <> struct value_traits : wstring_value_traits {}; - template struct value_traits : wstring_value_traits {}; - template <> struct value_traits : wstring_value_traits {}; - template struct value_traits : wstring_value_traits {}; - #endif - - // other native value traits - template - struct native_value_traits - { - using native_type = T; - static constexpr bool is_native = true; - static constexpr bool is_losslessly_convertible_to_native = true; - static constexpr bool can_represent_native = true; - static constexpr bool can_partially_represent_native = true; - static constexpr auto type = NodeType; - }; - template <> struct value_traits : native_value_traits {}; - template <> struct value_traits : native_value_traits {}; - template <> struct value_traits