3 #include "CesiumGltf/PropertyType.h"
4 #include "getOffsetFromOffsetsBuffer.h"
6 #include <CesiumUtility/SpanHelper.h>
37 : _values{CesiumUtility::reintepretCastSpan<const ElementType>(buffer)} {}
39 const ElementType& operator[](int64_t index)
const noexcept {
40 return this->_values[index];
43 int64_t size() const noexcept {
return this->_values.size(); }
45 auto begin() {
return this->_values.begin(); }
46 auto end() {
return this->_values.end(); }
47 auto begin()
const {
return this->_values.begin(); }
48 auto end()
const {
return this->_values.end(); }
51 gsl::span<const ElementType> _values;
77 : _storage(), _view() {
78 size_t numberOfElements = values.size();
79 size_t sizeInBytes = numberOfElements *
sizeof(ElementType);
80 this->_storage.resize(sizeInBytes);
82 this->_storage.data(),
83 reinterpret_cast<const std::byte*
>(values.data()),
92 : _storage(std::move(buffer)), _view(this->_storage) {}
95 : _storage(rhs._storage), _view(this->_storage) {}
98 this->_storage = rhs._storage;
99 this->_view = PropertyArrayView<ElementType>(this->_storage);
103 const ElementType& operator[](int64_t index)
const noexcept {
104 return this->_view[index];
107 int64_t size() const noexcept {
return this->_view.size(); }
109 auto begin() {
return this->_view.begin(); }
110 auto end() {
return this->_view.end(); }
111 auto begin()
const {
return this->_view.begin(); }
112 auto end()
const {
return this->_view.end(); }
114 const PropertyArrayView<ElementType>& view()
const {
return this->_view; }
116 PropertyArrayView<ElementType>
117 toViewAndExternalBuffer(std::vector<std::byte>& outBuffer) && {
118 outBuffer = std::move(this->_storage);
119 PropertyArrayView<ElementType> result = std::move(this->_view);
120 this->_view = PropertyArrayView<ElementType>();
125 std::vector<std::byte> _storage;
126 PropertyArrayView<ElementType> _view;
145 const gsl::span<const std::byte>& buffer,
147 int64_t size) noexcept
148 : _values{buffer}, _bitOffset{bitOffset}, _size{size} {}
150 bool operator[](int64_t index)
const noexcept {
152 const int64_t byteIndex = index / 8;
153 const int64_t bitIndex = index % 8;
154 const int bitValue =
static_cast<int>(_values[byteIndex] >> bitIndex) & 1;
155 return bitValue == 1;
158 int64_t size() const noexcept {
return _size; }
161 gsl::span<const std::byte> _values;
174 _stringOffsetType{PropertyComponentType::None},
186 const gsl::span<const std::byte>& values,
187 const gsl::span<const std::byte>& stringOffsets,
188 PropertyComponentType stringOffsetType,
189 int64_t size) noexcept
191 _stringOffsets{stringOffsets},
192 _stringOffsetType{stringOffsetType},
195 std::string_view operator[](int64_t index)
const noexcept {
196 const size_t currentOffset =
197 getOffsetFromOffsetsBuffer(index, _stringOffsets, _stringOffsetType);
198 const size_t nextOffset = getOffsetFromOffsetsBuffer(
202 return std::string_view(
203 reinterpret_cast<const char*
>(_values.data() + currentOffset),
204 (nextOffset - currentOffset));
207 int64_t size() const noexcept {
return _size; }
210 gsl::span<const std::byte> _values;
211 gsl::span<const std::byte> _stringOffsets;
212 PropertyComponentType _stringOffsetType;
216 template <
typename T>
218 const PropertyArrayView<T>& lhs,
219 const PropertyArrayView<T>& rhs) {
220 int64_t size = lhs.size();
221 if (size != rhs.size()) {
225 for (int64_t i = 0; i < size; ++i) {
226 if (lhs[i] != rhs[i]) {
234 template <
typename T>
236 const PropertyArrayView<T>& lhs,
237 const PropertyArrayCopy<T>& rhs) {
238 return lhs == PropertyArrayView(rhs);
241 template <
typename T>
243 const PropertyArrayCopy<T>& lhs,
244 const PropertyArrayView<T>& rhs) {
245 return lhs.view() == rhs;
248 template <
typename T>
250 const PropertyArrayCopy<T>& lhs,
251 const PropertyArrayCopy<T>& rhs) {
252 return lhs.view() == rhs.view();
255 template <
typename T>
257 const PropertyArrayView<T>& lhs,
258 const PropertyArrayView<T>& rhs) {
259 return !(lhs == rhs);
262 template <
typename T>
264 const PropertyArrayView<T>& lhs,
265 const PropertyArrayCopy<T>& rhs) {
266 return !(lhs == rhs);
269 template <
typename T>
271 const PropertyArrayCopy<T>& lhs,
272 const PropertyArrayView<T>& rhs) {
273 return !(lhs == rhs);
276 template <
typename T>
278 const PropertyArrayCopy<T>& lhs,
279 const PropertyArrayCopy<T>& rhs) {
280 return !(lhs == rhs);
A copy of an array element of a PropertyTableProperty or PropertyTextureProperty.
PropertyArrayCopy(const std::vector< ElementType > &values) noexcept
Constructs an array view from a buffer.
PropertyArrayCopy()
Constructs an empty array view.
PropertyArrayView()
Constructs an empty array view.
PropertyArrayView(const gsl::span< const std::byte > &buffer, int64_t bitOffset, int64_t size) noexcept
Constructs an array view from a buffer.
PropertyArrayView(const gsl::span< const std::byte > &values, const gsl::span< const std::byte > &stringOffsets, PropertyComponentType stringOffsetType, int64_t size) noexcept
Constructs an array view from buffers and their information.
PropertyArrayView()
Constructs an empty array view.
A view on an array element of a PropertyTableProperty or PropertyTextureProperty.
PropertyArrayView(const gsl::span< const std::byte > &buffer) noexcept
Constructs an array view from a buffer.
PropertyArrayView()
Constructs an empty array view.
Classes for working with glTF models.