Infinity Engine v0.6.20
C++ API Documentation
Loading...
Searching...
No Matches
Infinity::Types::Containers::ArrayBase Class Referenceabstract

Abstract base class for all array container types in the Infinity type system. More...

#include <ArrayBase.hpp>

Inheritance diagram for Infinity::Types::Containers::ArrayBase:
[legend]
Collaboration diagram for Infinity::Types::Containers::ArrayBase:
[legend]

Public Member Functions

 ArrayBase ()
 
 ArrayBase (const ArrayBase &other)
 
virtual ~ArrayBase ()=default
 Virtual destructor.
 
virtual const Infinity::Types::TypeIDelementTypeId ()=0
 Gets the TypeID of the element type contained in this array.
 
virtual void * pointer (size_t index)=0
 Gets a type-erased pointer to the element at the specified index.
 
virtual const void * pointer (size_t index) const =0
 Gets a const type-erased pointer to the element at the specified index.
 
virtual bool containsData () const =0
 Checks if the array contains Core::Data-derived types.
 
virtual bool containsValues () const =0
 Checks if the array contains plain value (POD) types.
 
virtual std::shared_ptr< Core::DatadataAt (size_t index)=0
 Gets a type-erased Data pointer to the element at the specified index.
 
virtual std::shared_ptr< const Core::DatadataAt (size_t index) const =0
 Gets a const type-erased Data pointer to the element at the specified index.
 
virtual void setData (size_t index, const Core::Data &data)=0
 Sets an element from type-erased Data.
 
virtual void resize (size_t newSize)=0
 Resizes the array to contain the specified number of elements.
 
virtual size_t dimensions () const noexcept=0
 Gets the number of dimensions in this array container.
 
virtual size_t size () const noexcept=0
 Gets the total number of elements in the array.
 
- 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 const Infinity::Types::TypeIDtypeId () const override
 Gets the runtime type identifier for this object.
 
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.
 

Additional Inherited Members

- Public Attributes inherited from Infinity::Types::Core::Data
std::unordered_map< std::string, PropertyValueproperties
 Property storage for arbitrary metadata.
 

Detailed Description

Abstract base class for all array container types in the Infinity type system.

ArrayBase provides a type-erased interface for array-like containers, enabling polymorphic access to Array<T>, Array2D<T>, and Array3D<T> through a common base. This abstraction is essential for the procedural component system, allowing components to work with arrays generically without knowing the element type or dimensionality at compile time.

The class bridges the gap between strongly-typed array containers and the type-erased Data interface, providing:

  • Generic element access through type-erased pointers
  • Run-time type information (element TypeID)
  • Dimension queries (1D, 2D, or 3D)
  • Data/Value type discrimination
  • Dynamic resizing capability

This abstraction enables:

  • Generic array manipulation in ProceduralComponents
  • Type-safe downcasting when element types are known
  • Serialization and deserialization without template parameters
  • Plugin systems that work with arrays of unknown element types
Note
This is an abstract class and cannot be instantiated directly.
All concrete array types (Array, Array2D, Array3D) inherit from this base.
The class is part of the Core::Data hierarchy for seamless type system integration.

Example usage:

// Working with arrays generically in a component
void processArray(ArrayBase& array) {
// Query properties
size_t dims = array.dimensions();
size_t count = array.size();
// Check element type
if (array.elementTypeId() == getTypeID<float>()) {
// Safe to downcast
Array<float>& floatArray = static_cast<Array<float>&>(array);
// Process float array...
}
// Generic element access
for (size_t i = 0; i < array.size(); ++i) {
auto data = array.dataAt(i);
// Process element...
}
}
// Type-erased array handling in ProceduralSystem
void ProceduralComponent::setArrayInput(const std::string& port, ArrayBase& array) {
if (array.containsData()) {
// Array contains Core::Data-derived types
} else {
// Array contains POD value types
}
}
Abstract base class for all array container types in the Infinity type system.
Definition ArrayBase.hpp:72
virtual size_t size() const noexcept=0
Gets the total number of elements in the array.
virtual size_t dimensions() const noexcept=0
Gets the number of dimensions in this array container.
ArrayBase()
Definition ArrayBase.hpp:74
virtual std::shared_ptr< Core::Data > dataAt(size_t index)=0
Gets a type-erased Data pointer to the element at the specified index.
virtual const Infinity::Types::TypeID & elementTypeId()=0
Gets the TypeID of the element type contained in this array.
Dynamic contiguous container for homogeneous elements in the Infinity type system.
Definition Array.hpp:77

