is_sax.hpp 6.8 KB

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