simdjson 5.0.2
Ridiculously Fast JSON
Loading...
Searching...
No Matches
convert.h
1
2#ifndef SIMDJSON_CONVERT_H
3#define SIMDJSON_CONVERT_H
4
5#include "simdjson/ondemand.h"
6#include <optional>
7
8#if SIMDJSON_SUPPORTS_CONCEPTS
9
10
11namespace simdjson {
12namespace convert {
13namespace internal {
14
21template <typename parser_type = ondemand::parser*>
22struct auto_parser {
23private:
24 parser_type m_parser;
25 ondemand::document m_doc;
26 error_code m_error{SUCCESS};
27
28 template <typename T>
29 static constexpr bool is_nothrow_gettable = requires(ondemand::document doc) {
30 { doc.get<T>() } noexcept;
31 };
32public:
33 explicit auto_parser(parser_type &&parser, ondemand::document &&doc) noexcept requires(!std::is_pointer_v<parser_type>);
34 explicit auto_parser(parser_type &&parser, padded_string_view const str) noexcept requires(!std::is_pointer_v<parser_type>);
35 explicit auto_parser(std::remove_pointer_t<parser_type> &parser, ondemand::document &&doc) noexcept requires(std::is_pointer_v<parser_type>);
36 explicit auto_parser(std::remove_pointer_t<parser_type> &parser, padded_string_view const str) noexcept requires(std::is_pointer_v<parser_type>);
37 explicit auto_parser(padded_string_view const str) noexcept requires(std::is_pointer_v<parser_type>);
38 explicit auto_parser(parser_type parser, ondemand::document &&doc) noexcept requires(std::is_pointer_v<parser_type>);
39 auto_parser(auto_parser const &) = delete;
40 auto_parser &operator=(auto_parser const &) = delete;
41 ~auto_parser() = default;
42 // Prevent moving
43 auto_parser(auto_parser&&) = delete;
44 auto_parser &operator=(auto_parser &&) noexcept = delete;
45 simdjson_warn_unused std::remove_pointer_t<parser_type> &parser() noexcept;
46
47 template <typename T>
48 simdjson_warn_unused simdjson_inline simdjson_result<T> result() noexcept(is_nothrow_gettable<T>);
49 template <typename T>
50 simdjson_warn_unused simdjson_inline error_code get(T &value) && noexcept(is_nothrow_gettable<T>);
51
52
53 simdjson_warn_unused simdjson_inline simdjson_result<ondemand::array> array() noexcept;
54 simdjson_warn_unused simdjson_inline simdjson_result<ondemand::object> object() noexcept;
55 simdjson_warn_unused simdjson_inline simdjson_result<ondemand::number> number() noexcept;
56
57
58#if SIMDJSON_EXCEPTIONS
59 template <typename T>
60 simdjson_warn_unused simdjson_inline explicit(false) operator T() noexcept(false);
61#endif // SIMDJSON_EXCEPTIONS
62
63 template <typename T>
64 simdjson_warn_unused simdjson_inline std::optional<T> optional() noexcept(is_nothrow_gettable<T>);
65};
66
67
73template <typename T = void>
74struct to_adaptor {
75 T operator()(simdjson_result<ondemand::value> &val) const noexcept;
76 auto operator()(padded_string_view const str) const noexcept;
77 auto operator()(ondemand::parser &parser, padded_string_view const str) const noexcept;
78};
79// deduction guide
80auto_parser(padded_string_view const str) -> auto_parser<ondemand::parser*>;
81} // namespace internal
82} // namespace convert
83
116static constexpr convert::internal::to_adaptor<> from{};
117
118} // namespace simdjson
119
120#endif // SIMDJSON_SUPPORTS_CONCEPTS
121#endif // SIMDJSON_CONVERT_H
The top level simdjson namespace, containing everything the library provides.
Definition base.h:8
error_code
All possible errors returned by simdjson.
Definition error.h:19
@ SUCCESS
No error.
Definition error.h:20