mirror of
https://github.com/nlohmann/json.git
synced 2024-08-23 13:32:28 +02:00
105 lines
3.9 KiB
C++
105 lines
3.9 KiB
C++
#pragma once
|
|
|
|
// This file contains all internal macro definitions
|
|
// You MUST include macro_unscope.hpp at the end of json.hpp to undef all of them
|
|
|
|
// exclude unsupported compilers
|
|
#if !defined(JSON_SKIP_UNSUPPORTED_COMPILER_CHECK)
|
|
#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__) && !(defined(__ICC) || defined(__INTEL_COMPILER))
|
|
#if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) < 40800
|
|
#error "unsupported GCC version - see https://github.com/nlohmann/json#supported-compilers"
|
|
#endif
|
|
#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 (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) && !defined(JSON_NOEXCEPTION)
|
|
#define JSON_THROW(exception) throw exception
|
|
#define JSON_TRY try
|
|
#define JSON_CATCH(exception) catch(exception)
|
|
#define JSON_INTERNAL_CATCH(exception) catch(exception)
|
|
#else
|
|
#define JSON_THROW(exception) std::abort()
|
|
#define JSON_TRY if(true)
|
|
#define JSON_CATCH(exception) if(false)
|
|
#define JSON_INTERNAL_CATCH(exception) if(false)
|
|
#endif
|
|
|
|
// override exception macros
|
|
#if defined(JSON_THROW_USER)
|
|
#undef JSON_THROW
|
|
#define JSON_THROW JSON_THROW_USER
|
|
#endif
|
|
#if defined(JSON_TRY_USER)
|
|
#undef JSON_TRY
|
|
#define JSON_TRY JSON_TRY_USER
|
|
#endif
|
|
#if defined(JSON_CATCH_USER)
|
|
#undef JSON_CATCH
|
|
#define JSON_CATCH JSON_CATCH_USER
|
|
#undef JSON_INTERNAL_CATCH
|
|
#define JSON_INTERNAL_CATCH JSON_CATCH_USER
|
|
#endif
|
|
#if defined(JSON_INTERNAL_CATCH_USER)
|
|
#undef JSON_INTERNAL_CATCH
|
|
#define JSON_INTERNAL_CATCH JSON_INTERNAL_CATCH_USER
|
|
#endif
|
|
|
|
// manual branch prediction
|
|
#if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__)
|
|
#define JSON_LIKELY(x) __builtin_expect(!!(x), 1)
|
|
#define JSON_UNLIKELY(x) __builtin_expect(!!(x), 0)
|
|
#else
|
|
#define JSON_LIKELY(x) x
|
|
#define JSON_UNLIKELY(x) x
|
|
#endif
|
|
|
|
// C++ language standard detection
|
|
#if (defined(__cplusplus) && __cplusplus >= 201703L) || (defined(_HAS_CXX17) && _HAS_CXX17 == 1) // fix for issue #464
|
|
#define JSON_HAS_CPP_17
|
|
#define JSON_HAS_CPP_14
|
|
#elif (defined(__cplusplus) && __cplusplus >= 201402L) || (defined(_HAS_CXX14) && _HAS_CXX14 == 1)
|
|
#define JSON_HAS_CPP_14
|
|
#endif
|
|
|
|
// Ugly macros to avoid uglier copy-paste when specializing basic_json. They
|
|
// may be removed in the future once the class is split.
|
|
|
|
#define NLOHMANN_BASIC_JSON_TPL_DECLARATION \
|
|
template<template<typename, typename, typename...> class ObjectType, \
|
|
template<typename, typename...> class ArrayType, \
|
|
class StringType, class BooleanType, class NumberIntegerType, \
|
|
class NumberUnsignedType, class NumberFloatType, \
|
|
template<typename> class AllocatorType, \
|
|
template<typename, typename = void> class JSONSerializer>
|
|
|
|
#define NLOHMANN_BASIC_JSON_TPL \
|
|
basic_json<ObjectType, ArrayType, StringType, BooleanType, \
|
|
NumberIntegerType, NumberUnsignedType, NumberFloatType, \
|
|
AllocatorType, JSONSerializer>
|