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

Abstract base class for all Infinity Engine data types. More...

#include <Base.hpp>

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

Public Member Functions

virtual ~Base ()
 Virtual destructor.
 
virtual const Infinity::Types::TypeIDtypeId () const
 Gets the runtime type identifier for this object.
 
virtual std::unique_ptr< Baseclone () const
 
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.
 

Friends

std::istream & operator>> (std::istream &in, Base &obj)
 Stream extraction operator for single-line text input.
 
std::ostream & operator<< (std::ostream &out, const Base &obj)
 Stream insertion operator for single-line text output.
 

Detailed Description

Abstract base class for all Infinity Engine data types.

Base serves as the root of the Infinity type system hierarchy, providing fundamental capabilities required by all data types in the engine:

  • Runtime type identification via TypeID
  • Binary serialization for efficient storage and transmission
  • Single-line text representation for default values and inline data

All concrete types in the Infinity Engine (meshes, textures, point clouds, procedural data, etc.) derive from Base, enabling polymorphic operations, type-safe downcasting, and unified data handling throughout the system.

Derived classes should override:

  • typeId() to return their specific type identifier

Example usage:

// Runtime type checking
if (data->typeId() == getTypeID<Mesh>()) {
Mesh* mesh = static_cast<Mesh*>(data.get());
// Use mesh...
}
See also
IOStreamLegible
TypeID

Constructor & Destructor Documentation

◆ ~Base()

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

Virtual destructor.

Ensures proper cleanup of derived class resources when deleted through a Base pointer. This is critical for polymorphic usage throughout the engine.

Member Function Documentation

◆ clone()

◆ legibleDataRead()

virtual std::istream & Infinity::Types::Core::Base::legibleDataRead ( std::istream &  in)
overridevirtual

Deserializes the object from a single-line text representation.

Reads the object's state from a compact, single-line text format. This method is specifically designed for parsing default values and inline data in component/system descriptions, configuration files, and YAML/JSON documents.

The format must be concise enough to fit on one line. For example:

  • Primitives: "4.0", "true", "42"
  • Vectors: "[1.0, 2.0, 3.0]"
  • Simple types: "{ x: 1.0, y: 2.0 }"

Derived classes should override this to parse their specific single-line format. The implementation should not expect or consume newlines.

Parameters
inInput stream to read from (text mode, single line).
Returns
Reference to the input stream (for chaining).
Note
This is NOT for multi-line or verbose serialization.
Used when parsing lines like "default: 4.0" in descriptors.
// In a component description YAML:
// inputs:
// - name: scale
// default: 4.0
std::istringstream defaultValue("4.0");
floatValue.legibleDataRead(defaultValue);

Implements Infinity::Types::Core::IOStreamLegible.

Reimplemented in Infinity::Types::Core::Value< T >.

◆ legibleDataWrite()

virtual std::ostream & Infinity::Types::Core::Base::legibleDataWrite ( std::ostream &  out) const
overridevirtual

Serializes the object to a single-line text representation.

Writes the object's state to a compact, single-line text format suitable for embedding in configuration files, component descriptions, or as default values. This method prioritizes compactness and inline readability over detailed formatting.

The output must fit on a single line without newlines. For example:

  • Primitives: "4.0", "true", "42"
  • Vectors: "[1.0, 2.0, 3.0]"
  • Simple types: "{ x: 1.0, y: 2.0 }"

Derived classes should override this to format their data as a single line. The implementation should not output newlines or multi-line formatting.

Parameters
outOutput stream to write to (text mode).
Returns
Reference to the output stream (for chaining).
Note
This is NOT for verbose or pretty-printed output.
Used when writing default values in descriptors or config files.
// Write a default value to a component description
std::ofstream desc("component.yaml");
desc << " default: ";
floatValue.legibleDataWrite(desc); // Outputs: "4.0"
desc << "\n";

Implements Infinity::Types::Core::IOStreamLegible.

Reimplemented in Infinity::Types::Core::Value< T >.

◆ typeId()

virtual const Infinity::Types::TypeID & Infinity::Types::Core::Base::typeId ( ) const
virtual

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 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::Data, 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.

Friends And Related Symbol Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream &  out,
const Base obj 
)
friend

Stream insertion operator for single-line text output.

Allows Base objects to be written to output streams using the operator. Calls legibleDataWrite() internally.

Parameters
outOutput stream to write to.
objObject to serialize.
Returns
Reference to the output stream (for chaining).
FloatValue value(4.0);
std::cout << "Value: " << value << std::endl; // Outputs: "Value: 4.0"

◆ operator>>

std::istream & operator>> ( std::istream &  in,
Base obj 
)
friend

Stream extraction operator for single-line text input.

Allows Base objects to be read from input streams using the >> operator. Calls legibleDataRead() internally.

Parameters
inInput stream to read from.
objObject to deserialize into.
Returns
Reference to the input stream (for chaining).
std::istringstream data("4.0");
FloatValue value;
data >> value; // value now contains 4.0