ufe 7.0
Universal Front End is a DCC-agnostic component that will allow a DCC to browse and edit data in multiple data models
array.h
Go to the documentation of this file.
1#line 1 "D:/Jenkins/workspace/EMS/ECG/ufe/full/ufe-full-python3.13-windows/ufe/include/array.h"
2#ifndef UFE_ARRAY_H
3#define UFE_ARRAY_H
4
5// ===========================================================================
6// Copyright 2025 Autodesk, Inc. All rights reserved.
7//
8// The use of this software is subject to the Autodesk Terms of Use or other
9// license agreement provided at the time of installation or download, or
10// which otherwise accompanies this software.
11// ===========================================================================
12
13#include "common/ufeExport.h"
14
15#include "types.h"
16
17#include <algorithm>
18#include <initializer_list>
19#include <iterator>
20#include <memory>
21#include <string>
22#include <vector>
23
25
26
28
60// Forward declaration with specialization.
61template<typename T> class UFE_SDK_DECL Array;
62
63template<typename T>
65public:
66
67 // Standard container type definitions.
68 typedef T value_type;
69 typedef T& reference;
70 typedef const T& const_reference;
71 typedef T* pointer;
72 typedef const T* const_pointer;
73
74 // A pointer to an element of an array satisfies all requirements of LegacyRandomAccessIterator.
75 using iterator = T*;
76 using const_iterator = const T*;
77 typedef std::reverse_iterator<iterator> reverse_iterator;
78 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
79
80 using size_type = std::size_t;
81
84
87
89 Array(const Array&);
90
92 explicit Array(size_type count);
93
95 explicit Array(size_type count, const value_type& value);
96
98 Array(std::initializer_list<value_type> il);
99
102 template<typename InputIt>
103 Array(InputIt first, InputIt last)
104 : Array()
105 {
106 assign(first, last);
107 }
108
112 Array(Array&&) noexcept;
113
116
118
121
123 Array& operator=(const Array& other);
124
128 Array& operator=(Array&& other) noexcept;
129
131 Array& operator=(std::initializer_list<value_type> il);
132
134
137
139 iterator begin();
140
142 const_iterator begin() const;
143
145 const_iterator cbegin() const { return begin(); }
146
149
152
154 const_iterator cend() const { return end(); }
155
158
161
163 const_reverse_iterator crbegin() const { return rbegin(); }
164
167
170
172 const_reverse_iterator crend() const { return rend(); }
173
175
178
181
184
187 bool empty() const;
188
193
195
198
204
210
216
222
227
232
237
242
245
247 const value_type* data() const;
248
250
253
255 void assign(size_type n, const value_type& val);
256
258 template<typename InputIt>
259 void assign(InputIt first, InputIt last)
260 {
261 // Because of the hidden implementation, we cannot use the _imp directly here.
262 // Use a simple implementation for now that uses existing public methods.
263 clear();
264 resize(static_cast<size_type>(std::distance(first, last)));
265 std::copy(first, last, begin());
266 }
267
269 void assign(std::initializer_list<value_type> il);
270
272 void push_back(const value_type& val);
273
276
279 void pop_back();
280
284
288
291
295 template<class InputIt>
296 std::enable_if_t<!std::is_integral_v<InputIt>, iterator>
297 insert(const_iterator position, InputIt first, InputIt last)
298 {
299 const size_type insertCount = static_cast<size_type>(std::distance(first, last));
300 if (insertCount == 0)
301 return begin() + std::distance(cbegin(), position);
302
303 const size_type posIndex = static_cast<size_type>(std::distance(cbegin(), position));
304 const size_type oldSize = size();
305
306 // Check for overlap with internal storage (inserting a range of this array into itself).
307 const_pointer dataBegin = data();
308 const_pointer dataEnd = data() + oldSize;
309 auto is_pointer_in_range = [dataBegin, dataEnd](const_pointer p) {
310 return p >= dataBegin && p < dataEnd;
311 };
312
313 bool overlap = false;
314 if constexpr (std::is_pointer_v<InputIt>) {
315 // Only check for pointer iterators
316 overlap = is_pointer_in_range(first) || is_pointer_in_range(last - 1);
317 }
318
319 if (overlap) {
320 // Copy to temp buffer to avoid overlap
321 std::vector<value_type> temp(first, last);
322 resize(oldSize + insertCount);
323 std::move_backward(begin() + posIndex, begin() + oldSize, end());
324 std::copy(temp.begin(), temp.end(), begin() + posIndex);
325 } else {
326 resize(oldSize + insertCount);
327 std::move_backward(begin() + posIndex, begin() + oldSize, end());
328 std::copy(first, last, begin() + posIndex);
329 }
330 return begin() + posIndex;
331 }
332
336 iterator insert(const_iterator position, std::initializer_list<value_type> il);
337
341
345
349
353
355 void swap(Array& other);
356
363 void resize(size_type count);
364
371 void resize(size_type count, const value_type& value);
372
374 void clear();
375
378 template<typename... Args>
379 iterator emplace(const_iterator position, Args&&... args);
380
382 template<typename... Args>
383 void emplace_back(Args&&... args);
384
386
389
390 bool operator==(const Array& other) const;
391 bool operator!=(const Array& other) const;
392 bool operator<(const Array& other) const;
393 bool operator<=(const Array& other) const;
394 bool operator>(const Array& other) const;
395 bool operator>=(const Array& other) const;
396
398
399private:
400 struct Imp;
401 std::unique_ptr<Imp> _imp;
402};
403
423
424} // namespace UFE_NS_DEF
425
426#endif /* UFE_ARRAY_H */
Array is a container class that encapsulates dynamic sized arrays.
Definition: array.h:64
bool operator>(const Array &other) const
reference at(size_type n)
Returns a reference to the element at specified location pos, with bounds checking.
void resize(size_type count, const value_type &value)
Resizes the array to contain count elements.
iterator insert(const_iterator position, size_type n, const value_type &val)
Inserts n copies of val before the element at the specified position position.
std::unique_ptr< Imp > _imp
Definition: array.h:401
const T * const_pointer
Definition: array.h:72
reference back()
Returns a reference to the last element in the array.
Array()
Default constructor. Creates an empty Array.
reference front()
Returns a reference to the first element in the array.
bool operator==(const Array &other) const
void push_back(const value_type &val)
Appends an element to the end of the array.
Array(InputIt first, InputIt last)
Range constructor. Creates a Array with elements from the range [first, last).
Definition: array.h:103
bool operator<(const Array &other) const
const_reference operator[](size_type n) const
Returns a constant reference to the element at specified location n.
const_reference front() const
Returns a constant reference to the first element in the array.
iterator emplace(const_iterator position, Args &&... args)
Constructs a new element in-place at the specified position position.
std::enable_if_t<!std::is_integral_v< InputIt >, iterator > insert(const_iterator position, InputIt first, InputIt last)
Inserts copies of the elements in the range [first, last) before the element at the specified positio...
Definition: array.h:297
void swap(Array &other)
Exchanges the contents and capacity of the array with those of other.
std::size_t size_type
Definition: array.h:80
reverse_iterator rend()
Returns a reverse iterator to the beginning of the array.
Definition: array.h:166
const_reverse_iterator crend() const
Returns a constant reverse iterator to the beginning of the array.
Definition: array.h:172
T * pointer
Definition: array.h:71
bool operator!=(const Array &other) const
reverse_iterator rbegin()
Returns a reverse iterator to the end of the array.
Definition: array.h:157
void assign(size_type n, const value_type &val)
Replaces the contents with n copies of val.
std::reverse_iterator< iterator > reverse_iterator
Definition: array.h:77
iterator erase(const_iterator first, const_iterator last)
Removes the elements in the range [first, last).
iterator insert(const_iterator position, const value_type &val)
Inserts a copy of val before the element at the specified position position.
size_type size() const
Returns the number of elements in the container.
iterator erase(iterator position)
Removes the element at the specified position position.
Array(const Array &)
Copy constructor.
const T & const_reference
Definition: array.h:70
void reserve(size_type n)
Requests that the capacity be at least enough to contain n elements.
value_type * data()
Returns a pointer to this array's data.
iterator erase(iterator first, iterator last)
Removes the elements in the range [first, last).
const_reverse_iterator rbegin() const
Returns a constant reverse iterator to the end of the array.
Definition: array.h:160
size_type capacity() const
Returns the number of elements that can be held in currently allocated storage.
void assign(std::initializer_list< value_type > il)
Replaces the contents with copies of the elements in the initializer list il.
iterator insert(const_iterator position, value_type &&val)
Inserts val before the element at the specified position position possibly moving it.
void emplace_back(Args &&... args)
Constructs a new element in-place at the end of the array.
iterator erase(const_iterator position)
Removes the element at the specified position position.
const_iterator cend() const
Returns a constant iterator to the element following the last element of the array.
Definition: array.h:154
Array(Array &&) noexcept
Move constructor.
reference operator[](size_type n)
Returns a reference to the element at specified location n.
bool operator>=(const Array &other) const
Array(std::initializer_list< value_type > il)
Initializer list constructor.
void push_back(value_type &&val)
Appends an element to the end of the array.
void resize(size_type count)
Resizes the array to contain count elements.
T & reference
Definition: array.h:69
const_reference at(size_type n) const
Returns a constant reference to the element at specified location pos, with bounds checking.
Array(size_type count)
Constructs an array with count default-inserted objects of T.
const T * const_iterator
Definition: array.h:76
T * iterator
Definition: array.h:75
void pop_back()
Removes the last element of the array.
const_reverse_iterator rend() const
Returns a constant reverse iterator to the beginning of the array.
Definition: array.h:169
const_reference back() const
Returns a constant reference to the last element in the array.
T value_type
Definition: array.h:68
void assign(InputIt first, InputIt last)
Replaces the contents with copies of the elements in the range [first, last).
Definition: array.h:259
bool empty() const
Checks if the array has no elements.
bool operator<=(const Array &other) const
iterator end()
Returns an iterator to the element following the last element of the array.
Array(size_type count, const value_type &value)
Constructs an array with count copies of elements with value value.
const_iterator end() const
Returns a constant iterator to the element following the last element of the array.
const value_type * data() const
Returns a const pointer to this array's data.
const_reverse_iterator crbegin() const
Returns a constant reverse iterator to the end of the array.
Definition: array.h:163
void clear()
Removes all elements from the array. The array will be empty after this call.
iterator insert(const_iterator position, std::initializer_list< value_type > il)
Inserts copies of the elements in the initializer list il before the element at the specified positio...
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition: array.h:78
Array< std::string > StringArray
Definition: array.h:409
Array< Vector3d > Vector3dArray
Definition: array.h:415
Array< Vector3f > Vector3fArray
Definition: array.h:414
Array< Vector4i > Vector4iArray
Definition: array.h:416
Array< Vector3i > Vector3iArray
Definition: array.h:413
Array< Matrix3d > Matrix3dArray
Definition: array.h:421
Array< Vector4f > Vector4fArray
Definition: array.h:417
Array< double > DoubleArray
Definition: array.h:408
Array< Color3f > Color3fArray
Definition: array.h:419
Array< Matrix4d > Matrix4dArray
Definition: array.h:422
Array< int > IntArray
Definition: array.h:405
Array< Vector2i > Vector2iArray
Definition: array.h:410
Array< Color4f > Color4fArray
Definition: array.h:420
Array< unsigned int > UIntArray
Definition: array.h:406
Array< Vector2f > Vector2fArray
Definition: array.h:411
Array< Vector4d > Vector4dArray
Definition: array.h:418
Array< float > FloatArray
Definition: array.h:407
Array< Vector2d > Vector2dArray
Definition: array.h:412
Array< bool > BoolArray
Definition: array.h:404
Definition: path.h:202
#define UFE_NS_DEF
Definition: ufe.h:36
Definition of macros for symbol visibility.
#define UFE_SDK_DECL
Definition: ufeExport.h:35