1#ifndef SIMDJSON_DOM_ELEMENT_H
2#define SIMDJSON_DOM_ELEMENT_H
6#include "simdjson/dom/base.h"
7#include "simdjson/dom/array.h"
36 simdjson_inline
element()
noexcept;
128 inline bool is_array()
const noexcept;
146 inline bool is_int64()
const noexcept;
172 inline bool is_bool()
const noexcept;
176 inline bool is_null()
const noexcept;
191 simdjson_inline
bool is()
const noexcept;
216 static_assert(!
sizeof(T),
"The get method with given type is not implemented by the simdjson library. "
217 "The supported types are Boolean (bool), numbers (double, uint64_t, int64_t), "
218 "strings (std::string_view, const char *), arrays (dom::array) and objects (dom::object). "
219 "We recommend you use get_double(), get_bool(), get_uint64(), get_int64(), "
220 "get_object(), get_array() or get_string() instead of the get template.");
240 simdjson_warn_unused simdjson_inline
error_code get(T &value)
const noexcept;
260#if SIMDJSON_EXCEPTIONS
267 inline operator bool() const noexcept(false);
280 inline explicit operator const
char*() const noexcept(false);
291 inline operator std::
string_view() const noexcept(false);
300 inline operator uint64_t() const noexcept(false);
308 inline operator int64_t() const noexcept(false);
315 inline operator
double() const noexcept(false);
322 inline operator
array() const noexcept(false);
329 inline operator
object() const noexcept(false);
337 inline dom::
array::iterator
begin() const noexcept(false);
345 inline dom::
array::iterator
end() const noexcept(false);
421#ifndef SIMDJSON_DISABLE_DEPRECATED_API
442 [[deprecated(
"For standard compliance, use at_pointer instead, and prefix your pointers with a slash '/', see RFC6901 ")]]
484 inline bool operator<(
const element &other)
const noexcept;
492 inline bool operator==(
const element &other)
const noexcept;
495 inline bool dump_raw_tape(std::ostream &out)
const noexcept;
498 simdjson_inline
element(
const internal::tape_ref &tape)
noexcept;
499 internal::tape_ref tape{};
500 friend class document;
505 friend class simdjson::internal::string_builder;
513struct simdjson_result<dom::element> :
public internal::simdjson_result_base<dom::element> {
521 simdjson_inline
bool is()
const noexcept;
525 simdjson_warn_unused simdjson_inline
error_code get(T &value)
const noexcept;
537 simdjson_inline
bool is_array()
const noexcept;
538 simdjson_inline
bool is_object()
const noexcept;
539 simdjson_inline
bool is_string()
const noexcept;
540 simdjson_inline
bool is_int64()
const noexcept;
541 simdjson_inline
bool is_uint64()
const noexcept;
542 simdjson_inline
bool is_double()
const noexcept;
543 simdjson_inline
bool is_number()
const noexcept;
544 simdjson_inline
bool is_bool()
const noexcept;
545 simdjson_inline
bool is_null()
const noexcept;
553 [[deprecated(
"For standard compliance, use at_pointer instead, and prefix your pointers with a slash '/', see RFC6901 ")]]
559#if SIMDJSON_EXCEPTIONS
560 simdjson_inline
operator bool()
const noexcept(
false);
561 simdjson_inline
explicit operator const char*()
const noexcept(
false);
562 simdjson_inline
operator std::string_view()
const noexcept(
false);
563 simdjson_inline
operator uint64_t()
const noexcept(
false);
564 simdjson_inline
operator int64_t()
const noexcept(
false);
565 simdjson_inline
operator double()
const noexcept(
false);
566 simdjson_inline
operator dom::array()
const noexcept(
false);
567 simdjson_inline
operator dom::object()
const noexcept(
false);
bool is_object() const noexcept
Whether this element is a json object.
bool is_double() const noexcept
Whether this element is a json number that fits in a double.
simdjson_inline element_type type() const noexcept
The type of this element.
bool is_number() const noexcept
Whether this element is a json number.
simdjson_result< T > get() const noexcept
Get the value as the provided type (T).
simdjson_result< const char * > get_c_str() const noexcept
Cast this element to a null-terminated C string.
simdjson_result< element > at_pointer(const std::string_view json_pointer) const noexcept
Get the value associated with the given JSON pointer.
simdjson_result< double > get_double() const noexcept
Cast this element to a double floating-point.
simdjson_inline bool is() const noexcept
Tell whether the value can be cast to provided type (T).
simdjson_result< element > at_key_case_insensitive(std::string_view key) const noexcept
Get the value associated with the given key in a case-insensitive manner.
void tie(T &value, error_code &error) &&noexcept
Get the value as the provided type (T), setting error if it's not the given type.
simdjson_result< bool > get_bool() const noexcept
Cast this element to a bool.
bool is_string() const noexcept
Whether this element is a json string.
simdjson_result< element > at_key(std::string_view key) const noexcept
Get the value associated with the given key.
operator std::string_view() const noexcept(false)
Read this element as a null-terminated UTF-8 string.
dom::array::iterator end() const noexcept(false)
Iterate over each element in this array.
simdjson_result< array > get_array() const noexcept
Cast this element to an array.
simdjson_result< size_t > get_string_length() const noexcept
Gives the length in bytes of the string.
simdjson_inline element() noexcept
Create a new, invalid element.
simdjson_result< uint64_t > get_uint64() const noexcept
Cast this element to an unsigned integer.
dom::array::iterator begin() const noexcept(false)
Iterate over each element in this array.
simdjson_result< element > at(const std::string_view json_pointer) const noexcept
Version 0.4 of simdjson used an incorrect interpretation of the JSON Pointer standard and allowed the...
simdjson_result< int64_t > get_int64() const noexcept
Cast this element to a signed integer.
simdjson_result< object > get_object() const noexcept
Cast this element to an object.
bool is_uint64() const noexcept
Whether this element is a json number that fits in an unsigned 64-bit integer.
simdjson_result< element > operator[](std::string_view key) const noexcept
Get the value associated with the given key.
bool is_int64() const noexcept
Whether this element is a json number that fits in a signed 64-bit integer.
bool is_null() const noexcept
Whether this element is a json null.
simdjson_result< element > at_path(std::string_view json_path) const noexcept
Get the value associated with the given JSONPath expression.
simdjson_result< std::string_view > get_string() const noexcept
Cast this element to a string.
bool is_array() const noexcept
Whether this element is a json array.
bool is_bool() const noexcept
Whether this element is a json true or false.
element_type
The actual concrete type of a JSON element This is the type it is most easily cast to with get<>.
@ UINT64
uint64_t: any integer that fits in uint64_t but not int64_t
@ DOUBLE
double: Any number with a "." or "e" that fits in double.
The top level simdjson namespace, containing everything the library provides.
error_code
All possible errors returned by simdjson.
The result of a simdjson operation that could fail.
simdjson_inline error_code error() const noexcept
The error.
simdjson_warn_unused simdjson_inline error_code get(T &value) &&noexcept
Move the value to the provided variable.