77 bool is()
const {
return this->
getType() == T::kType; }
87 return *
reinterpret_cast<const T*
>(
this);
96 operator const T*()
const {
97 return this->is<T>() ? &this->as<T>() :
nullptr;
131 enum class Tag : uint8_t {
134 kShortString = 0b00000000,
139 kString = 0b00000101,
141 kObject = 0b00000111,
143 inline static constexpr uint8_t
kTagMask = 0b00000111;
183 template <
typename T>
185 static_assert(
sizeof (
T) <=
sizeof(
Value),
"");
186 static_assert(
alignof(
T) <=
alignof(
Value),
"");
188 return (
sizeof(
T) >
sizeof(*this) / 2)
189 ?
reinterpret_cast<const T*
>(
this) + 0
190 :
reinterpret_cast<const T*
>(
this) + 1;
193 template <
typename T>
194 T*
cast() {
return const_cast<T*
>(
const_cast<const Value*
>(
this)->cast<T>()); }
197 template <
typename T>
199 static_assert(
sizeof(uintptr_t) ==
sizeof(
Value) ||
200 sizeof(uintptr_t) * 2 ==
sizeof(
Value),
"");
202 return (
sizeof(uintptr_t) <
sizeof(
Value))
204 ? *this->cast<const T*>()
206 :
reinterpret_cast<T*
>(*this->cast<uintptr_t>() & ~static_cast<uintptr_t>(
kTagMask));
210 inline static constexpr size_t kValueSize = 8;
212 uint8_t fData8[kValueSize];
214#if !defined(SK_CPU_LENDIAN)
216 static_assert(
false,
"Big-endian builds are not supported at this time.");
235 return *this->cast<bool>();
251 ?
static_cast<double>(*this->cast<int32_t>())
252 :
static_cast<double>(*this->cast<float>());
256template <
typename T, Value::Type vtype>
264 return *this->ptr<size_t>();
269 const auto* size_ptr = this->ptr<size_t>();
270 return reinterpret_cast<const T*
>(size_ptr + 1);
275 const auto* size_ptr = this->ptr<size_t>();
276 return reinterpret_cast<const T*
>(size_ptr + 1) + *size_ptr;
283 return *(this->
begin() +
i);
307 return strlen(this->cast<char>());
309 return this->cast<VectorValue<char, Value::Type::kString>>()->
size();
318 : this->cast<VectorValue<char, Value::Type::kString>>()->
begin();
323 ? strchr(this->cast<char>(),
'\0')
324 : this->cast<VectorValue<char, Value::Type::kString>>()->
end();
327 std::string_view
str()
const {
328 return std::string_view(this->
begin(), this->
size());
344 const auto* member = this->find(
key);
355 const Member* find(
const char*)
const;
360 DOM(
const char*,
size_t);
390 return this->is<ObjectValue>()
391 ? this->as<ObjectValue>()[
key]
ArrayValue(const Value *src, size_t size, SkArenaAlloc &alloc)
static constexpr Type kType
DOM(const char *, size_t)
void write(SkWStream *) const
const Value & root() const
static constexpr Type kType
static constexpr Type kType
const Value & operator[](const char *key) const
Value & writable(const char *key, SkArenaAlloc &) const
ObjectValue(const Member *src, size_t size, SkArenaAlloc &alloc)
const char * begin() const
std::string_view str() const
static constexpr Type kType
static constexpr uint8_t kTagMask
const Value & operator[](const char *key) const
SkString toString() const
void init_tagged_pointer(Tag, void *)
const T & operator[](size_t i) const
static constexpr Type kType