1#ifndef SOURCEMETA_CORE_JSONPOINTER_TOKEN_H_
2#define SOURCEMETA_CORE_JSONPOINTER_TOKEN_H_
4#include <sourcemeta/core/json.h>
8namespace sourcemeta::core {
20 using Index =
typename Value::Array::size_type;
26 : as_property{true}, property{std::move(value)}, hash{
property_hash},
51 : as_property{true}, property{std::move(value)}, hash{hasher(property)},
88 : as_property{false}, property{DEFAULT_PROPERTY}, hash{0}, index{value} {}
100 : as_property{false}, property{DEFAULT_PROPERTY}, hash{0},
101 index{static_cast<
Index>(value)} {
116 : as_property{false}, property{DEFAULT_PROPERTY}, hash{0}, index{value} {}
130 return this->as_property;
146 return this->as_property && this->
property.size() == 1 &&
147 this->
property.front() ==
'\u002D';
160 [[nodiscard]]
auto is_index() const noexcept ->
bool {
161 return !this->as_property;
177 if constexpr (
requires { this->
property.get(); }) {
178 return this->
property.get();
180 return this->property;
196 typename Hash::hash_type {
216 const typename Hash::hash_type value_hash)
const noexcept
219 assert(hasher(value.data(), value.size()) == value_hash);
220 if constexpr (
requires { hasher.is_perfect(value_hash); }) {
225 return this->hash == value_hash &&
226 (hasher.is_perfect(value_hash)
228 : this->to_property() == value);
230 return this->hash == value_hash && this->
to_property() == value;
247 if constexpr (
requires { this->
property.get(); }) {
248 return this->
property.get();
250 return this->property;
297 if (this->as_property != other.as_property) {
299 }
else if (this->as_property) {
300 if constexpr (
requires { hasher.is_perfect(this->hash); }) {
305 if (hasher.is_perfect(this->hash) && hasher.is_perfect(other.hash)) {
306 return this->hash == other.hash &&
307 this->
to_property().size() == other.to_property().size();
311 return this->hash == other.hash &&
314 return this->index == other.index;
322 if (this->as_property && !other.as_property) {
324 }
else if (!this->as_property && other.as_property) {
326 }
else if (this->as_property) {
329 return this->index < other.index;
336 inline static const Hash hasher;
340 typename Hash::hash_type hash;
char Char
The character type used by the JSON document.
Definition json_value.h:42
std::basic_string< Char, CharTraits, Allocator< Char > > String
The string type used by the JSON document.
Definition json_value.h:52
std::basic_string_view< Char, CharTraits > StringView
The string view type used by the JSON document.
Definition json_value.h:54
typename Value::Array::size_type Index
The stored type of an array index token.
Definition jsonpointer_token.h:20
auto to_json() const -> JSON
Definition jsonpointer_token.h:286
JSON Value
The JSON value type these tokens convert to.
Definition jsonpointer_token.h:16
GenericToken(const JSON::Char value)
Definition jsonpointer_token.h:75
auto property_equals(const JSON::StringView value, const typename Hash::hash_type value_hash) const noexcept -> bool
Definition jsonpointer_token.h:215
GenericToken(const Index value)
Definition jsonpointer_token.h:87
GenericToken(const int value)
Definition jsonpointer_token.h:99
GenericToken(Property value, const typename Hash::hash_type property_hash)
Definition jsonpointer_token.h:25
auto is_hyphen() const noexcept -> bool
Definition jsonpointer_token.h:145
auto is_index() const noexcept -> bool
Definition jsonpointer_token.h:160
GenericToken(const Property &value)
Definition jsonpointer_token.h:38
auto property_hash() const noexcept -> typename Hash::hash_type
Definition jsonpointer_token.h:195
GenericToken(Property &&value)
Definition jsonpointer_token.h:50
auto to_index() const noexcept -> Index
Definition jsonpointer_token.h:265
auto is_property() const noexcept -> bool
Definition jsonpointer_token.h:129
auto to_property() const noexcept -> const auto &
Definition jsonpointer_token.h:175
GenericToken(const JSON::Char *const value)
Definition jsonpointer_token.h:63
auto to_property() noexcept -> auto &
Definition jsonpointer_token.h:245
PropertyT Property
The stored type of an object property token.
Definition jsonpointer_token.h:18