Infinity Engine v0.6.20
C++ API Documentation
Loading...
Searching...
No Matches
Infinity::Types::Containers::Array< T > Class Template Reference

Dynamic contiguous container for homogeneous elements in the Infinity type system. More...

#include <Array.hpp>

Inheritance diagram for Infinity::Types::Containers::Array< T >:
[legend]
Collaboration diagram for Infinity::Types::Containers::Array< T >:
[legend]

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.
 
Arrayoperator= (const Array &rhs)
 Copy assignment operator.
 
Arrayoperator= (Array &&rhs) noexcept
 Move assignment operator.
 
virtual const Infinity::Types::TypeIDtypeId () const override
 Gets the TypeID for this array type.
 
virtual const Infinity::Types::TypeIDelementTypeId () override
 Gets the TypeID for the element type.
 
std::unique_ptr< Core::Baseclone () 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::DatadataAt (size_t index) override
 Gets a type-erased Data pointer to the element at the specified index.
 
virtual std::shared_ptr< const Core::DatadataAt (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)
 
Dataoperator= (const Data &other)
 
Dataoperator= (Data &&other)
 
std::unique_ptr< Baseclone () 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 PropertyValuegetProperty (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, PropertyValueproperties
 Property storage for arbitrary metadata.
 

Detailed Description

template<typename T>
class Infinity::Types::Containers::Array< T >

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:

  • Automatic capacity management with exponential growth
  • 64-byte aligned memory allocation for SIMD operations
  • Seamless integration with Core::Data and Core::Value<T> wrappers
  • Support for serialization and memory mapping (wrapping)
  • STL-compatible iterators and algorithms
  • Copy-on-write semantics with explicit clone() for deep copies

The Array automatically distinguishes between:

  • POD types (int, float, etc.) - stored directly with memcpy optimization
  • Core::Data types - stored with proper copy/move semantics
  • Core::Serializable types - custom serialization support
  • Core::Mappable types - zero-copy memory mapping support
Template Parameters
TElement type (can be POD, Core::Data-derived, or Core::Serializable)
Note
Array is move-only by default for efficiency. Use clone() for explicit deep copies.
Memory is always 64-byte aligned for optimal SIMD performance.

Example usage:

// Create and populate an array
Array<float> heights(1024);
for (size_t i = 0; i < heights.size(); ++i) {
heights[i] = generateHeight(i);
}
// Use with ProceduralSystem
system->setIn("heightmap", std::move(heights));
// Retrieve from output
const Array<Vector3>& positions = system->getOut<Array<Vector3>>("positions");
// Work with complex types
Array<Mesh> meshArray;
meshArray.push_back(generateMesh());
meshArray.emplace_back(vertices, indices);
Dynamic contiguous container for homogeneous elements in the Infinity type system.
Definition Array.hpp:77
void emplace_back(Args &&... args)
Constructs and appends an element in-place.
Definition Array.hpp:354
void push_back(const T &value)
Appends an element to the end of the array.
Definition Array.hpp:333

Member Typedef Documentation

◆ const_iterator

template<typename T >
using Infinity::Types::Containers::Array< T >::const_iterator = const T*

◆ const_reverse_iterator

template<typename T >
using Infinity::Types::Containers::Array< T >::const_reverse_iterator = std::reverse_iterator<const_iterator>

◆ iterator

template<typename T >
using Infinity::Types::Containers::Array< T >::iterator = T*

◆ reverse_iterator

template<typename T >
using Infinity::Types::Containers::Array< T >::reverse_iterator = std::reverse_iterator<iterator>

Constructor & Destructor Documentation

◆ Array() [1/7]

template<typename T >
Infinity::Types::Containers::Array< T >::Array ( )
inline

Default constructor.

Constructs an empty array with no allocated memory.

◆ Array() [2/7]

template<typename T >
Infinity::Types::Containers::Array< T >::Array ( size_t  size)
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.

Parameters
sizeNumber of elements to allocate and construct.

◆ Array() [3/7]

template<typename T >
Infinity::Types::Containers::Array< T >::Array ( const T *  data,
size_t  size 
)
inline

Constructs an array by copying data from a raw pointer.

Allocates new memory and copies all elements from the provided data.

Parameters
dataPointer to the source data array.
sizeNumber of elements to copy.

◆ Array() [4/7]

template<typename T >
Infinity::Types::Containers::Array< T >::Array ( const std::vector< T > &  data)
inline

Constructs an array from a std::vector.

Allocates memory and copies all elements from the vector.

Parameters
dataSource vector to copy from.

◆ Array() [5/7]

template<typename T >
Infinity::Types::Containers::Array< T >::Array ( Core::span< T >  data)
inline

Constructs an array from a span.

Allocates memory and copies all elements from the span.

Parameters
dataSource span to copy from.

◆ Array() [6/7]

template<typename T >
Infinity::Types::Containers::Array< T >::Array ( const Array< T > &  other)
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.

Parameters
otherArray to copy from.

◆ Array() [7/7]

template<typename T >
Infinity::Types::Containers::Array< T >::Array ( Array< T > &&  other)
inlinenoexcept

Move constructor.

Transfers ownership of the data from another array without copying. The source array is left in a valid but empty state.

Parameters
otherArray to move from.

◆ ~Array()

template<typename T >
virtual Infinity::Types::Containers::Array< T >::~Array ( )
inlinevirtual

Destructor.

Properly destroys all elements and deallocates memory.

Member Function Documentation

◆ _alloc()

template<typename T >
static T * Infinity::Types::Containers::Array< T >::_alloc ( size_t  size)
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.

Parameters
sizeNumber of elements to allocate.
Returns
Pointer to the allocated and initialized memory.
Note
Memory is always 64-byte aligned regardless of element type.

◆ _dealloc()

template<typename T >
void Infinity::Types::Containers::Array< T >::_dealloc ( )
inlineprotected

Deallocates the array's memory.

Destroys all elements (if non-trivial destructors) and frees the 64-byte aligned memory.

Note
Must only be called on memory allocated by _alloc().

◆ _delete()

template<typename T >
void Infinity::Types::Containers::Array< T >::_delete ( )
inlineprotectednoexcept

Deallocates the array's memory.

Destroys all elements (if non-trivial) and frees the allocated memory. Resets the internal span to null.

◆ _reallocate()

template<typename T >
void Infinity::Types::Containers::Array< T >::_reallocate ( size_t  newCapacity)
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.

Parameters
newCapacityNew capacity to allocate.
Note
Old memory is automatically deallocated after elements are transferred.

◆ at() [1/2]

template<typename T >
T & Infinity::Types::Containers::Array< T >::at ( size_t  index)
inline

Accesses element at specified index (checked).

Parameters
indexElement index.
Returns
Reference to the element.
Note
Currently does not perform bounds checking despite the name. This may be updated in future versions to throw on out-of-bounds.

◆ at() [2/2]

template<typename T >
const T & Infinity::Types::Containers::Array< T >::at ( size_t  index) const
inline

Accesses element at specified index (checked, const).

Parameters
indexElement index.
Returns
Const reference to the element.
Note
Currently does not perform bounds checking despite the name. This may be updated in future versions to throw on out-of-bounds.

◆ back() [1/2]

template<typename T >
T & Infinity::Types::Containers::Array< T >::back ( )
inline

Accesses the last element.

Returns
Reference to the last element.
Warning
Behavior is undefined if the array is empty.

◆ back() [2/2]

template<typename T >
const T & Infinity::Types::Containers::Array< T >::back ( ) const
inline

Accesses the last element (const).

Returns
Const reference to the last element.
Warning
Behavior is undefined if the array is empty.

◆ begin() [1/2]

template<typename T >
const_iterator Infinity::Types::Containers::Array< T >::begin ( ) const
inlinenoexcept

Returns a const iterator to the beginning.

Returns
Const iterator to the first element.

◆ begin() [2/2]

template<typename T >
iterator Infinity::Types::Containers::Array< T >::begin ( )
inlinenoexcept

Returns an iterator to the beginning.

Returns
Iterator to the first element.

◆ capacity()

template<typename T >
size_t Infinity::Types::Containers::Array< T >::capacity ( ) const
inlinenoexcept

Gets the current capacity.

Returns
Number of elements that can be stored without reallocation.

◆ clear()

template<typename T >
void Infinity::Types::Containers::Array< T >::clear ( )
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.

Note
This operation does not affect capacity. To reduce memory footprint, call shrink_to_fit() or reset() after clear().

◆ clone()

template<typename T >
std::unique_ptr< Core::Base > Infinity::Types::Containers::Array< T >::clone ( ) const
inlineoverridevirtual

◆ containsData()

template<typename T >
virtual bool Infinity::Types::Containers::Array< T >::containsData ( ) const
inlineoverridevirtual

Checks if the array contains Core::Data-derived types.

Returns
True if T is derived from Core::Data, false otherwise.

Implements Infinity::Types::Containers::ArrayBase.

◆ containsValues()

template<typename T >
virtual bool Infinity::Types::Containers::Array< T >::containsValues ( ) const
inlineoverridevirtual

Checks if the array contains plain value types.

Returns
True if T is not derived from Core::Data, false otherwise.

Implements Infinity::Types::Containers::ArrayBase.

◆ copy()

template<typename T >
void Infinity::Types::Containers::Array< T >::copy ( const T *  data,
size_t  count 
)
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.

Parameters
dataPointer to source data.
countNumber of elements to copy.

◆ data() [1/2]

template<typename T >
T * Infinity::Types::Containers::Array< T >::data ( )
inline

Gets a pointer to the underlying data array.

Returns
Pointer to the first element.
Warning
The pointer becomes invalid after reallocation (push_back, insert, etc.).

◆ data() [2/2]

template<typename T >
const T * Infinity::Types::Containers::Array< T >::data ( ) const
inline

Gets a const pointer to the underlying data array.

Returns
Const pointer to the first element.
Warning
The pointer becomes invalid after reallocation (push_back, insert, etc.).

◆ dataAt() [1/2]

template<typename T >
virtual std::shared_ptr< const Core::Data > Infinity::Types::Containers::Array< T >::dataAt ( size_t  index) const
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>.

Parameters
indexElement index.
Returns
Shared pointer to const type-erased data.

Implements Infinity::Types::Containers::ArrayBase.

◆ dataAt() [2/2]

template<typename T >
virtual std::shared_ptr< Core::Data > Infinity::Types::Containers::Array< T >::dataAt ( size_t  index)
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>.

Parameters
indexElement index.
Returns
Shared pointer to type-erased data.

Implements Infinity::Types::Containers::ArrayBase.

◆ dimensions()

template<typename T >
virtual size_t Infinity::Types::Containers::Array< T >::dimensions ( ) const
inlineoverridevirtualnoexcept

Gets the number of dimensions in this container.

Returns
Always returns 1 for Array (one-dimensional).

Implements Infinity::Types::Containers::ArrayBase.

Reimplemented in Infinity::Types::Containers::Array2D< T >, and Infinity::Types::Containers::Array3D< T >.

◆ elementTypeId()

template<typename T >
virtual const Infinity::Types::TypeID & Infinity::Types::Containers::Array< T >::elementTypeId ( )
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.

Returns
TypeID of the contained element type.

Implements Infinity::Types::Containers::ArrayBase.

◆ emplace_back()

template<typename T >
template<typename... Args>
void Infinity::Types::Containers::Array< T >::emplace_back ( Args &&...  args)
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.

Template Parameters
ArgsTypes of constructor arguments.
Parameters
argsArguments forwarded to T's constructor.

◆ empty()

template<typename T >
bool Infinity::Types::Containers::Array< T >::empty ( ) const
inlinenoexcept

Checks if the array is empty.

Returns
True if size() == 0, false otherwise.

◆ end() [1/2]

template<typename T >
const_iterator Infinity::Types::Containers::Array< T >::end ( ) const
inlinenoexcept

Returns a const iterator to the end.

Returns
Const iterator to one past the last element.

◆ end() [2/2]

template<typename T >
iterator Infinity::Types::Containers::Array< T >::end ( )
inlinenoexcept

Returns an iterator to the end.

Returns
Iterator to one past the last element.

◆ erase()

template<typename T >
void Infinity::Types::Containers::Array< T >::erase ( size_t  index)
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.

Parameters
indexPosition of element to remove.
Exceptions
std::out_of_rangeIf index >= size().

◆ front() [1/2]

template<typename T >
T & Infinity::Types::Containers::Array< T >::front ( )
inline

Accesses the first element.

Returns
Reference to the first element.
Warning
Behavior is undefined if the array is empty.

◆ front() [2/2]

template<typename T >
const T & Infinity::Types::Containers::Array< T >::front ( ) const
inline

Accesses the first element (const).

Returns
Const reference to the first element.
Warning
Behavior is undefined if the array is empty.

◆ insert()

template<typename T >
void Infinity::Types::Containers::Array< T >::insert ( size_t  index,
const T &  value 
)
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.

Parameters
indexPosition to insert at (must be <= size()).
valueElement to insert.
Exceptions
std::out_of_rangeIf index > size().

◆ operator=() [1/2]

template<typename T >
Array & Infinity::Types::Containers::Array< T >::operator= ( Array< T > &&  rhs)
inlinenoexcept

Move assignment operator.

Replaces the contents by moving from another array using move-and-swap idiom.

Parameters
rhsArray to move from.
Returns
Reference to this array.

◆ operator=() [2/2]

template<typename T >
Array & Infinity::Types::Containers::Array< T >::operator= ( const Array< T > &  rhs)
inline

Copy assignment operator.

Replaces the contents with a copy of another array using copy-and-swap idiom.

Parameters
rhsArray to copy from.
Returns
Reference to this array.

◆ operator[]() [1/2]

template<typename T >
T & Infinity::Types::Containers::Array< T >::operator[] ( size_t  index)
inline

Accesses element at specified index (unchecked).

Parameters
indexElement index (must be < size()).
Returns
Reference to the element.
Warning
No bounds checking. Use at() for checked access.

◆ operator[]() [2/2]

template<typename T >
const T & Infinity::Types::Containers::Array< T >::operator[] ( size_t  index) const
inline

Accesses element at specified index (unchecked, const).

Parameters
indexElement index (must be < size()).
Returns
Const reference to the element.
Warning
No bounds checking. Use at() for checked access.

◆ pointer() [1/2]

template<typename T >
virtual const void * Infinity::Types::Containers::Array< T >::pointer ( size_t  index) const
inlineoverridevirtual

Gets a const void pointer to the element at the specified index.

Used for generic type-erased access to array elements.

Parameters
indexElement index.
Returns
Const void pointer to the element.

Implements Infinity::Types::Containers::ArrayBase.

◆ pointer() [2/2]

template<typename T >
virtual void * Infinity::Types::Containers::Array< T >::pointer ( size_t  index)
inlineoverridevirtual

Gets a void pointer to the element at the specified index.

Used for generic type-erased access to array elements.

Parameters
indexElement index.
Returns
Void pointer to the element.

Implements Infinity::Types::Containers::ArrayBase.

◆ push_back()

template<typename T >
void Infinity::Types::Containers::Array< T >::push_back ( const T &  value)
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.

Parameters
valueElement to append (copied).

◆ rbegin() [1/2]

template<typename T >
const_reverse_iterator Infinity::Types::Containers::Array< T >::rbegin ( ) const
inlinenoexcept

Returns a const reverse iterator to the beginning.

Returns
Const reverse iterator to the last element.

◆ rbegin() [2/2]

template<typename T >
reverse_iterator Infinity::Types::Containers::Array< T >::rbegin ( )
inlinenoexcept

Returns a reverse iterator to the beginning.

Returns
Reverse iterator to the last element.

◆ releaseData()

template<typename T >
T * Infinity::Types::Containers::Array< T >::releaseData ( )
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.

Returns
Pointer to the data array.
Warning
The caller must manually deallocate using operator delete[] with 64-byte alignment and properly destroy all elements.

◆ rend() [1/2]

template<typename T >
const_reverse_iterator Infinity::Types::Containers::Array< T >::rend ( ) const
inlinenoexcept

Returns a const reverse iterator to the end.

Returns
Const reverse iterator to one before the first element.

◆ rend() [2/2]

template<typename T >
reverse_iterator Infinity::Types::Containers::Array< T >::rend ( )
inlinenoexcept

Returns a reverse iterator to the end.

Returns
Reverse iterator to one before the first element.

◆ reserve()

template<typename T >
void Infinity::Types::Containers::Array< T >::reserve ( size_t  capacity)
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.

Parameters
capacityMinimum capacity to reserve.
Note
If the requested capacity is less than current capacity, no action is taken.

◆ reset()

template<typename T >
void Infinity::Types::Containers::Array< T >::reset ( )
inlineprotectednoexcept

Resets the array to an empty state.

Deallocates all memory and destroys all elements, leaving the array with zero size and capacity.

◆ resize()

template<typename T >
virtual void Infinity::Types::Containers::Array< T >::resize ( size_t  newSize)
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.

Parameters
newSizeTarget size for the array.

Implements Infinity::Types::Containers::ArrayBase.

◆ setData()

template<typename T >
virtual void Infinity::Types::Containers::Array< T >::setData ( size_t  index,
const Core::Data data 
)
inlineoverridevirtual

Sets an element from type-erased Data.

Unwraps the Data to the appropriate type and assigns it to the element.

Parameters
indexElement index.
dataType-erased data to assign.
Exceptions
std::invalid_argumentIf data is not the correct type.

Implements Infinity::Types::Containers::ArrayBase.

◆ shrink_to_fit()

template<typename T >
void Infinity::Types::Containers::Array< T >::shrink_to_fit ( )
inline

Reduces capacity to match the current size.

Reallocates memory to eliminate unused capacity, potentially reducing memory footprint. Useful after a series of removals.

◆ size()

template<typename T >
size_t Infinity::Types::Containers::Array< T >::size ( ) const
inlineoverridevirtualnoexcept

Gets the number of elements in the array.

Returns
Current number of elements.

Implements Infinity::Types::Containers::ArrayBase.

◆ swap()

template<typename T >
void Infinity::Types::Containers::Array< T >::swap ( Array< T > &  other)
inlineprotectednoexcept

Swaps the contents with another array.

Efficiently exchanges all internal state between two arrays in constant time.

Parameters
otherArray to swap with.

◆ typeId()

template<typename T >
virtual const Infinity::Types::TypeID & Infinity::Types::Containers::Array< T >::typeId ( ) const
inlineoverridevirtual

Gets the TypeID for this array type.

Returns
TypeID identifying this Array<T> specialization.

Reimplemented from Infinity::Types::Core::Data.

Reimplemented in Infinity::Types::Containers::Array2D< T >, and Infinity::Types::Containers::Array3D< T >.

Friends And Related Symbol Documentation

◆ Infinity::IO::Data::ArraySerializer< T >

template<typename T >
friend class Infinity::IO::Data::ArraySerializer< T >
friend

Member Data Documentation

◆ _capacity

template<typename T >
size_t Infinity::Types::Containers::Array< T >::_capacity
protected

Total allocated capacity.

◆ _data

template<typename T >
Core::span<T> Infinity::Types::Containers::Array< T >::_data
protected

Span wrapping the allocated data.

◆ _size

template<typename T >
size_t Infinity::Types::Containers::Array< T >::_size
protected

Current number of elements.