Infinity Engine v0.6.20
C++ API Documentation
Loading...
Searching...
No Matches
Infinity::Types::Core::Data Class Reference

Base class for complex data types with memory wrapping and property support. More...

#include <Data.hpp>

Inheritance diagram for Infinity::Types::Core::Data:
[legend]
Collaboration diagram for Infinity::Types::Core::Data:
[legend]

Public Member Functions

 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.
 

Public Attributes

std::unordered_map< std::string, PropertyValueproperties
 Property storage for arbitrary metadata.
 

Detailed Description

Base class for complex data types with memory wrapping and property support.

Data extends Base to provide support for types that:

  • Store arbitrary metadata as key-value properties
  • Have known memory sizes for efficient allocation/serialization

Data types represent substantial content like meshes, textures, point clouds, and other large data structures used in procedural generation. Unlike simple value types, Data objects typically:

  • Own or reference significant memory buffers
  • Carry metadata as properties (e.g., texture format, mesh topology info)

The property system allows attaching arbitrary metadata to data objects without modifying the core type definition, enabling extensibility and runtime customization.

Example usage:

// Create a mesh and add metadata properties
auto mesh = std::make_shared<Mesh>();
mesh->setProperty("author", std::make_shared<Value<std::string>>("John Doe"));
mesh->setProperty("lod_level", std::make_shared<Value<int>>(2));
// Retrieve properties
auto author = mesh->getProperty<Value<std::string>>("author");
if (author) {
std::cout << "Created by: " << author->get() << std::endl;
}
Template wrapper for primitive types to integrate with the Infinity type system.
Definition Value.hpp:89
T & get()
Gets a mutable reference to the underlying value.
Definition Value.inl:60
See also
Base
Value

Constructor & Destructor Documentation

◆ Data() [1/3]

Infinity::Types::Core::Data::Data ( )

◆ Data() [2/3]

Infinity::Types::Core::Data::Data ( const Data other)

◆ Data() [3/3]

Infinity::Types::Core::Data::Data ( Data &&  other)

◆ ~Data()

virtual Infinity::Types::Core::Data::~Data ( )
virtual

Virtual destructor.

Ensures proper cleanup of derived class resources.

Member Function Documentation

◆ clone()

◆ getProperty() [1/2]

const PropertyValue & Infinity::Types::Core::Data::getProperty ( const std::string &  key) const

Gets a property value without type checking.

Retrieves the property value associated with the given key as a Base pointer. The caller is responsible for type checking or casting.

Parameters
keyThe property name to look up.
Returns
Shared pointer to the property value, or nullptr if not found.
auto prop = mesh->getProperty("quality");
if (prop) {
// Property exists, cast to specific type as needed
}

◆ getProperty() [2/2]

template<typename T >
const T & Infinity::Types::Core::Data::getProperty ( const std::string &  key) const

Gets a typed property value.

Retrieves the property value associated with the given key and attempts to cast it to the specified type. This is a type-safe convenience method that performs dynamic casting automatically.

Template Parameters
TThe expected type of the property value (must derive from Base).
Parameters
keyThe property name to look up.
Returns
Shared pointer to the property value cast to type T, or nullptr if not found or if the cast fails.
auto quality = mesh->getProperty<Value<float>>("quality");
if (quality) {
std::cout << "Quality: " << quality->get() << std::endl;
}
auto author = mesh->getProperty<Value<std::string>>("author");
if (author) {
std::cout << "Author: " << author->get() << std::endl;
}
auto lodLevel = mesh->getProperty<Value<int>>("lod_level");
if (lodLevel) {
std::cout << "LOD: " << lodLevel->get() << std::endl;
}

◆ hasProperty()

bool Infinity::Types::Core::Data::hasProperty ( const std::string &  key) const

◆ operator=() [1/2]

Data & Infinity::Types::Core::Data::operator= ( const Data other)

◆ operator=() [2/2]

Data & Infinity::Types::Core::Data::operator= ( Data &&  other)

◆ removeProperty()

void Infinity::Types::Core::Data::removeProperty ( const std::string &  key)

◆ setProperty() [1/3]