Constructor & Destructor Documentation

◆ ArrayBase() [1/2]

Infinity::Types::Containers::ArrayBase::ArrayBase ( )
inline

◆ ArrayBase() [2/2]

Infinity::Types::Containers::ArrayBase::ArrayBase ( const ArrayBase other)
inline

◆ ~ArrayBase()

virtual Infinity::Types::Containers::ArrayBase::~ArrayBase ( )
virtualdefault

Virtual destructor.

Ensures proper cleanup of derived array types through base class pointers.

Member Function Documentation

◆ containsData()

virtual bool Infinity::Types::Containers::ArrayBase::containsData ( ) const
pure virtual

◆ containsValues()

virtual bool Infinity::Types::Containers::ArrayBase::containsValues ( ) const
pure virtual

◆ dataAt() [1/2]

virtual std::shared_ptr< const Core::Data > Infinity::Types::Containers::ArrayBase::dataAt ( size_t  index) const
pure virtual

◆ dataAt() [2/2]

virtual std::shared_ptr< Core::Data > Infinity::Types::Containers::ArrayBase::dataAt ( size_t  index)
pure virtual

Gets a type-erased Data pointer to the element at the specified index.

Wraps the element in a Core::Data-derived type for uniform handling. For Data-derived elements, returns the element directly. For POD types, wraps in a Value<T>.

Parameters
indexElement index.
Returns
Shared pointer to type-erased Data wrapper.
Note
This creates a copy of the element. Use pointer() for direct access.
auto element = array.dataAt(5);
// Element is now accessible through Core::Data interface

Implemented in Infinity::Types::Containers::Array< T >, Infinity::Types::Containers::Array< Infinity::Types::Containers::Array2D >, Infinity::Types::Containers::Array< Infinity::Types::Containers::Array2D< float > >, Infinity::Types::Containers::Array< Infinity::Types::Math::t_Vector2 >, Infinity::Types::Containers::Array< Infinity::Types::Math::t_Vector3 >, Infinity::Types::Containers::Array< Infinity::Types::Math::t_Vector4 >, Infinity::Types::Containers::Array< Infinity::Types::Rendering::Material >, Infinity::Types::Containers::Array< Infinity::Types::Rendering::SubMesh >, Infinity::Types::Containers::Array< Infinity::Types::Spatial::Transform >, and Infinity::Types::Containers::Array< uint8_t >.

◆ dimensions()

virtual size_t Infinity::Types::Containers::ArrayBase::dimensions ( ) const
pure virtualnoexcept

Gets the number of dimensions in this array container.

Returns the dimensionality of the array:

  • 1 for Array<T> (one-dimensional)
  • 2 for Array2D<T> (two-dimensional grid)
  • 3 for Array3D<T> (three-dimensional volume)
Returns
Number of dimensions (1, 2, or 3).
if (array.dimensions() == 2) {
// Safe to cast to Array2D
Array2D<float>& array2d = static_cast<Array2D<float>&>(array);
size_t width = array2d.width();
size_t height = array2d.height();
}
Two-dimensional array container for grid-based data in procedural generation.
Definition Array2D.hpp:82
size_t width() const noexcept
Gets the width (number of columns) of the 2D array.
Definition Array2D.hpp:163
size_t height() const noexcept
Gets the height (number of rows) of the 2D array.
Definition Array2D.hpp:173

