/* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ | | |__ | | | | | | version 2.0.10 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . Copyright (c) 2013-2017 Niels Lohmann . 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 NLOHMANN_JSON_HPP #define NLOHMANN_JSON_HPP #include // all_of, for_each, transform #include // array #include // assert #include // isdigit #include // and, not, or #include // isfinite, ldexp, signbit #include // nullptr_t, ptrdiff_t, size_t #include // int64_t, uint64_t #include // strtod, strtof, strtold, strtoul #include // strlen #include // function, hash, less #include // initializer_list #include // setw #include // istream, ostream #include // advance, begin, bidirectional_iterator_tag, distance, end, inserter, iterator, iterator_traits, next, random_access_iterator_tag, reverse_iterator #include // numeric_limits #include // locale #include // map #include // addressof, allocator, allocator_traits, unique_ptr #include // accumulate #include // stringstream #include // domain_error, invalid_argument, out_of_range #include // getline, stoi, string, to_string #include // add_pointer, enable_if, is_arithmetic, is_base_of, is_const, is_constructible, is_convertible, is_floating_point, is_integral, is_nothrow_move_assignable, std::is_nothrow_move_constructible, std::is_pointer, std::is_reference, std::is_same, remove_const, remove_pointer, remove_reference #include // declval, forward, make_pair, move, pair, swap #include // vector // exclude unsupported compilers #if defined(__clang__) #if (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__) < 30400 #error "unsupported Clang version - see https://github.com/nlohmann/json#supported-compilers" #endif #elif defined(__GNUC__) #if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) < 40900 #error "unsupported GCC version - see https://github.com/nlohmann/json#supported-compilers" #endif #endif // disable float-equal warnings on GCC/clang #if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wfloat-equal" #endif // disable documentation warnings on clang #if defined(__clang__) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wdocumentation" #endif // allow for portable deprecation warnings #if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__) #define JSON_DEPRECATED __attribute__((deprecated)) #elif defined(_MSC_VER) #define JSON_DEPRECATED __declspec(deprecated) #else #define JSON_DEPRECATED #endif // allow to disable exceptions #if not defined(JSON_NOEXCEPTION) || defined(__EXCEPTIONS) #define JSON_THROW(exception) throw exception #define JSON_TRY try #define JSON_CATCH(exception) catch(exception) #else #define JSON_THROW(exception) std::abort() #define JSON_TRY if(true) #define JSON_CATCH(exception) if(false) #endif /*! @brief namespace for Niels Lohmann @see https://github.com/nlohmann @since version 1.0.0 */ namespace nlohmann { // alias templates to reduce boilerplate template using enable_if_t = typename std::enable_if::type; template using remove_cv_t = typename std::remove_cv::type; template using remove_reference_t = typename std::remove_reference::type; template using uncvref_t = remove_cv_t>; template using conditional_t = typename std::conditional::type; // TODO update this doc /*! @brief unnamed namespace with internal helper functions @since version 1.0.0 */ namespace detail { // Implementation of 3 C++17 constructs: conjunction, disjunction, negation. // This is needed to avoid evaluating all the traits in a condition // // For example: not std::is_same::value and has_value_type::value // will not compile when T = void (on MSVC at least) // Whereas conjunction>, has_value_type>::value // will stop evaluating if negation<...>::value == false // // Please note that those constructs must be used with caution, since symbols can // become very long quickly (which can slow down compilation and cause MSVC internal compiler errors) // Only use it when you have too (see example ahead) template struct conjunction : std::true_type {}; template struct conjunction : B1 {}; template struct conjunction : conditional_t, B1> {}; template struct negation : std::integral_constant {}; template struct disjunction : std::false_type {}; template struct disjunction : B1 {}; template struct disjunction : conditional_t> {}; /*! @brief Helper to determine whether there's a key_type for T. Thus helper is used to tell associative containers apart from other containers such as sequence containers. For instance, `std::map` passes the test as it contains a `mapped_type`, whereas `std::vector` fails the test. @sa http://stackoverflow.com/a/7728728/266378 @since version 1.0.0, overworked in version 2.0.6 */ #define NLOHMANN_JSON_HAS_HELPER(type) \ template struct has_##type { \ private: \ template \ static int detect(U &&); \ \ static void detect(...); \ \ public: \ static constexpr bool value = \ std::is_integral()))>::value; \ }; NLOHMANN_JSON_HAS_HELPER(mapped_type) NLOHMANN_JSON_HAS_HELPER(key_type) NLOHMANN_JSON_HAS_HELPER(value_type) NLOHMANN_JSON_HAS_HELPER(iterator) #undef NLOHMANN_JSON_HAS_HELPER template struct is_compatible_object_type_impl : std::false_type{}; template struct is_compatible_object_type_impl { static constexpr auto value = std::is_constructible::value and std::is_constructible::value; }; template struct is_compatible_object_type { // As noted ahead, we need to stop evaluating traits if CompatibleObjectType = void // hence the conjunction static auto constexpr value = is_compatible_object_type_impl< conjunction>, has_mapped_type, has_key_type>::value, RealType, CompatibleObjectType>::value; }; template struct is_compatible_array_type_impl : std::false_type{}; template struct is_compatible_array_type_impl { static constexpr auto value = not std::is_same::value and not std::is_same::value and not std::is_same::value and not std::is_same::value and not std::is_same::value and not std::is_same::value; }; template struct is_compatible_array_type { // the check for CompatibleArrayType = void is done in is_compatible_object_type // but we need the conjunction here as well static auto constexpr value = is_compatible_array_type_impl< conjunction>, has_value_type, has_iterator>::value, BasicJson, CompatibleArrayType>::value; }; template struct is_compatible_integer_type_impl : std::false_type{}; template struct is_compatible_integer_type_impl { using RealLimits = std::numeric_limits; using CompatibleLimits = std::numeric_limits; static constexpr auto value = std::is_constructible::value and CompatibleLimits::is_integer and RealLimits::is_signed == CompatibleLimits::is_signed; }; template struct is_compatible_integer_type { static constexpr auto value = is_compatible_integer_type_impl< std::is_arithmetic::value, RealIntegerType, CompatibleNumberIntegerType>::value; }; template struct is_compatible_float_type { static constexpr auto value = std::is_constructible::value and std::is_floating_point::value; }; template struct is_compatible_basic_json_type { static auto constexpr value = std::is_same::value or std::is_constructible::value or std::is_same::value or is_compatible_array_type::value or is_compatible_object_type::value or is_compatible_float_type::value or is_compatible_integer_type::value or is_compatible_integer_type::value; }; // This trait checks if JSONSerializer::from_json exists template