template<typename T >
void Infinity::Types::Core::Data::setProperty ( const std::string &  key,
const T &  value 
)

Sets a typed property value.

Adds or updates a property with the given key. If the key already exists, the previous value is replaced. The value is copied into the property container.

Parameters
keyThe property name (e.g., "author", "lod_level").
valueThe property value. The value is copied.
mesh->setProperty("quality", std::make_shared<Value<float>>(0.95f));
mesh->setProperty("optimized", std::make_shared<Value<bool>>(true));
mesh->setProperty("name", std::make_shared<Value<std::string>>("terrain"));

◆ setProperty() [2/3]

void Infinity::Types::Core::Data::setProperty ( const std::string &  key,
PropertyValue &&  value 
)

Sets a typed property value.

Adds or updates a property with the given key. If the key already exists, the previous value is replaced.

Parameters
keyThe property name (e.g., "author", "lod_level").
valueShared pointer to the property value (any Base-derived type).
mesh->setProperty("quality", std::make_shared<Value<float>>(0.95f));
mesh->setProperty("optimized", std::make_shared<Value<bool>>(true));
mesh->setProperty("name", std::make_shared<Value<std::string>>("terrain"));

◆ setProperty() [3/3]

template<typename T >
void Infinity::Types::Core::Data::setProperty ( const std::string &  key,
T &&  value 
)

Sets a typed property value.

Adds or updates a property with the given key. If the key already exists, the previous value is replaced. The value is moved into the property container.

Parameters
keyThe property name (e.g., "author", "lod_level").
valueShared pointer to the property value (any Base-derived type).
mesh->setProperty("quality", std::make_shared<Value<float>>(0.95f));
mesh->setProperty("optimized", std::make_shared<Value<bool>>(true));
mesh->setProperty("name", std::make_shared<Value<std::string>>("terrain"));

◆ typeId()

virtual const Infinity::Types::TypeID & Infinity::Types::Core::Data::typeId ( ) const
overridevirtual

Gets the runtime type identifier for this object.

Returns the TypeID corresponding to the actual concrete type of this object. This enables runtime type checking, dynamic casting, and type-specific dispatch without RTTI overhead.

Derived classes should override this to return their specific TypeID:

const TypeID& Mesh::typeId() const override {
return getTypeID<Mesh>();
}
Runtime type identifier for the Infinity type system.
Definition TypeID.hpp:71
Returns
Const reference to the TypeID for this object's concrete type.
Note
The default implementation returns the TypeID for Base itself. All derived classes should override this method.

Reimplemented from Infinity::Types::Core::Base.

Reimplemented 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 >, Infinity::Types::Containers::Array3D< T >, Infinity::Types::Containers::ImmutableMap, Infinity::Types::Containers::Map, Infinity::Types::Core::Pair< L, R >, Infinity::Types::Core::Value< T >, Infinity::Types::Math::Ramp< T >, Infinity::Types::Procedural::Landscape, Infinity::Types::Procedural::Noise, Infinity::Types::Rendering::IndexBuffer, Infinity::Types::Rendering::Material, Infinity::Types::Rendering::Mesh, Infinity::Types::Rendering::Renderable, Infinity::Types::Rendering::RenderObject, Infinity::Types::Rendering::VertexBuffer, Infinity::Types::Spatial::Spline2D, Infinity::Types::Spatial::Spline3D, and Infinity::Types::Spatial::Spline4D.

Member Data Documentation

◆ properties

std::unordered_map<std::string, PropertyValue> Infinity::Types::Core::Data::properties

Property storage for arbitrary metadata.

Stores key-value pairs where keys are strings and values are any type derived from Base. Properties provide a flexible extension mechanism for attaching metadata without modifying type definitions.

Common uses:

  • Authoring information (creator, timestamp, source file)
  • Processing hints (LOD level, compression quality)
  • Pipeline metadata (generation parameters, dependencies)
  • Runtime tags (cached, dirty, optimized)

Primitive values should be wrapped in Value<T> template:

data->setProperty("count", std::unique_ptr<Value<int>>(42));
data->setProperty("name", std::unique_ptr<Value<std::string>>("test"));
data->setProperty("quality", std::unique_ptr<Value<float>>(0.95f));