1 #ifndef SIMDJSON_TAPE_REF_INL_H
2 #define SIMDJSON_TAPE_REF_INL_H
4 #include "simdjson/dom/document.h"
5 #include "simdjson/internal/tape_ref.h"
6 #include "simdjson/internal/tape_type.h"
13 constexpr
const uint64_t JSON_VALUE_MASK = 0x00FFFFFFFFFFFFFF;
14 constexpr
const uint32_t JSON_COUNT_MASK = 0xFFFFFF;
19 simdjson_inline tape_ref::tape_ref() noexcept : doc{
nullptr}, json_index{0} {}
20 simdjson_inline tape_ref::tape_ref(
const dom::document *_doc,
size_t _json_index) noexcept : doc{_doc}, json_index{_json_index} {}
23 simdjson_inline
bool tape_ref::is_document_root() const noexcept {
24 return json_index == 1;
26 simdjson_inline
bool tape_ref::usable() const noexcept {
27 return doc !=
nullptr;
33 simdjson_inline
bool tape_ref::is_double() const noexcept {
34 constexpr uint64_t tape_double = uint64_t(tape_type::DOUBLE)<<56;
35 return doc->tape[json_index] == tape_double;
37 simdjson_inline
bool tape_ref::is_int64() const noexcept {
38 constexpr uint64_t tape_int64 = uint64_t(tape_type::INT64)<<56;
39 return doc->tape[json_index] == tape_int64;
41 simdjson_inline
bool tape_ref::is_uint64() const noexcept {
42 constexpr uint64_t tape_uint64 = uint64_t(tape_type::UINT64)<<56;
43 return doc->tape[json_index] == tape_uint64;
45 simdjson_inline
bool tape_ref::is_false() const noexcept {
46 constexpr uint64_t tape_false = uint64_t(tape_type::FALSE_VALUE)<<56;
47 return doc->tape[json_index] == tape_false;
49 simdjson_inline
bool tape_ref::is_true() const noexcept {
50 constexpr uint64_t tape_true = uint64_t(tape_type::TRUE_VALUE)<<56;
51 return doc->tape[json_index] == tape_true;
53 simdjson_inline
bool tape_ref::is_null_on_tape() const noexcept {
54 constexpr uint64_t tape_null = uint64_t(tape_type::NULL_VALUE)<<56;
55 return doc->tape[json_index] == tape_null;
58 inline size_t tape_ref::after_element() const noexcept {
59 switch (tape_ref_type()) {
60 case tape_type::START_ARRAY:
61 case tape_type::START_OBJECT:
62 return matching_brace_index();
63 case tape_type::UINT64:
64 case tape_type::INT64:
65 case tape_type::DOUBLE:
66 return json_index + 2;
68 return json_index + 1;
71 simdjson_inline tape_type tape_ref::tape_ref_type() const noexcept {
72 return static_cast<tape_type
>(doc->tape[json_index] >> 56);
74 simdjson_inline uint64_t internal::tape_ref::tape_value() const noexcept {
75 return doc->tape[json_index] & internal::JSON_VALUE_MASK;
77 simdjson_inline uint32_t internal::tape_ref::matching_brace_index() const noexcept {
78 return uint32_t(doc->tape[json_index]);
80 simdjson_inline uint32_t internal::tape_ref::scope_count() const noexcept {
81 return uint32_t((doc->tape[json_index] >> 32) & internal::JSON_COUNT_MASK);
85 simdjson_inline T tape_ref::next_tape_value() const noexcept {
86 static_assert(
sizeof(T) ==
sizeof(uint64_t),
"next_tape_value() template parameter must be 64-bit");
92 std::memcpy(&x,&doc->tape[json_index + 1],
sizeof(uint64_t));
96 simdjson_inline uint32_t internal::tape_ref::get_string_length() const noexcept {
97 size_t string_buf_index = size_t(tape_value());
99 std::memcpy(&len, &doc->string_buf[string_buf_index],
sizeof(len));
103 simdjson_inline
const char * internal::tape_ref::get_c_str() const noexcept {
104 size_t string_buf_index = size_t(tape_value());
105 return reinterpret_cast<const char *
>(&doc->string_buf[string_buf_index +
sizeof(uint32_t)]);
108 inline std::string_view internal::tape_ref::get_string_view() const noexcept {
109 return std::string_view(
The top level simdjson namespace, containing everything the library provides.