|
Infinity Engine v0.6.20
C++ API Documentation
|
Global registry for type conversion functions. More...
#include <Converters.hpp>
Public Member Functions | |
| ~Converters () | |
| Destructor. | |
| bool | canConvert (const TypeID &fromType, const TypeID &toType) |
| Checks if conversion between two types is possible (runtime version). | |
| Core::Base * | convert (const TypeID &fromType, const TypeID &toType, const Core::Base *from) |
| Performs type conversion using registered converter (runtime version). | |
| ConverterFn | converter (const TypeID &fromType, const TypeID &toType) |
| Retrieves the converter function for a type pair. | |
| template<typename F , typename T > | |
| T * | convert (F *from) |
| Performs type conversion with compile-time type safety. | |
| template<typename F , typename T > | |
| bool | canConvert () |
| Checks if conversion is possible (compile-time version). | |
| template<typename F , typename T > | |
| void | registerConversion (ConverterFn fn) |
| Registers a conversion function between two types. | |
Static Public Member Functions | |
| static Converters & | instance () |
| Gets the global Converters singleton instance. | |
Global registry for type conversion functions.
Converters maintains a centralized registry of conversion functions between different types in the Infinity type system. It enables both compile-time (template-based) and runtime (TypeID-based) type conversions, supporting flexible data transformation pipelines in procedural generation workflows.
The registry allows:
Converters is implemented as a singleton that persists for the application lifetime. Conversions are typically registered during initialization and used throughout the program execution.
Example usage:
| Infinity::Types::Converters::~Converters | ( | ) |
Destructor.
Cleans up the converter registry and releases all registered conversion functions.
|
inline |
Checks if conversion is possible (compile-time version).
Template version of canConvert() that uses compile-time type information. More convenient than the runtime version when types are known at compile time.
| F | The source type. |
| T | The target type. |
|
inline |
Checks if conversion between two types is possible (runtime version).
Queries the registry to determine whether a conversion function has been registered for the specified type pair.
| Core::Base * Infinity::Types::Converters::convert | ( | const TypeID & | fromType, |
| const TypeID & | toType, | ||
| const Core::Base * | from | ||
| ) |
Performs type conversion using registered converter (runtime version).
Executes the registered conversion function for the specified type pair, transforming the source object into a new target object. The returned object is heap-allocated and must be deleted by the caller.
| fromType | The source TypeID. |
| toType | The target TypeID. |
| from | Pointer to the source object to convert. |
| std::runtime_error | if no converter is registered for this type pair. |
|
inline |
Performs type conversion with compile-time type safety.
Template version of convert() that provides compile-time type checking and automatic casting. More convenient and safer than the runtime version when types are known at compile time.
| F | The source type. |
| T | The target type. |
| from | Pointer to the source object. |
| ConverterFn Infinity::Types::Converters::converter | ( | const TypeID & | fromType, |
| const TypeID & | toType | ||
| ) |
Retrieves the converter function for a type pair.
Returns the registered converter function without executing it, allowing for deferred conversion or custom conversion workflows.
| std::runtime_error | if no converter is registered for this type pair. |
|
static |
Gets the global Converters singleton instance.
Returns a reference to the application-wide converter registry. The instance is created on first access and persists for the lifetime of the program.
|
inline |
Registers a conversion function between two types.
Adds a new converter to the registry, enabling conversion from type F to type T. The converter function should create a new object of type T from the provided object of type F.
| F | The source type. |
| T | The target type. |
| fn | The converter function to register. Must accept const Core::Base* and return Core::Base*. The function should perform appropriate casting and create a new heap-allocated object. |