simdjson 4.0.7
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
26template <typename T>
27concept is_builtin_deserializable_v = is_builtin_deserializable<T>::value;
28
29template <typename T, typename ValT = SIMDJSON_IMPLEMENTATION::ondemand::value>
30concept custom_deserializable = tag_invocable<deserialize_tag, ValT&, T&>;
31
32template <typename T, typename ValT = SIMDJSON_IMPLEMENTATION::ondemand::value>
33concept deserializable = custom_deserializable<T, ValT> || is_builtin_deserializable_v<T> || concepts::optional_type<T>;
34
35template <typename T, typename ValT = SIMDJSON_IMPLEMENTATION::ondemand::value>
36concept nothrow_custom_deserializable = nothrow_tag_invocable<deserialize_tag, ValT&, T&>;
37
38// built-in types are noexcept and if an error happens, the value simply gets ignored and the error is returned.
39template <typename T, typename ValT = SIMDJSON_IMPLEMENTATION::ondemand::value>
40concept nothrow_deserializable = nothrow_custom_deserializable<T, ValT> || is_builtin_deserializable_v<T>;
41
43inline constexpr struct deserialize_tag {
44 using array_type = SIMDJSON_IMPLEMENTATION::ondemand::array;
45 using object_type = SIMDJSON_IMPLEMENTATION::ondemand::object;
46 using value_type = SIMDJSON_IMPLEMENTATION::ondemand::value;
47 using document_type = SIMDJSON_IMPLEMENTATION::ondemand::document;
48 using document_reference_type = SIMDJSON_IMPLEMENTATION::ondemand::document_reference;
49
50 // Customization Point for array
51 template <typename T>
52 requires custom_deserializable<T, value_type>
53 simdjson_warn_unused constexpr /* error_code */ auto operator()(array_type &object, T& output) const noexcept(nothrow_custom_deserializable<T, value_type>) {
54 return tag_invoke(*this, object, output);
55 }
56
57 // Customization Point for object
58 template <typename T>
59 requires custom_deserializable<T, value_type>
60 simdjson_warn_unused constexpr /* error_code */ auto operator()(object_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 value
65 template <typename T>
66 requires custom_deserializable<T, value_type>
67 simdjson_warn_unused constexpr /* error_code */ auto operator()(value_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 document
72 template <typename T>
73 requires custom_deserializable<T, document_type>
74 simdjson_warn_unused constexpr /* error_code */ auto operator()(document_type &object, T& output) const noexcept(nothrow_custom_deserializable<T, document_type>) {
75 return tag_invoke(*this, object, output);
76 }
77
78 // Customization Point for document reference
79 template <typename T>
80 requires custom_deserializable<T, document_reference_type>
81 simdjson_warn_unused constexpr /* error_code */ auto operator()(document_reference_type &object, T& output) const noexcept(nothrow_custom_deserializable<T, document_reference_type>) {
82 return tag_invoke(*this, object, output);
83 }
84
85
86} deserialize{};
87
88} // namespace simdjson
89
90#endif // SIMDJSON_ONDEMAND_DESERIALIZE_H
91#endif // SIMDJSON_SUPPORTS_CONCEPTS
92
The top level simdjson namespace, containing everything the library provides.
Definition base.h:8