1 #ifndef SIMDJSON_GENERIC_ONDEMAND_JSON_TYPE_INL_H
3 #ifndef SIMDJSON_CONDITIONAL_INCLUDE
4 #define SIMDJSON_GENERIC_ONDEMAND_JSON_TYPE_INL_H
5 #include "simdjson/generic/ondemand/base.h"
6 #include "simdjson/generic/ondemand/json_type.h"
7 #include "simdjson/generic/implementation_simdjson_result_base-inl.h"
11 namespace SIMDJSON_IMPLEMENTATION {
22 default: SIMDJSON_UNREACHABLE();
27 #if SIMDJSON_EXCEPTIONS
29 return out << type.value();
44 return payload.unsigned_integer;
47 simdjson_inline number::operator uint64_t() const noexcept {
59 simdjson_inline number::operator int64_t() const noexcept {
68 return payload.floating_point_number;
71 simdjson_inline number::operator double() const noexcept {
77 return payload.floating_point_number;
80 return double(
payload.signed_integer);
82 return double(
payload.unsigned_integer);
86 payload.signed_integer =
value;
87 type = number_type::signed_integer;
91 payload.unsigned_integer =
value;
92 type = number_type::unsigned_integer;
96 payload.floating_point_number =
value;
97 type = number_type::floating_point_number;
101 type = number_type::floating_point_number;
111 : implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::json_type>(std::forward<SIMDJSON_IMPLEMENTATION::ondemand::json_type>(value)) {}
112 simdjson_inline simdjson_result<SIMDJSON_IMPLEMENTATION::ondemand::json_type>::simdjson_result(
error_code error) noexcept
113 : implementation_simdjson_result_base<SIMDJSON_IMPLEMENTATION::ondemand::json_type>(error) {}
An ephemeral JSON value returned during iteration.
std::ostream & operator<<(std::ostream &out, json_type type) noexcept
Write the JSON type to the output stream.
json_type
The type of a JSON value.
@ boolean
A JSON boolean (true or false)
@ object
A JSON object ( { "a": 1, "b" 2, ... } )
@ number
A JSON number ( 1 or -2.3 or 4.5e6 ...)
@ string
A JSON string ( "a" or "hello world\n" ...)
@ array
A JSON array ( [ 1, 2, 3 ... ] )
The top level simdjson namespace, containing everything the library provides.
error_code
All possible errors returned by simdjson.
simdjson_inline bool is_int64() const noexcept
return true if the automatically determined type of the number is number_type::signed_integer.
simdjson_inline double as_double() const noexcept
Convert the number to a double.
simdjson_inline bool is_double() const noexcept
return true if the automatically determined type of the number is number_type::floating_point_number.
simdjson_inline ondemand::number_type get_number_type() const noexcept
return the automatically determined type of the number: number_type::floating_point_number,...
simdjson_inline int64_t get_int64() const noexcept
return the value as a int64_t, only valid if is_int64() is true.
union simdjson::SIMDJSON_IMPLEMENTATION::ondemand::number::@0 payload
End of friend declarations.
simdjson_inline void append_u64(uint64_t value) noexcept
Store an unsigned 64-bit value to the number.
simdjson_inline double get_double() const noexcept
return the value as a double, only valid if is_double() is true.
simdjson_inline void skip_double() noexcept
Specifies that the value is a double, but leave it undefined.
simdjson_inline void append_s64(int64_t value) noexcept
Store a signed 64-bit value to the number.
simdjson_inline void append_double(double value) noexcept
Store a double value to the number.
simdjson_inline bool is_uint64() const noexcept
return true if the automatically determined type of the number is number_type::unsigned_integer.
simdjson_inline uint64_t get_uint64() const noexcept
return the value as a uint64_t, only valid if is_uint64() is true.
The result of a simdjson operation that could fail.