1 #ifndef SIMDJSON_INLINE_TAPE_REF_H
2 #define SIMDJSON_INLINE_TAPE_REF_H
4 #include "simdjson/internal/tape_ref.h"
13 simdjson_inline tape_ref::tape_ref() noexcept : doc{
nullptr}, json_index{0} {}
14 simdjson_inline tape_ref::tape_ref(
const dom::document *_doc,
size_t _json_index) noexcept : doc{_doc}, json_index{_json_index} {}
17 simdjson_inline
bool tape_ref::is_document_root() const noexcept {
18 return json_index == 1;
20 simdjson_inline
bool tape_ref::usable() const noexcept {
21 return doc !=
nullptr;
27 simdjson_inline
bool tape_ref::is_double() const noexcept {
28 constexpr uint64_t tape_double = uint64_t(tape_type::DOUBLE)<<56;
29 return doc->tape[json_index] == tape_double;
31 simdjson_inline
bool tape_ref::is_int64() const noexcept {
32 constexpr uint64_t tape_int64 = uint64_t(tape_type::INT64)<<56;
33 return doc->tape[json_index] == tape_int64;
35 simdjson_inline
bool tape_ref::is_uint64() const noexcept {
36 constexpr uint64_t tape_uint64 = uint64_t(tape_type::UINT64)<<56;
37 return doc->tape[json_index] == tape_uint64;
39 simdjson_inline
bool tape_ref::is_false() const noexcept {
40 constexpr uint64_t tape_false = uint64_t(tape_type::FALSE_VALUE)<<56;
41 return doc->tape[json_index] == tape_false;
43 simdjson_inline
bool tape_ref::is_true() const noexcept {
44 constexpr uint64_t tape_true = uint64_t(tape_type::TRUE_VALUE)<<56;
45 return doc->tape[json_index] == tape_true;
47 simdjson_inline
bool tape_ref::is_null_on_tape() const noexcept {
48 constexpr uint64_t tape_null = uint64_t(tape_type::NULL_VALUE)<<56;
49 return doc->tape[json_index] == tape_null;
52 inline size_t tape_ref::after_element() const noexcept {
53 switch (tape_ref_type()) {
54 case tape_type::START_ARRAY:
55 case tape_type::START_OBJECT:
56 return matching_brace_index();
57 case tape_type::UINT64:
58 case tape_type::INT64:
59 case tape_type::DOUBLE:
60 return json_index + 2;
62 return json_index + 1;
65 simdjson_inline tape_type tape_ref::tape_ref_type() const noexcept {
66 return static_cast<tape_type
>(doc->tape[json_index] >> 56);
68 simdjson_inline uint64_t internal::tape_ref::tape_value() const noexcept {
69 return doc->tape[json_index] & internal::JSON_VALUE_MASK;
71 simdjson_inline uint32_t internal::tape_ref::matching_brace_index() const noexcept {
72 return uint32_t(doc->tape[json_index]);
74 simdjson_inline uint32_t internal::tape_ref::scope_count() const noexcept {
75 return uint32_t((doc->tape[json_index] >> 32) & internal::JSON_COUNT_MASK);
79 simdjson_inline T tape_ref::next_tape_value() const noexcept {
80 static_assert(
sizeof(T) ==
sizeof(uint64_t),
"next_tape_value() template parameter must be 64-bit");
86 std::memcpy(&x,&doc->tape[json_index + 1],
sizeof(uint64_t));
90 simdjson_inline uint32_t internal::tape_ref::get_string_length() const noexcept {
91 size_t string_buf_index = size_t(tape_value());
93 std::memcpy(&len, &doc->string_buf[string_buf_index],
sizeof(len));
97 simdjson_inline
const char * internal::tape_ref::get_c_str() const noexcept {
98 size_t string_buf_index = size_t(tape_value());
99 return reinterpret_cast<const char *
>(&doc->string_buf[string_buf_index +
sizeof(uint32_t)]);
102 inline std::string_view internal::tape_ref::get_string_view() const noexcept {
103 return std::string_view(
We want to support argument-dependent lookup (ADL).