| 1 |
#pragma once |
| 2 |
|
| 3 |
#include <cstdint> // size_t |
| 4 |
#include <utility> // declval |
| 5 |
#include <string> // string |
| 6 |
|
| 7 |
#include <nlohmann/detail/meta/detected.hpp> |
| 8 |
#include <nlohmann/detail/meta/type_traits.hpp> |
| 9 |
|
| 10 |
namespace nlohmann |
| 11 |
{ |
| 12 |
namespace detail |
| 13 |
{ |
| 14 |
template<typename T> |
| 15 |
using null_function_t = decltype(std::declval<T&>().null()); |
| 16 |
|
| 17 |
template<typename T> |
| 18 |
using boolean_function_t = |
| 19 |
decltype(std::declval<T&>().boolean(std::declval<bool>())); |
| 20 |
|
| 21 |
template<typename T, typename Integer> |
| 22 |
using number_integer_function_t = |
| 23 |
decltype(std::declval<T&>().number_integer(std::declval<Integer>())); |
| 24 |
|
| 25 |
template<typename T, typename Unsigned> |
| 26 |
using number_unsigned_function_t = |
| 27 |
decltype(std::declval<T&>().number_unsigned(std::declval<Unsigned>())); |
| 28 |
|
| 29 |
template<typename T, typename Float, typename String> |
| 30 |
using number_float_function_t = decltype(std::declval<T&>().number_float( |
| 31 |
std::declval<Float>(), std::declval<const String&>())); |
| 32 |
|
| 33 |
template<typename T, typename String> |
| 34 |
using string_function_t = |
| 35 |
decltype(std::declval<T&>().string(std::declval<String&>())); |
| 36 |
|
| 37 |
template<typename T, typename Binary> |
| 38 |
using binary_function_t = |
| 39 |
decltype(std::declval<T&>().binary(std::declval<Binary&>())); |
| 40 |
|
| 41 |
template<typename T> |
| 42 |
using start_object_function_t = |
| 43 |
decltype(std::declval<T&>().start_object(std::declval<std::size_t>())); |
| 44 |
|
| 45 |
template<typename T, typename String> |
| 46 |
using key_function_t = |
| 47 |
decltype(std::declval<T&>().key(std::declval<String&>())); |
| 48 |
|
| 49 |
template<typename T> |
| 50 |
using end_object_function_t = decltype(std::declval<T&>().end_object()); |
| 51 |
|
| 52 |
template<typename T> |
| 53 |
using start_array_function_t = |
| 54 |
decltype(std::declval<T&>().start_array(std::declval<std::size_t>())); |
| 55 |
|
| 56 |
template<typename T> |
| 57 |
using end_array_function_t = decltype(std::declval<T&>().end_array()); |
| 58 |
|
| 59 |
template<typename T, typename Exception> |
| 60 |
using parse_error_function_t = decltype(std::declval<T&>().parse_error( |
| 61 |
std::declval<std::size_t>(), std::declval<const std::string&>(), |
| 62 |
std::declval<const Exception&>())); |
| 63 |
|
| 64 |
template<typename SAX, typename BasicJsonType> |
| 65 |
struct is_sax |
| 66 |
{ |
| 67 |
private: |
| 68 |
static_assert(is_basic_json<BasicJsonType>::value, |
| 69 |
"BasicJsonType must be of type basic_json<...>"); |
| 70 |
|
| 71 |
using number_integer_t = typename BasicJsonType::number_integer_t; |
| 72 |
using number_unsigned_t = typename BasicJsonType::number_unsigned_t; |
| 73 |
using number_float_t = typename BasicJsonType::number_float_t; |
| 74 |
using string_t = typename BasicJsonType::string_t; |
| 75 |
using binary_t = typename BasicJsonType::binary_t; |
| 76 |
using exception_t = typename BasicJsonType::exception; |
| 77 |
|
| 78 |
public: |
| 79 |
static constexpr bool value = |
| 80 |
is_detected_exact<bool, null_function_t, SAX>::value && |
| 81 |
is_detected_exact<bool, boolean_function_t, SAX>::value && |
| 82 |
is_detected_exact<bool, number_integer_function_t, SAX, number_integer_t>::value && |
| 83 |
is_detected_exact<bool, number_unsigned_function_t, SAX, number_unsigned_t>::value && |
| 84 |
is_detected_exact<bool, number_float_function_t, SAX, number_float_t, string_t>::value && |
| 85 |
is_detected_exact<bool, string_function_t, SAX, string_t>::value && |
| 86 |
is_detected_exact<bool, binary_function_t, SAX, binary_t>::value && |
| 87 |
is_detected_exact<bool, start_object_function_t, SAX>::value && |
| 88 |
is_detected_exact<bool, key_function_t, SAX, string_t>::value && |
| 89 |
is_detected_exact<bool, end_object_function_t, SAX>::value && |
| 90 |
is_detected_exact<bool, start_array_function_t, SAX>::value && |
| 91 |
is_detected_exact<bool, end_array_function_t, SAX>::value && |
| 92 |
is_detected_exact<bool, parse_error_function_t, SAX, exception_t>::value; |
| 93 |
}; |
| 94 |
|
| 95 |
template<typename SAX, typename BasicJsonType> |
| 96 |
struct is_sax_static_asserts |
| 97 |
{ |
| 98 |
private: |
| 99 |
static_assert(is_basic_json<BasicJsonType>::value, |
| 100 |
"BasicJsonType must be of type basic_json<...>"); |
| 101 |
|
| 102 |
using number_integer_t = typename BasicJsonType::number_integer_t; |
| 103 |
using number_unsigned_t = typename BasicJsonType::number_unsigned_t; |
| 104 |
using number_float_t = typename BasicJsonType::number_float_t; |
| 105 |
using string_t = typename BasicJsonType::string_t; |
| 106 |
using binary_t = typename BasicJsonType::binary_t; |
| 107 |
using exception_t = typename BasicJsonType::exception; |
| 108 |
|
| 109 |
public: |
| 110 |
static_assert(is_detected_exact<bool, null_function_t, SAX>::value, |
| 111 |
"Missing/invalid function: bool null()"); |
| 112 |
static_assert(is_detected_exact<bool, boolean_function_t, SAX>::value, |
| 113 |
"Missing/invalid function: bool boolean(bool)"); |
| 114 |
static_assert(is_detected_exact<bool, boolean_function_t, SAX>::value, |
| 115 |
"Missing/invalid function: bool boolean(bool)"); |
| 116 |
static_assert( |
| 117 |
is_detected_exact<bool, number_integer_function_t, SAX, |
| 118 |
number_integer_t>::value, |
| 119 |
"Missing/invalid function: bool number_integer(number_integer_t)"); |
| 120 |
static_assert( |
| 121 |
is_detected_exact<bool, number_unsigned_function_t, SAX, |
| 122 |
number_unsigned_t>::value, |
| 123 |
"Missing/invalid function: bool number_unsigned(number_unsigned_t)"); |
| 124 |
static_assert(is_detected_exact<bool, number_float_function_t, SAX, |
| 125 |
number_float_t, string_t>::value, |
| 126 |
"Missing/invalid function: bool number_float(number_float_t, const string_t&)"); |
| 127 |
static_assert( |
| 128 |
is_detected_exact<bool, string_function_t, SAX, string_t>::value, |
| 129 |
"Missing/invalid function: bool string(string_t&)"); |
| 130 |
static_assert( |
| 131 |
is_detected_exact<bool, binary_function_t, SAX, binary_t>::value, |
| 132 |
"Missing/invalid function: bool binary(binary_t&)"); |
| 133 |
static_assert(is_detected_exact<bool, start_object_function_t, SAX>::value, |
| 134 |
"Missing/invalid function: bool start_object(std::size_t)"); |
| 135 |
static_assert(is_detected_exact<bool, key_function_t, SAX, string_t>::value, |
| 136 |
"Missing/invalid function: bool key(string_t&)"); |
| 137 |
static_assert(is_detected_exact<bool, end_object_function_t, SAX>::value, |
| 138 |
"Missing/invalid function: bool end_object()"); |
| 139 |
static_assert(is_detected_exact<bool, start_array_function_t, SAX>::value, |
| 140 |
"Missing/invalid function: bool start_array(std::size_t)"); |
| 141 |
static_assert(is_detected_exact<bool, end_array_function_t, SAX>::value, |
| 142 |
"Missing/invalid function: bool end_array()"); |
| 143 |
static_assert( |
| 144 |
is_detected_exact<bool, parse_error_function_t, SAX, exception_t>::value, |
| 145 |
"Missing/invalid function: bool parse_error(std::size_t, const " |
| 146 |
"std::string&, const exception&)"); |
| 147 |
}; |
| 148 |
} // namespace detail |
| 149 |
} // namespace nlohmann |