3#include "CesiumGltf/PropertyType.h"
4#include "getOffsetFromOffsetsBuffer.h"
6#include <CesiumUtility/SpanHelper.h>
41 const ElementType&
operator[](int64_t index)
const noexcept {
42 return this->_values[index];
48 int64_t
size() const noexcept {
return 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()),
109 : _storage(std::move(buffer)), _view(this->_storage) {}
113 : _storage(rhs._storage), _view(this->_storage) {}
117 this->_storage = rhs._storage;
128 const ElementType&
operator[](int64_t index)
const noexcept {
129 return this->_view[index];
133 int64_t
size() const noexcept {
return this->_view.size(); }
136 auto begin() {
return this->_view.begin(); }
138 auto end() {
return this->_view.end(); }
140 auto begin()
const {
return this->_view.begin(); }
142 auto end()
const {
return this->_view.end(); }
158 outBuffer = std::move(this->_storage);
165 std::vector<std::byte> _storage;
192 const std::span<const std::byte>& buffer,
194 int64_t
size) noexcept
195 : _values{buffer}, _bitOffset{bitOffset}, _size{
size} {}
202 const int64_t byteIndex = index / 8;
203 const int64_t bitIndex = index % 8;
204 const int bitValue =
static_cast<int>(_values[byteIndex] >> bitIndex) & 1;
205 return bitValue == 1;
211 int64_t
size() const noexcept {
return _size; }
214 std::span<const std::byte> _values;
246 const std::span<const std::byte>& values,
247 const std::span<const std::byte>& stringOffsets,
249 int64_t
size) noexcept
251 _stringOffsets{stringOffsets},
252 _stringOffsetType{stringOffsetType},
259 const size_t currentOffset =
260 getOffsetFromOffsetsBuffer(index, _stringOffsets, _stringOffsetType);
261 const size_t nextOffset = getOffsetFromOffsetsBuffer(
265 return std::string_view(
266 reinterpret_cast<const char*
>(_values.data() + currentOffset),
267 (nextOffset - currentOffset));
273 int64_t
size() const noexcept {
return _size; }
276 std::span<const std::byte> _values;
277 std::span<const std::byte> _stringOffsets;
289 int64_t size = lhs.
size();
290 if (size != rhs.
size()) {
294 for (int64_t i = 0; i < size; ++i) {
295 if (lhs[i] != rhs[i]) {
318 return lhs.
view() == rhs;
337 return !(lhs == rhs);
347 return !(lhs == rhs);
357 return !(lhs == rhs);
367 return !(lhs == rhs);
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 view from a buffer.
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 view.
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.
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 ...