Implemented in Infinity::Types::Containers::Array< T >, Infinity::Types::Containers::Array< Infinity::Types::Containers::Array2D >, Infinity::Types::Containers::Array< Infinity::Types::Containers::Array2D< float > >, Infinity::Types::Containers::Array< Infinity::Types::Math::t_Vector2 >, Infinity::Types::Containers::Array< Infinity::Types::Math::t_Vector3 >, Infinity::Types::Containers::Array< Infinity::Types::Math::t_Vector4 >, Infinity::Types::Containers::Array< Infinity::Types::Rendering::Material >, Infinity::Types::Containers::Array< Infinity::Types::Rendering::SubMesh >, Infinity::Types::Containers::Array< Infinity::Types::Spatial::Transform >, Infinity::Types::Containers::Array< uint8_t >, Infinity::Types::Containers::Array2D< T >, and Infinity::Types::Containers::Array3D< T >.

◆ elementTypeId()

virtual const Infinity::Types::TypeID & Infinity::Types::Containers::ArrayBase::elementTypeId ( )
pure virtual

◆ pointer() [1/2]

virtual const void * Infinity::Types::Containers::ArrayBase::pointer ( size_t  index) const
pure virtual

◆ pointer() [2/2]

virtual void * Infinity::Types::Containers::ArrayBase::pointer ( size_t  index)
pure virtual

Gets a type-erased pointer to the element at the specified index.

Provides low-level access to array elements through void pointers. Useful for generic algorithms that need direct memory access.

Parameters
indexElement index (must be < size()).
Returns
Void pointer to the element.
Warning
No bounds checking is performed. Accessing out-of-bounds is undefined behavior.
The pointer becomes invalid after array reallocation or modification.

Implemented in Infinity::Types::Containers::Array< T >, Infinity::Types::Containers::Array< Infinity::Types::Containers::Array2D >, Infinity::Types::Containers::Array< Infinity::Types::Containers::Array2D< float > >, Infinity::Types::Containers::Array< Infinity::Types::Math::t_Vector2 >, Infinity::Types::Containers::Array< Infinity::Types::Math::t_Vector3 >, Infinity::Types::Containers::Array< Infinity::Types::Math::t_Vector4 >, Infinity::Types::Containers::Array< Infinity::Types::Rendering::Material >, Infinity::Types::Containers::Array< Infinity::Types::Rendering::SubMesh >, Infinity::Types::Containers::Array< Infinity::Types::Spatial::Transform >, and Infinity::Types::Containers::Array< uint8_t >.

◆ resize()

virtual void Infinity::Types::Containers::ArrayBase::resize ( size_t  newSize)
pure virtual

◆ setData()

virtual void Infinity::Types::Containers::ArrayBase::setData ( size_t  index,
const Core::Data data 
)
pure virtual

Sets an element from type-erased Data.

Unwraps the Data to the appropriate element type and assigns it to the specified index. The Data must be compatible with the array's element type.

Parameters
indexElement index to set.
dataType-erased data to assign.
Exceptions
std::invalid_argumentIf data is not compatible with element type.
ArrayBase& array = getFloatArray();
auto value = std::make_shared<Value<float>>(3.14f);
array.setData(0, *value);
virtual void setData(size_t index, const Core::Data &data)=0
Sets an element from type-erased Data.

Implemented in Infinity::Types::Containers::Array< T >, Infinity::Types::Containers::Array< Infinity::Types::Containers::Array2D >, Infinity::Types::Containers::Array< Infinity::Types::Containers::Array2D< float > >, Infinity::Types::Containers::Array< Infinity::Types::Math::t_Vector2 >, Infinity::Types::Containers::Array< Infinity::Types::Math::t_Vector3 >, Infinity::Types::Containers::Array< Infinity::Types::Math::t_Vector4 >, Infinity::Types::Containers::Array< Infinity::Types::Rendering::Material >, Infinity::Types::Containers::Array< Infinity::Types::Rendering::SubMesh >, Infinity::Types::Containers::Array< Infinity::Types::Spatial::Transform >, and Infinity::Types::Containers::Array< uint8_t >.

◆ size()