|
Infinity Engine v0.6.20
C++ API Documentation
|
Dynamic contiguous container for homogeneous elements in the Infinity type system. More...
#include <Array.hpp>
Public Types | |
| using | iterator = T * |
| using | const_iterator = const T * |
| using | reverse_iterator = std::reverse_iterator< iterator > |
| using | const_reverse_iterator = std::reverse_iterator< const_iterator > |
Public Member Functions | |
| Array () | |
| Default constructor. | |
| Array (size_t size) | |
| Constructs an array with specified size. | |
| Array (const T *data, size_t size) | |
| Constructs an array by copying data from a raw pointer. | |
| Array (const std::vector< T > &data) | |
| Constructs an array from a std::vector. | |
| Array (Core::span< T > data) | |
| Constructs an array from a span. | |
| Array (const Array &other) | |
| Copy constructor. | |
| Array (Array &&other) noexcept | |
| Move constructor. | |
| virtual | ~Array () |
| Destructor. | |
| Array & | operator= (const Array &rhs) |
| Copy assignment operator. | |
| Array & | operator= (Array &&rhs) noexcept |
| Move assignment operator. | |
| virtual const Infinity::Types::TypeID & | typeId () const override |
| Gets the TypeID for this array type. | |
| virtual const Infinity::Types::TypeID & | elementTypeId () override |
| Gets the TypeID for the element type. | |
| std::unique_ptr< Core::Base > | clone () const override |
| void | copy (const T *data, size_t count) |
| Replaces array contents by copying from raw data. | |
| T & | operator[] (size_t index) |
| Accesses element at specified index (unchecked). | |
| const T & | operator[] (size_t index) const |
| Accesses element at specified index (unchecked, const). | |
| T & | at (size_t index) |
| Accesses element at specified index (checked). | |
| const T & | at (size_t index) const |
| Accesses element at specified index (checked, const). | |
| void | push_back (const T &value) |
| Appends an element to the end of the array. | |
| template<typename... Args> | |
| void | emplace_back (Args &&... args) |
| Constructs and appends an element in-place. | |
| void | insert (size_t index, const T &value) |
| Inserts an element at the specified position. | |
| void | erase (size_t index) |
| Removes the element at the specified position. | |
| void | reserve (size_t capacity) |
| Reserves capacity for at least the specified number of elements. | |
| virtual void | resize (size_t newSize) override |
| Resizes the array to contain the specified number of elements. | |
| void | shrink_to_fit () |
| Reduces capacity to match the current size. | |
| void | clear () noexcept |
| Removes all elements from the array. | |
| virtual bool | containsData () const override |
| Checks if the array contains Core::Data-derived types. | |
| virtual bool | containsValues () const override |
| Checks if the array contains plain value types. | |
| virtual std::shared_ptr< Core::Data > | dataAt (size_t index) override |
| Gets a type-erased Data pointer to the element at the specified index. | |
| virtual std::shared_ptr< const Core::Data > | dataAt (size_t index) const override |
| Gets a const type-erased Data pointer to the element at the specified index. | |
| virtual void | setData (size_t index, const Core::Data &data) override |
| Sets an element from type-erased Data. | |
| T * | data () |
| Gets a pointer to the underlying data array. | |
| const T * | data () const |
| Gets a const pointer to the underlying data array. | |
| T * | releaseData () |
| Releases ownership of the underlying data array. | |
| T & | front () |
| Accesses the first element. | |
| const T & | front () const |
| Accesses the first element (const). | |
| T & | back () |
| Accesses the last element. | |
| const T & | back () const |
| Accesses the last element (const). | |
| size_t | size () const noexcept override |
| Gets the number of elements in the array. | |
| size_t | capacity () const noexcept |
| Gets the current capacity. | |
| bool | empty () const noexcept |
| Checks if the array is empty. | |
| virtual void * | pointer (size_t index) override |
| Gets a void pointer to the element at the specified index. | |
| virtual const void * | pointer (size_t index) const override |
| Gets a const void pointer to the element at the specified index. | |
| virtual size_t | dimensions () const noexcept override |
| Gets the number of dimensions in this container. | |
| iterator | begin () noexcept |
| Returns an iterator to the beginning. | |
| iterator | end () noexcept |
| Returns an iterator to the end. | |
| const_iterator | begin () const noexcept |
| Returns a const iterator to the beginning. | |
| const_iterator | end () const noexcept |
| Returns a const iterator to the end. | |
| reverse_iterator | rbegin () noexcept |
| Returns a reverse iterator to the beginning. | |
| reverse_iterator | rend () noexcept |
| Returns a reverse iterator to the end. | |
| const_reverse_iterator | rbegin () const noexcept |
| Returns a const reverse iterator to the beginning. | |
| const_reverse_iterator | rend () const noexcept |
| Returns a const reverse iterator to the end. | |
Public Member Functions inherited from Infinity::Types::Containers::ArrayBase | |
| ArrayBase () | |
| ArrayBase (const ArrayBase &other) | |
| virtual | ~ArrayBase ()=default |
| Virtual destructor. | |
Public Member Functions inherited from Infinity::Types::Core::Data | |
| Data () | |
| Data (const Data &other) | |
| Data (Data &&other) | |
| Data & | operator= (const Data &other) |
| Data & | operator= (Data &&other) |
| std::unique_ptr< Base > | clone () const override |
| virtual | ~Data () |
| Virtual destructor. | |
| bool | hasProperty (const std::string &key) const |
| template<typename T > | |
| void | setProperty (const std::string &key, T &&value) |
| Sets a typed property value. | |
| template<typename T > | |
| void | setProperty (const std::string &key, const T &value) |
| Sets a typed property value. | |
| void | setProperty (const std::string &key, PropertyValue &&value) |
| Sets a typed property value. | |
| const PropertyValue & | getProperty (const std::string &key) const |
| Gets a property value without type checking. | |
| template<typename T > | |
| const T & | getProperty (const std::string &key) const |
| Gets a typed property value. | |
| void | removeProperty (const std::string &key) |
Public Member Functions inherited from Infinity::Types::Core::Base | |
| virtual | ~Base () |
| Virtual destructor. | |
| virtual std::istream & | legibleDataRead (std::istream &in) override |
| Deserializes the object from a single-line text representation. | |
| virtual std::ostream & | legibleDataWrite (std::ostream &out) const override |
| Serializes the object to a single-line text representation. | |
Protected Member Functions | |
| void | swap (Array &other) noexcept |
| Swaps the contents with another array. | |
| void | reset () noexcept |
| Resets the array to an empty state. | |
| void | _reallocate (size_t newCapacity) |
| Reallocates the array with a new capacity. | |
| void | _delete () noexcept |
| Deallocates the array's memory. | |
| void | _dealloc () |
| Deallocates the array's memory. | |
Static Protected Member Functions | |
| static T * | _alloc (size_t size) |
| Allocates aligned memory for the specified number of elements. | |
Protected Attributes | |
| Core::span< T > | _data |
| Span wrapping the allocated data. | |
| size_t | _capacity |
| Total allocated capacity. | |
| size_t | _size |
| Current number of elements. | |
Friends | |
| class | Infinity::IO::Data::ArraySerializer< T > |
Additional Inherited Members | |
Public Attributes inherited from Infinity::Types::Core::Data | |
| std::unordered_map< std::string, PropertyValue > | properties |
| Property storage for arbitrary metadata. | |
Dynamic contiguous container for homogeneous elements in the Infinity type system.
Array<T> provides a type-safe, dynamically resizable container that integrates seamlessly with the Infinity Engine's type system. It supports both plain-old-data (POD) types and complex Data-derived types, automatically handling serialization, memory management, and type conversions.
Key features:
The Array automatically distinguishes between:
| T | Element type (can be POD, Core::Data-derived, or Core::Serializable) |
Example usage:
| using Infinity::Types::Containers::Array< T >::const_iterator = const T* |
| using Infinity::Types::Containers::Array< T >::const_reverse_iterator = std::reverse_iterator<const_iterator> |
| using Infinity::Types::Containers::Array< T >::iterator = T* |
| using Infinity::Types::Containers::Array< T >::reverse_iterator = std::reverse_iterator<iterator> |
|
inline |
Default constructor.
Constructs an empty array with no allocated memory.
|
inline |
Constructs an array with specified size.
Allocates memory for the specified number of elements and default-constructs them. For POD types, memory is allocated but not initialized.
| size | Number of elements to allocate and construct. |
|
inline |
Constructs an array by copying data from a raw pointer.
Allocates new memory and copies all elements from the provided data.
| data | Pointer to the source data array. |
| size | Number of elements to copy. |
|
inline |
Constructs an array from a std::vector.
Allocates memory and copies all elements from the vector.
| data | Source vector to copy from. |
|
inline |
Constructs an array from a span.
Allocates memory and copies all elements from the span.
| data | Source span to copy from. |
|
inline |
Copy constructor.
Creates a deep copy of the array, allocating new memory and copying all elements. Preserves both the size and capacity of the original array.
| other | Array to copy from. |
|
inlinenoexcept |
Move constructor.
Transfers ownership of the data from another array without copying. The source array is left in a valid but empty state.
| other | Array to move from. |
|
inlinevirtual |
Destructor.
Properly destroys all elements and deallocates memory.
|
inlinestaticprotected |
Allocates aligned memory for the specified number of elements.
Allocates memory with 64-byte alignment for optimal SIMD performance. For non-trivial types, default-constructs all elements in place.
| size | Number of elements to allocate. |
|
inlineprotected |
Deallocates the array's memory.
Destroys all elements (if non-trivial destructors) and frees the 64-byte aligned memory.
|
inlineprotectednoexcept |
Deallocates the array's memory.
Destroys all elements (if non-trivial) and frees the allocated memory. Resets the internal span to null.
|
inlineprotected |
Reallocates the array with a new capacity.
Allocates new memory and moves/copies all existing elements to the new buffer. Uses the most efficient method available: memcpy for trivially copyable types, move construction for move-constructible types, or copy construction otherwise.
| newCapacity | New capacity to allocate. |
|
inline |
Accesses element at specified index (checked).
| index | Element index. |
|
inline |
Accesses element at specified index (checked, const).
| index | Element index. |
|
inline |
Accesses the last element.
|
inline |
Accesses the last element (const).
|
inlinenoexcept |
Returns a const iterator to the beginning.
|
inlinenoexcept |
Returns an iterator to the beginning.
|
inlinenoexcept |
Gets the current capacity.
|
inlinenoexcept |
Removes all elements from the array.
Destroys all elements (if non-trivial destructors) and sets the size to zero. Does not deallocate memory - capacity remains unchanged. Use shrink_to_fit() afterward if you want to free the memory.
|
inlineoverridevirtual |
Reimplemented from Infinity::Types::Core::Base.
Reimplemented in Infinity::Types::Containers::Array2D< T >, and Infinity::Types::Containers::Array3D< T >.
|
inlineoverridevirtual |
Checks if the array contains Core::Data-derived types.
Implements Infinity::Types::Containers::ArrayBase.
|
inlineoverridevirtual |
Checks if the array contains plain value types.
Implements Infinity::Types::Containers::ArrayBase.
|
inline |
Replaces array contents by copying from raw data.
Deallocates existing memory and allocates new memory to hold the copied data. Uses memcpy for POD types and element-wise copy for complex types.
| data | Pointer to source data. |
| count | Number of elements to copy. |
|
inline |
Gets a pointer to the underlying data array.
|
inline |
Gets a const pointer to the underlying data array.
|
inlineoverridevirtual |
Gets a const type-erased Data pointer to the element at the specified index.
For Data-derived types, wraps the element directly. For POD types, wraps in a Value<T>.
| index | Element index. |
Implements Infinity::Types::Containers::ArrayBase.
|
inlineoverridevirtual |
Gets a type-erased Data pointer to the element at the specified index.
For Data-derived types, wraps the element directly. For POD types, wraps in a Value<T>.
| index | Element index. |
Implements Infinity::Types::Containers::ArrayBase.
|
inlineoverridevirtualnoexcept |
Gets the number of dimensions in this container.
Implements Infinity::Types::Containers::ArrayBase.
Reimplemented in Infinity::Types::Containers::Array2D< T >, and Infinity::Types::Containers::Array3D< T >.
|
inlineoverridevirtual |
Gets the TypeID for the element type.
For Data-derived types, returns the type directly. For POD types, returns the Value<T> wrapper type.
Implements Infinity::Types::Containers::ArrayBase.
|
inline |
Constructs and appends an element in-place.
Constructs the element directly in the array's memory, avoiding copies. If capacity is exceeded, automatically reallocates with double the capacity.
| Args | Types of constructor arguments. |
| args | Arguments forwarded to T's constructor. |
|
inlinenoexcept |
Checks if the array is empty.
|
inlinenoexcept |
Returns a const iterator to the end.
|
inlinenoexcept |
Returns an iterator to the end.
|
inline |
Removes the element at the specified position.
All elements after the removed element are shifted left. The element is properly destroyed if it has a non-trivial destructor.
| index | Position of element to remove. |
| std::out_of_range | If index >= size(). |
|
inline |
Accesses the first element.
|
inline |
Accesses the first element (const).
|
inline |
Inserts an element at the specified position.
All elements from the insertion point onward are shifted right. If capacity is exceeded, automatically reallocates with double the capacity.
| index | Position to insert at (must be <= size()). |
| value | Element to insert. |
| std::out_of_range | If index > size(). |
|
inlinenoexcept |
Move assignment operator.
Replaces the contents by moving from another array using move-and-swap idiom.
| rhs | Array to move from. |
|
inline |
Copy assignment operator.
Replaces the contents with a copy of another array using copy-and-swap idiom.
| rhs | Array to copy from. |
|
inline |
|
inline |
|
inlineoverridevirtual |
Gets a const void pointer to the element at the specified index.
Used for generic type-erased access to array elements.
| index | Element index. |
Implements Infinity::Types::Containers::ArrayBase.
|
inlineoverridevirtual |
Gets a void pointer to the element at the specified index.
Used for generic type-erased access to array elements.
| index | Element index. |
Implements Infinity::Types::Containers::ArrayBase.
|
inline |
Appends an element to the end of the array.
If capacity is exceeded, automatically reallocates with double the capacity. Initial capacity is 8 elements.
| value | Element to append (copied). |
|
inlinenoexcept |
Returns a const reverse iterator to the beginning.
|
inlinenoexcept |
Returns a reverse iterator to the beginning.
|
inline |
Releases ownership of the underlying data array.
Transfers ownership of the data pointer to the caller and leaves the array in an empty state. The caller is responsible for deallocating the memory using the appropriate deallocation method.
|
inlinenoexcept |
Returns a const reverse iterator to the end.
|
inlinenoexcept |
Returns a reverse iterator to the end.
|
inline |
Reserves capacity for at least the specified number of elements.
Does not change the size, but ensures that subsequent insertions up to the reserved capacity won't trigger reallocation.
| capacity | Minimum capacity to reserve. |
|
inlineprotectednoexcept |
Resets the array to an empty state.
Deallocates all memory and destroys all elements, leaving the array with zero size and capacity.
|
inlineoverridevirtual |
Resizes the array to contain the specified number of elements.
If newSize > size(), new elements are default-constructed. If newSize < size(), excess elements are destroyed. If newSize == size(), no action is taken.
| newSize | Target size for the array. |
Implements Infinity::Types::Containers::ArrayBase.
|
inlineoverridevirtual |
Sets an element from type-erased Data.
Unwraps the Data to the appropriate type and assigns it to the element.
| index | Element index. |
| data | Type-erased data to assign. |
| std::invalid_argument | If data is not the correct type. |
Implements Infinity::Types::Containers::ArrayBase.
|
inline |
Reduces capacity to match the current size.
Reallocates memory to eliminate unused capacity, potentially reducing memory footprint. Useful after a series of removals.
|
inlineoverridevirtualnoexcept |
Gets the number of elements in the array.
Implements Infinity::Types::Containers::ArrayBase.
|
inlineprotectednoexcept |
Swaps the contents with another array.
Efficiently exchanges all internal state between two arrays in constant time.
| other | Array to swap with. |
|
inlineoverridevirtual |
Gets the TypeID for this array type.
Reimplemented from Infinity::Types::Core::Data.
Reimplemented in Infinity::Types::Containers::Array2D< T >, and Infinity::Types::Containers::Array3D< T >.
|
friend |
|
protected |
Total allocated capacity.
|
protected |
Span wrapping the allocated data.
|
protected |
Current number of elements.