json/include/nlohmann/detail/meta/is_sax.hpp

143 lines
6.0 KiB
C++
Raw Normal View History

2018-07-24 20:47:41 +08:00
#pragma once
#include <cstdint> // size_t
#include <utility> // declval
2019-03-15 21:55:13 +08:00
#include <string> // string
2018-07-24 20:47:41 +08:00
#include <nlohmann/detail/meta/detected.hpp>
#include <nlohmann/detail/meta/type_traits.hpp>
namespace nlohmann
{
namespace detail
{
template<typename T>
2018-07-24 20:47:41 +08:00
using null_function_t = decltype(std::declval<T&>().null());
template<typename T>
2018-07-24 20:47:41 +08:00
using boolean_function_t =
decltype(std::declval<T&>().boolean(std::declval<bool>()));
template<typename T, typename Integer>
2018-07-24 20:47:41 +08:00
using number_integer_function_t =
decltype(std::declval<T&>().number_integer(std::declval<Integer>()));
template<typename T, typename Unsigned>
2018-07-24 20:47:41 +08:00
using number_unsigned_function_t =
2019-03-28 21:23:26 +08:00
decltype(std::declval<T&>().number_unsigned(std::declval<Unsigned>()));
2018-07-24 20:47:41 +08:00
template<typename T, typename Float, typename String>
2019-03-28 21:23:26 +08:00
using number_float_function_t = decltype(std::declval<T&>().number_float(
std::declval<Float>(), std::declval<const String&>()));
2018-07-24 20:47:41 +08:00
template<typename T, typename String>
2018-07-24 20:47:41 +08:00
using string_function_t =
2019-03-28 21:23:26 +08:00
decltype(std::declval<T&>().string(std::declval<String&>()));
2018-07-24 20:47:41 +08:00
template<typename T>
2018-07-24 20:47:41 +08:00
using start_object_function_t =
2019-03-28 21:23:26 +08:00
decltype(std::declval<T&>().start_object(std::declval<std::size_t>()));
2018-07-24 20:47:41 +08:00
template<typename T, typename String>
2018-07-24 20:47:41 +08:00
using key_function_t =
2019-03-28 21:23:26 +08:00
decltype(std::declval<T&>().key(std::declval<String&>()));
2018-07-24 20:47:41 +08:00
template<typename T>
2019-03-28 21:23:26 +08:00
using end_object_function_t = decltype(std::declval<T&>().end_object());
2018-07-24 20:47:41 +08:00
template<typename T>
2018-07-24 20:47:41 +08:00
using start_array_function_t =
2019-03-28 21:23:26 +08:00
decltype(std::declval<T&>().start_array(std::declval<std::size_t>()));
2018-07-24 20:47:41 +08:00
template<typename T>
2019-03-28 21:23:26 +08:00
using end_array_function_t = decltype(std::declval<T&>().end_array());
2018-07-24 20:47:41 +08:00
template<typename T, typename Exception>
2019-03-28 21:23:26 +08:00
using parse_error_function_t = decltype(std::declval<T&>().parse_error(
std::declval<std::size_t>(), std::declval<const std::string&>(),
std::declval<const Exception&>()));
2018-07-24 20:47:41 +08:00
template<typename SAX, typename BasicJsonType>
2018-07-24 20:47:41 +08:00
struct is_sax
{
2019-03-28 21:23:26 +08:00
private:
static_assert(is_basic_json<BasicJsonType>::value,
"BasicJsonType must be of type basic_json<...>");
using number_integer_t = typename BasicJsonType::number_integer_t;
using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
using number_float_t = typename BasicJsonType::number_float_t;
using string_t = typename BasicJsonType::string_t;
using exception_t = typename BasicJsonType::exception;
public:
static constexpr bool value =
is_detected_exact<bool, null_function_t, SAX>::value &&
is_detected_exact<bool, boolean_function_t, SAX>::value &&
is_detected_exact<bool, number_integer_function_t, SAX,
number_integer_t>::value &&
is_detected_exact<bool, number_unsigned_function_t, SAX,
number_unsigned_t>::value &&
is_detected_exact<bool, number_float_function_t, SAX, number_float_t,
string_t>::value &&
is_detected_exact<bool, string_function_t, SAX, string_t>::value &&
is_detected_exact<bool, start_object_function_t, SAX>::value &&
is_detected_exact<bool, key_function_t, SAX, string_t>::value &&
is_detected_exact<bool, end_object_function_t, SAX>::value &&
is_detected_exact<bool, start_array_function_t, SAX>::value &&
is_detected_exact<bool, end_array_function_t, SAX>::value &&
is_detected_exact<bool, parse_error_function_t, SAX, exception_t>::value;
2018-07-24 20:47:41 +08:00
};
template<typename SAX, typename BasicJsonType>
2018-07-24 20:47:41 +08:00
struct is_sax_static_asserts
{
2019-03-28 21:23:26 +08:00
private:
static_assert(is_basic_json<BasicJsonType>::value,
"BasicJsonType must be of type basic_json<...>");
using number_integer_t = typename BasicJsonType::number_integer_t;
using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
using number_float_t = typename BasicJsonType::number_float_t;
using string_t = typename BasicJsonType::string_t;
using exception_t = typename BasicJsonType::exception;
public:
static_assert(is_detected_exact<bool, null_function_t, SAX>::value,
"Missing/invalid function: bool null()");
static_assert(is_detected_exact<bool, boolean_function_t, SAX>::value,
"Missing/invalid function: bool boolean(bool)");
static_assert(is_detected_exact<bool, boolean_function_t, SAX>::value,
"Missing/invalid function: bool boolean(bool)");
static_assert(
is_detected_exact<bool, number_integer_function_t, SAX,
number_integer_t>::value,
"Missing/invalid function: bool number_integer(number_integer_t)");
static_assert(
is_detected_exact<bool, number_unsigned_function_t, SAX,
number_unsigned_t>::value,
"Missing/invalid function: bool number_unsigned(number_unsigned_t)");
static_assert(is_detected_exact<bool, number_float_function_t, SAX,
number_float_t, string_t>::value,
"Missing/invalid function: bool number_float(number_float_t, const string_t&)");
static_assert(
is_detected_exact<bool, string_function_t, SAX, string_t>::value,
"Missing/invalid function: bool string(string_t&)");
static_assert(is_detected_exact<bool, start_object_function_t, SAX>::value,
"Missing/invalid function: bool start_object(std::size_t)");
static_assert(is_detected_exact<bool, key_function_t, SAX, string_t>::value,
"Missing/invalid function: bool key(string_t&)");
static_assert(is_detected_exact<bool, end_object_function_t, SAX>::value,
"Missing/invalid function: bool end_object()");
static_assert(is_detected_exact<bool, start_array_function_t, SAX>::value,
"Missing/invalid function: bool start_array(std::size_t)");
static_assert(is_detected_exact<bool, end_array_function_t, SAX>::value,
"Missing/invalid function: bool end_array()");
static_assert(
is_detected_exact<bool, parse_error_function_t, SAX, exception_t>::value,
"Missing/invalid function: bool parse_error(std::size_t, const "
"std::string&, const exception&)");
2018-07-24 20:47:41 +08:00
};
} // namespace detail
} // namespace nlohmann