1 #pragma once 2 3 #include <utility> // pair 4 #include <nlohmann/thirdparty/hedley/hedley.hpp> 5 6 // This file contains all internal macro definitions 7 // You MUST include macro_unscope.hpp at the end of json.hpp to undef all of them 8 9 // exclude unsupported compilers 10 #if !defined(JSON_SKIP_UNSUPPORTED_COMPILER_CHECK) 11 #if defined(__clang__) 12 #if (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__) < 30400 13 #error "unsupported Clang version - see https://github.com/nlohmann/json#supported-compilers" 14 #endif 15 #elif defined(__GNUC__) && !(defined(__ICC) || defined(__INTEL_COMPILER)) 16 #if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) < 40800 17 #error "unsupported GCC version - see https://github.com/nlohmann/json#supported-compilers" 18 #endif 19 #endif 20 #endif 21 22 // C++ language standard detection 23 #if (defined(__cplusplus) && __cplusplus >= 201703L) || (defined(_HAS_CXX17) && _HAS_CXX17 == 1) // fix for issue #464 24 #define JSON_HAS_CPP_17 25 #define JSON_HAS_CPP_14 26 #elif (defined(__cplusplus) && __cplusplus >= 201402L) || (defined(_HAS_CXX14) && _HAS_CXX14 == 1) 27 #define JSON_HAS_CPP_14 28 #endif 29 30 // disable float-equal warnings on GCC/clang 31 #if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__) 32 #pragma GCC diagnostic push 33 #pragma GCC diagnostic ignored "-Wfloat-equal" 34 #endif 35 36 // disable documentation warnings on clang 37 #if defined(__clang__) 38 #pragma GCC diagnostic push 39 #pragma GCC diagnostic ignored "-Wdocumentation" 40 #endif 41 42 // allow to disable exceptions 43 #if (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) && !defined(JSON_NOEXCEPTION) 44 #define JSON_THROW(exception) throw exception 45 #define JSON_TRY try 46 #define JSON_CATCH(exception) catch(exception) 47 #define JSON_INTERNAL_CATCH(exception) catch(exception) 48 #else 49 #include <cstdlib> 50 #define JSON_THROW(exception) std::abort() 51 #define JSON_TRY if(true) 52 #define JSON_CATCH(exception) if(false) 53 #define JSON_INTERNAL_CATCH(exception) if(false) 54 #endif 55 56 // override exception macros 57 #if defined(JSON_THROW_USER) 58 #undef JSON_THROW 59 #define JSON_THROW JSON_THROW_USER 60 #endif 61 #if defined(JSON_TRY_USER) 62 #undef JSON_TRY 63 #define JSON_TRY JSON_TRY_USER 64 #endif 65 #if defined(JSON_CATCH_USER) 66 #undef JSON_CATCH 67 #define JSON_CATCH JSON_CATCH_USER 68 #undef JSON_INTERNAL_CATCH 69 #define JSON_INTERNAL_CATCH JSON_CATCH_USER 70 #endif 71 #if defined(JSON_INTERNAL_CATCH_USER) 72 #undef JSON_INTERNAL_CATCH 73 #define JSON_INTERNAL_CATCH JSON_INTERNAL_CATCH_USER 74 #endif 75 76 /*! 77 @brief macro to briefly define a mapping between an enum and JSON 78 @def NLOHMANN_JSON_SERIALIZE_ENUM 79 @since version 3.4.0 80 */ 81 #define NLOHMANN_JSON_SERIALIZE_ENUM(ENUM_TYPE, ...) \ 82 template<typename BasicJsonType> \ 83 inline void to_json(BasicJsonType& j, const ENUM_TYPE& e) \ 84 { \ 85 static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an enum!"); \ 86 static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__; \ 87 auto it = std::find_if(std::begin(m), std::end(m), \ 88 [e](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool \ 89 { \ 90 return ej_pair.first == e; \ 91 }); \ 92 j = ((it != std::end(m)) ? it : std::begin(m))->second; \ 93 } \ 94 template<typename BasicJsonType> \ 95 inline void from_json(const BasicJsonType& j, ENUM_TYPE& e) \ 96 { \ 97 static_assert(std::is_enum<ENUM_TYPE>::value, #ENUM_TYPE " must be an enum!"); \ 98 static const std::pair<ENUM_TYPE, BasicJsonType> m[] = __VA_ARGS__; \ 99 auto it = std::find_if(std::begin(m), std::end(m), \ 100 [&j](const std::pair<ENUM_TYPE, BasicJsonType>& ej_pair) -> bool \ 101 { \ 102 return ej_pair.second == j; \ 103 }); \ 104 e = ((it != std::end(m)) ? it : std::begin(m))->first; \ 105 } 106 107 // Ugly macros to avoid uglier copy-paste when specializing basic_json. They 108 // may be removed in the future once the class is split. 109 110 #define NLOHMANN_BASIC_JSON_TPL_DECLARATION \ 111 template<template<typename, typename, typename...> class ObjectType, \ 112 template<typename, typename...> class ArrayType, \ 113 class StringType, class BooleanType, class NumberIntegerType, \ 114 class NumberUnsignedType, class NumberFloatType, \ 115 template<typename> class AllocatorType, \ 116 template<typename, typename = void> class JSONSerializer> 117 118 #define NLOHMANN_BASIC_JSON_TPL \ 119 basic_json<ObjectType, ArrayType, StringType, BooleanType, \ 120 NumberIntegerType, NumberUnsignedType, NumberFloatType, \ 121 AllocatorType, JSONSerializer> 122