simdjson 5.0.2
Ridiculously Fast JSON
Loading...
Searching...
No Matches
deserialize.h
1#if SIMDJSON_SUPPORTS_CONCEPTS
2
3#ifndef SIMDJSON_ONDEMAND_DESERIALIZE_H
4#ifndef SIMDJSON_CONDITIONAL_INCLUDE
5#define SIMDJSON_ONDEMAND_DESERIALIZE_H
6#include "simdjson/generic/ondemand/base.h"
7#include "simdjson/generic/ondemand/array.h"
8#endif // SIMDJSON_CONDITIONAL_INCLUDE
9
10namespace simdjson {
11
12struct deserialize_tag;
13
15template <typename> struct is_builtin_deserializable : std::false_type {};
16template <> struct is_builtin_deserializable<int64_t> : std::true_type {};
17template <> struct is_builtin_deserializable<uint64_t> : std::true_type {};
18template <> struct is_builtin_deserializable<double> : std::true_type {};
19template <> struct is_builtin_deserializable<bool> : std::true_type {};
20template <> struct is_builtin_deserializable<SIMDJSON_IMPLEMENTATION::ondemand::array> : std::true_type {};
21template <> struct is_builtin_deserializable<SIMDJSON_IMPLEMENTATION::ondemand::object> : std::true_type {};
22template <> struct is_builtin_deserializable<SIMDJSON_IMPLEMENTATION::ondemand::value> : std::true_type {};
23template <> struct is_builtin_deserializable<SIMDJSON_IMPLEMENTATION::ondemand::raw_json_string> : std::true_type {};
24template <> struct is_builtin_deserializable<std::string_view> : std::true_type {};
25#if SIMDJSON_SUPPORTS_CHAR8_T
26template <> struct is_builtin_deserializable<std::u8string_view> : std::true_type {};
27#endif // SIMDJSON_SUPPORTS_CHAR8_T
28
29template <typename T>
30concept is_builtin_deserializable_v = is_builtin_deserializable<T>::value;
31
32template <typename T, typename ValT = SIMDJSON_IMPLEMENTATION::ondemand::value>
33concept custom_deserializable = tag_invocable<deserialize_tag, ValT&, T&>;
34
35template <typename T, typename ValT = SIMDJSON_IMPLEMENTATION::ondemand::value>
36concept deserializable = custom_deserializable<T, ValT> || is_builtin_deserializable_v<T> || concepts::optional_type<T>;
37
38template <typename T, typename ValT = SIMDJSON_IMPLEMENTATION::ondemand::value>
39concept nothrow_custom_deserializable = nothrow_tag_invocable<deserialize_tag, ValT&, T&>;
40
41// built-in types are noexcept and if an error happens, the value simply gets ignored and the error is returned.
42template <typename T, typename ValT = SIMDJSON_IMPLEMENTATION::ondemand::value>
43concept nothrow_deserializable = nothrow_custom_deserializable<T, ValT> || is_builtin_deserializable_v<T>;
44
45// True iff get<T>() on ValT cannot throw: no custom tag_invoke, or that tag_invoke is noexcept.
46template <typename T, typename ValT = SIMDJSON_IMPLEMENTATION::ondemand::value>
47concept nothrow_gettable = !custom_deserializable<T, ValT> || nothrow_custom_deserializable<T, ValT>;
48
50inline constexpr struct deserialize_tag {
51 using array_type = SIMDJSON_IMPLEMENTATION::ondemand::array;
52 using object_type = SIMDJSON_IMPLEMENTATION::ondemand::object;
53 using value_type = SIMDJSON_IMPLEMENTATION::ondemand::value;
54 using document_type = SIMDJSON_IMPLEMENTATION::ondemand::document;
55 using document_reference_type = SIMDJSON_IMPLEMENTATION::ondemand::document_reference;
56
57 // Customization Point for array
58 template <typename T>
59 requires custom_deserializable<T, value_type>
60 simdjson_warn_unused constexpr /* error_code */ auto operator()(array_type &object, T& output) const noexcept(nothrow_custom_deserializable<T, value_type>) {
61 return tag_invoke(*this, object, output);
62 }
63
64 // Customization Point for object
65 template <typename T>
66 requires custom_deserializable<T, value_type>
67 simdjson_warn_unused constexpr /* error_code */ auto operator()(object_type &object, T& output) const noexcept(nothrow_custom_deserializable<T, value_type>) {
68 return tag_invoke(*this, object, output);
69 }
70
71 // Customization Point for value
72 template <typename T>
73 requires custom_deserializable<T, value_type>
74 simdjson_warn_unused constexpr /* error_code */ auto operator()(value_type &object, T& output) const noexcept(nothrow_custom_deserializable<T, value_type>) {
75 return tag_invoke(*this, object, output);
76 }
77
78 // Customization Point for document
79 template <typename T>
80 requires custom_deserializable<T, document_type>
81 simdjson_warn_unused constexpr /* error_code */ auto operator()(document_type &object, T& output) const noexcept(nothrow_custom_deserializable<T, document_type>) {
82 return tag_invoke(*this, object, output);
83 }
84
85 // Customization Point for document reference
86 template <typename T>
87 requires custom_deserializable<T, document_reference_type>
88 simdjson_warn_unused constexpr /* error_code */ auto operator()(document_reference_type &object, T& output) const noexcept(nothrow_custom_deserializable<T, document_reference_type>) {
89 return tag_invoke(*this, object, output);
90 }
91
92
93} deserialize{};
94
95} // namespace simdjson
96
97#endif // SIMDJSON_ONDEMAND_DESERIALIZE_H
98#endif // SIMDJSON_SUPPORTS_CONCEPTS
99
The top level simdjson namespace, containing everything the library provides.
Definition base.h:8