3#include <CesiumGltf/PropertyType.h>
4#include <CesiumGltf/getOffsetFromOffsetsBuffer.h>
5#include <CesiumUtility/SpanHelper.h>
39 const ElementType&
operator[](int64_t index)
const noexcept {
40 return this->_values[
static_cast<size_t>(index)];
46 int64_t
size() const noexcept {
47 return static_cast<int64_t
>(this->_values.size());
53 auto begin() {
return this->_values.begin(); }
57 auto end() {
return this->_values.end(); }
59 auto begin()
const {
return this->_values.begin(); }
61 auto end()
const {
return this->_values.end(); }
64 std::span<const ElementType> _values;
90 : _storage(), _view() {
91 size_t numberOfElements = values.size();
92 size_t sizeInBytes = numberOfElements *
sizeof(ElementType);
93 this->_storage.resize(sizeInBytes);
95 this->_storage.data(),
96 reinterpret_cast<const std::byte*
>(values.data()),
110 : _storage(std::move(buffer)), _view(this->_storage) {}
114 : _storage(rhs._storage), _view(this->_storage) {}
118 this->_storage = rhs._storage;
129 const ElementType&
operator[](int64_t index)
const noexcept {
130 return this->_view[index];
134 int64_t
size() const noexcept {
return this->_view.size(); }
137 auto begin() {
return this->_view.begin(); }
139 auto end() {
return this->_view.end(); }
141 auto begin()
const {
return this->_view.begin(); }
143 auto end()
const {
return this->_view.end(); }
159 outBuffer = std::move(this->_storage);
166 std::vector<std::byte> _storage;
193 const std::span<const std::byte>& buffer,
195 int64_t
size) noexcept
196 : _values{buffer}, _bitOffset{bitOffset}, _size{
size} {}
203 const int64_t byteIndex = index / 8;
204 const int64_t bitIndex = index % 8;
206 static_cast<int>(_values[
static_cast<size_t>(byteIndex)] >> bitIndex) &
208 return bitValue == 1;
214 int64_t
size() const noexcept {
return _size; }
217 std::span<const std::byte> _values;
245 : _storage(), _view() {
246 size_t numberOfElements = values.size();
247 size_t sizeInBytes = (numberOfElements + 7) / 8;
248 this->_storage.resize(sizeInBytes);
250 for (
size_t byteIndex = 0, valueIndex = 0; byteIndex < sizeInBytes;
253 for (
size_t bitIndex = 0; bitIndex < 8 && valueIndex < numberOfElements;
254 bitIndex++, valueIndex++) {
255 uint8_t bit = uint8_t(values[valueIndex]);
256 byte |= bit << bitIndex;
258 this->_storage[byteIndex] = std::byte(
byte);
264 static_cast<int64_t
>(numberOfElements));
274 : _storage(rhs._storage), _view(this->_storage, 0, rhs.
size()) {}
278 this->_storage = rhs._storage;
289 bool operator[](int64_t index)
const noexcept {
return this->_view[index]; }
292 int64_t
size() const noexcept {
return this->_view.size(); }
308 outBuffer = std::move(this->_storage);
315 std::vector<std::byte> _storage;
346 const std::span<const std::byte>& values,
347 const std::span<const std::byte>& stringOffsets,
349 int64_t
size) noexcept
351 _stringOffsets{stringOffsets},
352 _stringOffsetType{stringOffsetType},
359 const size_t currentOffset = getOffsetFromOffsetsBuffer(
360 static_cast<size_t>(index),
363 const size_t nextOffset = getOffsetFromOffsetsBuffer(
364 static_cast<size_t>(index + 1),
367 return std::string_view(
368 reinterpret_cast<const char*
>(_values.data() + currentOffset),
369 (nextOffset - currentOffset));
375 int64_t
size() const noexcept {
return _size; }
378 std::span<const std::byte> _values;
379 std::span<const std::byte> _stringOffsets;
408 : _storage(), _view() {
409 size_t numberOfElements = values.size();
410 size_t totalLength = 0;
411 for (
const std::string& value : values) {
412 totalLength += value.size();
415 std::vector<std::byte> stringData(totalLength);
416 std::vector<std::byte> offsetData;
418 auto copyDataWithOffsetType = [&]<
typename TOffsetType>() {
419 offsetData.resize(
sizeof(TOffsetType) * numberOfElements + 1);
420 TOffsetType* pOffset =
reinterpret_cast<TOffsetType*
>(offsetData.data());
422 TOffsetType writeOffset = 0;
423 for (
size_t i = 0; i < numberOfElements; i++) {
424 const std::string& value = values[i];
426 stringData.data() + writeOffset,
430 *pOffset = writeOffset;
431 writeOffset += TOffsetType(value.size());
435 *pOffset = writeOffset;
439 if (totalLength <
size_t(std::numeric_limits<uint8_t>::max())) {
441 copyDataWithOffsetType.template operator()<uint8_t>();
442 }
else if (totalLength <
size_t(std::numeric_limits<uint16_t>::max())) {
444 copyDataWithOffsetType.template operator()<uint16_t>();
445 }
else if (totalLength <
size_t(std::numeric_limits<uint32_t>::max())) {
447 copyDataWithOffsetType.template operator()<uint32_t>();
450 copyDataWithOffsetType.template operator()<uint64_t>();
453 this->_storage.resize(stringData.size() + offsetData.size());
454 std::memcpy(this->_storage.data(), stringData.data(), stringData.size());
456 this->_storage.data() +
static_cast<int32_t
>(stringData.size()),
461 std::span<const std::byte>(this->_storage.data(), stringData.size()),
462 std::span<const std::byte>(
463 this->_storage.data() +
static_cast<int32_t
>(stringData.size()),
466 static_cast<int64_t
>(numberOfElements));
476 : _storage(rhs._storage), _view() {
478 size_t valueSpanSize = rhs._view._values.size();
479 size_t offsetSpanSize = this->_storage.size() - valueSpanSize;
481 std::span<const std::byte>(this->_storage.data(), valueSpanSize),
482 std::span<const std::byte>(
483 this->_storage.data() +
static_cast<int32_t
>(valueSpanSize),
485 rhs._view._stringOffsetType,
491 this->_storage = rhs._storage;
493 size_t valueSpanSize = rhs._view._values.size();
494 size_t offsetSpanSize = this->_storage.size() - valueSpanSize;
496 std::span<const std::byte>(this->_storage.data(), valueSpanSize),
497 std::span<const std::byte>(
498 this->_storage.data() +
static_cast<int32_t
>(valueSpanSize),
500 rhs._view._stringOffsetType,
512 return this->_view[index];
516 int64_t
size() const noexcept {
return this->_view.size(); }
534 outBuffer = std::move(this->_storage);
543 std::vector<std::byte> _storage;
559 for (int64_t i = 0; i <
size; ++i) {
560 if (lhs[i] != rhs[i]) {
583 return lhs.
view() == rhs;
602 return !(lhs == rhs);
612 return !(lhs == rhs);
622 return !(lhs == rhs);
632 return !(lhs == rhs);
PropertyArrayCopy(PropertyArrayCopy &&)=default
Default move constructor.
const PropertyArrayView< bool > & view() const
Obtains a PropertyArrayView over the contents of this copy.
int64_t size() const noexcept
The number of elements in this array.
PropertyArrayCopy(const std::vector< bool > &values) noexcept
Constructs a bool array copy from a vector.
PropertyArrayCopy & operator=(PropertyArrayCopy &&)=default
Default move assignment operator.
PropertyArrayView< bool > toViewAndExternalBuffer(std::vector< std::byte > &outBuffer) &&
Obtains a buffer and view from the copied data, leaving this PropertyArrayCopy empty.
PropertyArrayCopy(const PropertyArrayCopy &rhs)
Copy constructor.
PropertyArrayCopy()
Constructs an empty array copy.
bool operator[](int64_t index) const noexcept
Returns the ElementType at the given index from this copy.
PropertyArrayCopy & operator=(const PropertyArrayCopy &rhs)
Copy assignment operator.
PropertyArrayCopy()
Constructs an empty array copy.
PropertyArrayCopy(const std::vector< std::string > &values) noexcept
Constructs a string array copy from a vector.
PropertyArrayCopy(PropertyArrayCopy &&)=default
Default move constructor.
PropertyArrayCopy(const PropertyArrayCopy &rhs)
Copy constructor.
PropertyArrayCopy & operator=(const PropertyArrayCopy &rhs)
Copy assignment operator.
int64_t size() const noexcept
The number of elements in this array.
const PropertyArrayView< std::string_view > & view() const
Obtains a PropertyArrayView over the contents of this copy.
PropertyArrayCopy & operator=(PropertyArrayCopy &&)=default
Default move assignment operator.
PropertyArrayView< std::string_view > toViewAndExternalBuffer(std::vector< std::byte > &outBuffer) &&
Obtains a buffer and view from the copied data, leaving this PropertyArrayCopy empty.
std::string_view operator[](int64_t index) const noexcept
Returns the ElementType at the given index from this copy.
A copy of an array element of a PropertyTableProperty or PropertyTextureProperty.
PropertyArrayCopy & operator=(const PropertyArrayCopy &rhs)
Copy assignment operator.
PropertyArrayCopy(const std::vector< ElementType > &values) noexcept
Constructs an array copy from a vector.
auto begin() const
The begin iterator.
auto end() const
The end iterator.
auto begin()
The begin iterator.
PropertyArrayCopy & operator=(PropertyArrayCopy &&)=default
Default move assignment operator.
PropertyArrayCopy(std::vector< std::byte > &&buffer) noexcept
Creates a new PropertyArrayCopy directly from a buffer of bytes, which will be moved into this copy.
PropertyArrayCopy(const PropertyArrayCopy &rhs)
Copy constructor.
auto end()
The end iterator.
int64_t size() const noexcept
The number of elements in this array.
const ElementType & operator[](int64_t index) const noexcept
Returns the ElementType at the given index from this copy.
const PropertyArrayView< ElementType > & view() const
Obtains a PropertyArrayView over the contents of this copy.
PropertyArrayCopy(PropertyArrayCopy &&)=default
Default move constructor.
PropertyArrayCopy()
Constructs an empty array copy.
PropertyArrayView< ElementType > toViewAndExternalBuffer(std::vector< std::byte > &outBuffer) &&
Obtains a buffer and view from the copied data, leaving this PropertyArrayCopy empty.
PropertyArrayView()
Constructs an empty array view.
PropertyArrayView(const std::span< const std::byte > &buffer, int64_t bitOffset, int64_t size) noexcept
Constructs an array view from a buffer.
bool operator[](int64_t index) const noexcept
Obtains the element in the array at the given index.
int64_t size() const noexcept
The number of entries in the array.
std::string_view operator[](int64_t index) const noexcept
Obtains an std::string_view for the element at the given index.
PropertyArrayView(const std::span< const std::byte > &values, const std::span< const std::byte > &stringOffsets, PropertyComponentType stringOffsetType, int64_t size) noexcept
Constructs an array view from buffers and their information.
int64_t size() const noexcept
The number of elements in this array.
PropertyArrayView()
Constructs an empty array view.
A view on an array element of a PropertyTableProperty or PropertyTextureProperty.
auto end()
The end iterator.
const ElementType & operator[](int64_t index) const noexcept
Accesses the element of this array at the given index.
auto end() const
The end iterator.
PropertyArrayView(const std::span< const std::byte > &buffer) noexcept
Constructs an array view from a buffer.
PropertyArrayView()
Constructs an empty array view.
auto begin() const
The begin iterator.
auto begin()
The begin iterator.
int64_t size() const noexcept
The number of elements in this array.
Classes for working with glTF models.
PropertyComponentType
The possible types of a property component.
@ Uint32
A property component equivalent to a uint32_t.
@ Uint16
A property component equivalent to a uint16_t.
@ Uint8
A property component equivalent to a uint8_t.
@ Uint64
A property component equivalent to a uint32_t.
bool operator==(const PropertyArrayView< T > &lhs, const PropertyArrayView< T > &rhs)
Compares two PropertyArrayView instances by comparing their values. If the two arrays aren't the same...
bool operator!=(const PropertyArrayView< T > &lhs, const PropertyArrayView< T > &rhs)
Compares two PropertyArrayView instances and returns the inverse.
std::span< To > reintepretCastSpan(const std::span< From > &from) noexcept
This function converts between span types. This function has the same rules with C++ reintepret_cast ...