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> |
38 | using start_object_function_t = |
39 | decltype(std::declval<T&>().start_object(std::declval<std::size_t>())); |
40 | |
41 | template <typename T, typename String> |
42 | using key_function_t = |
43 | decltype(std::declval<T&>().key(std::declval<String&>())); |
44 | |
45 | template <typename T> |
46 | using end_object_function_t = decltype(std::declval<T&>().end_object()); |
47 | |
48 | template <typename T> |
49 | using start_array_function_t = |
50 | decltype(std::declval<T&>().start_array(std::declval<std::size_t>())); |
51 | |
52 | template <typename T> |
53 | using end_array_function_t = decltype(std::declval<T&>().end_array()); |
54 | |
55 | template <typename T, typename Exception> |
56 | using parse_error_function_t = decltype(std::declval<T&>().parse_error( |
57 | std::declval<std::size_t>(), std::declval<const std::string&>(), |
58 | std::declval<const Exception&>())); |
59 | |
60 | template <typename SAX, typename BasicJsonType> |
61 | struct is_sax |
62 | { |
63 | private: |
64 | static_assert(is_basic_json<BasicJsonType>::value, |
65 | "BasicJsonType must be of type basic_json<...>" ); |
66 | |
67 | using number_integer_t = typename BasicJsonType::number_integer_t; |
68 | using number_unsigned_t = typename BasicJsonType::number_unsigned_t; |
69 | using number_float_t = typename BasicJsonType::number_float_t; |
70 | using string_t = typename BasicJsonType::string_t; |
71 | using exception_t = typename BasicJsonType::exception; |
72 | |
73 | public: |
74 | static constexpr bool value = |
75 | is_detected_exact<bool, null_function_t, SAX>::value && |
76 | is_detected_exact<bool, boolean_function_t, SAX>::value && |
77 | is_detected_exact<bool, number_integer_function_t, SAX, |
78 | number_integer_t>::value && |
79 | is_detected_exact<bool, number_unsigned_function_t, SAX, |
80 | number_unsigned_t>::value && |
81 | is_detected_exact<bool, number_float_function_t, SAX, number_float_t, |
82 | string_t>::value && |
83 | is_detected_exact<bool, string_function_t, SAX, string_t>::value && |
84 | is_detected_exact<bool, start_object_function_t, SAX>::value && |
85 | is_detected_exact<bool, key_function_t, SAX, string_t>::value && |
86 | is_detected_exact<bool, end_object_function_t, SAX>::value && |
87 | is_detected_exact<bool, start_array_function_t, SAX>::value && |
88 | is_detected_exact<bool, end_array_function_t, SAX>::value && |
89 | is_detected_exact<bool, parse_error_function_t, SAX, exception_t>::value; |
90 | }; |
91 | |
92 | template <typename SAX, typename BasicJsonType> |
93 | struct is_sax_static_asserts |
94 | { |
95 | private: |
96 | static_assert(is_basic_json<BasicJsonType>::value, |
97 | "BasicJsonType must be of type basic_json<...>" ); |
98 | |
99 | using number_integer_t = typename BasicJsonType::number_integer_t; |
100 | using number_unsigned_t = typename BasicJsonType::number_unsigned_t; |
101 | using number_float_t = typename BasicJsonType::number_float_t; |
102 | using string_t = typename BasicJsonType::string_t; |
103 | using exception_t = typename BasicJsonType::exception; |
104 | |
105 | public: |
106 | static_assert(is_detected_exact<bool, null_function_t, SAX>::value, |
107 | "Missing/invalid function: bool null()" ); |
108 | static_assert(is_detected_exact<bool, boolean_function_t, SAX>::value, |
109 | "Missing/invalid function: bool boolean(bool)" ); |
110 | static_assert(is_detected_exact<bool, boolean_function_t, SAX>::value, |
111 | "Missing/invalid function: bool boolean(bool)" ); |
112 | static_assert( |
113 | is_detected_exact<bool, number_integer_function_t, SAX, |
114 | number_integer_t>::value, |
115 | "Missing/invalid function: bool number_integer(number_integer_t)" ); |
116 | static_assert( |
117 | is_detected_exact<bool, number_unsigned_function_t, SAX, |
118 | number_unsigned_t>::value, |
119 | "Missing/invalid function: bool number_unsigned(number_unsigned_t)" ); |
120 | static_assert(is_detected_exact<bool, number_float_function_t, SAX, |
121 | number_float_t, string_t>::value, |
122 | "Missing/invalid function: bool number_float(number_float_t, const string_t&)" ); |
123 | static_assert( |
124 | is_detected_exact<bool, string_function_t, SAX, string_t>::value, |
125 | "Missing/invalid function: bool string(string_t&)" ); |
126 | static_assert(is_detected_exact<bool, start_object_function_t, SAX>::value, |
127 | "Missing/invalid function: bool start_object(std::size_t)" ); |
128 | static_assert(is_detected_exact<bool, key_function_t, SAX, string_t>::value, |
129 | "Missing/invalid function: bool key(string_t&)" ); |
130 | static_assert(is_detected_exact<bool, end_object_function_t, SAX>::value, |
131 | "Missing/invalid function: bool end_object()" ); |
132 | static_assert(is_detected_exact<bool, start_array_function_t, SAX>::value, |
133 | "Missing/invalid function: bool start_array(std::size_t)" ); |
134 | static_assert(is_detected_exact<bool, end_array_function_t, SAX>::value, |
135 | "Missing/invalid function: bool end_array()" ); |
136 | static_assert( |
137 | is_detected_exact<bool, parse_error_function_t, SAX, exception_t>::value, |
138 | "Missing/invalid function: bool parse_error(std::size_t, const " |
139 | "std::string&, const exception&)" ); |
140 | }; |
141 | } // namespace detail |
142 | } // namespace nlohmann |
143 | |