add detail/macro_{un}scope.hpp
This commit is contained in:
parent
5bffc95773
commit
d686713f91
4
Makefile
4
Makefile
@ -2,7 +2,9 @@
|
||||
|
||||
SRCDIR = src
|
||||
SRCS = ${SRCDIR}/json.hpp \
|
||||
${SRCDIR}/json_fwd.hpp
|
||||
${SRCDIR}/json_fwd.hpp \
|
||||
${SRCDIR}/detail/macro_scope.hpp \
|
||||
${SRCDIR}/detail/macro_unscope.hpp
|
||||
|
||||
# main target
|
||||
all:
|
||||
|
104
src/detail/macro_scope.hpp
Normal file
104
src/detail/macro_scope.hpp
Normal file
@ -0,0 +1,104 @@
|
||||
#ifndef NLOHMANN_JSON_MACRO_SCOPE_HPP
|
||||
#define NLOHMANN_JSON_MACRO_SCOPE_HPP
|
||||
|
||||
// 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(__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__) < 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 (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) && not defined(JSON_NOEXCEPTION)
|
||||
#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
|
||||
|
||||
// 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>
|
||||
|
||||
/*!
|
||||
@brief Helper to determine whether there's a key_type for T.
|
||||
|
||||
This 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<typename T> struct has_##type { \
|
||||
private: \
|
||||
template<typename U, typename = typename U::type> \
|
||||
static int detect(U &&); \
|
||||
static void detect(...); \
|
||||
public: \
|
||||
static constexpr bool value = \
|
||||
std::is_integral<decltype(detect(std::declval<T>()))>::value; \
|
||||
}
|
||||
|
||||
#endif
|
25
src/detail/macro_unscope.hpp
Normal file
25
src/detail/macro_unscope.hpp
Normal file
@ -0,0 +1,25 @@
|
||||
#ifndef NLOHMANN_JSON_DETAIL_MACRO_UNSCOPE_HPP
|
||||
#define NLOHMANN_JSON_DETAIL_MACRO_UNSCOPE_HPP
|
||||
|
||||
// restore GCC/clang diagnostic settings
|
||||
#if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
#if defined(__clang__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
// clean up
|
||||
#undef JSON_CATCH
|
||||
#undef JSON_THROW
|
||||
#undef JSON_TRY
|
||||
#undef JSON_LIKELY
|
||||
#undef JSON_UNLIKELY
|
||||
#undef JSON_DEPRECATED
|
||||
#undef JSON_HAS_CPP_14
|
||||
#undef JSON_HAS_CPP_17
|
||||
#undef NLOHMANN_BASIC_JSON_TPL_DECLARATION
|
||||
#undef NLOHMANN_BASIC_JSON_TPL
|
||||
#undef NLOHMANN_JSON_HAS_HELPER
|
||||
|
||||
#endif
|
120
src/json.hpp
120
src/json.hpp
@ -53,66 +53,7 @@ SOFTWARE.
|
||||
#include <valarray> // valarray
|
||||
|
||||
#include "json_fwd.hpp"
|
||||
|
||||
// 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__) && !(defined(__ICC) || defined(__INTEL_COMPILER))
|
||||
#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 (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) && not defined(JSON_NOEXCEPTION)
|
||||
#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
|
||||
|
||||
// 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
|
||||
#include "detail/macro_scope.hpp"
|
||||
|
||||
/*!
|
||||
@brief namespace for Niels Lohmann
|
||||
@ -121,23 +62,6 @@ SOFTWARE.
|
||||
*/
|
||||
namespace nlohmann
|
||||
{
|
||||
// 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>
|
||||
|
||||
|
||||
/*!
|
||||
@brief unnamed namespace with internal helper functions
|
||||
|
||||
@ -771,35 +695,11 @@ struct external_constructor<value_t::object>
|
||||
// has_/is_ functions //
|
||||
////////////////////////
|
||||
|
||||
/*!
|
||||
@brief Helper to determine whether there's a key_type for T.
|
||||
|
||||
This 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<typename T> struct has_##type { \
|
||||
private: \
|
||||
template<typename U, typename = typename U::type> \
|
||||
static int detect(U &&); \
|
||||
static void detect(...); \
|
||||
public: \
|
||||
static constexpr bool value = \
|
||||
std::is_integral<decltype(detect(std::declval<T>()))>::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<bool B, class RealType, class CompatibleObjectType>
|
||||
struct is_compatible_object_type_impl : std::false_type {};
|
||||
|
||||
@ -14865,22 +14765,6 @@ inline nlohmann::json::json_pointer operator "" _json_pointer(const char* s, std
|
||||
return nlohmann::json::json_pointer(std::string(s, n));
|
||||
}
|
||||
|
||||
// restore GCC/clang diagnostic settings
|
||||
#if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
#if defined(__clang__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
// clean up
|
||||
#undef JSON_CATCH
|
||||
#undef JSON_THROW
|
||||
#undef JSON_TRY
|
||||
#undef JSON_LIKELY
|
||||
#undef JSON_UNLIKELY
|
||||
#undef JSON_DEPRECATED
|
||||
#undef NLOHMANN_BASIC_JSON_TPL_DECLARATION
|
||||
#undef NLOHMANN_BASIC_JSON_TPL
|
||||
#include "detail/macro_unscope.hpp"
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user