Aeon Engine c550894
AeonGames Open Source Game Engine
Loading...
Searching...
No Matches
AeonGames::Factory< T, Types > Class Template Reference

Generic factory that registers and invokes named constructors for a given type. More...

#include <C:/Code/AeonEngine/engine/include/Factory.h>

Collaboration diagram for AeonGames::Factory< T, Types >:
Collaboration graph

Public Types

using Constructor = std::tuple<StringId, std::function < std::unique_ptr<T> ( Types... args ) >>
 Tuple pairing a StringId identifier with a constructor function.

Static Public Member Functions

static std::unique_ptr< T > Construct (uint32_t aIdentifier, Types... args)
 Constructs an object by its numeric identifier.
static std::unique_ptr< T > Construct (const std::string &aIdentifier, Types... args)
 Constructs an object by its string identifier.
static bool RegisterConstructor (const StringId &aIdentifier, const std::function< std::unique_ptr< T >(Types... args) > &aConstructor)
 Registers a constructor function with the given identifier.
static bool UnregisterConstructor (const StringId &aIdentifier)
 Unregisters the constructor with the given identifier.
static void EnumerateConstructors (const std::function< bool(const StringId &) > &aEnumerator)
 Enumerates all registered constructors, calling the provided function for each.
static std::vector< std::string > GetConstructorNames ()
 Returns the names of all registered constructors.

Detailed Description

template<class T, typename... Types>
class AeonGames::Factory< T, Types >

Generic factory that registers and invokes named constructors for a given type.

Template Parameters
TThe base type produced by the factory.
TypesAdditional argument types forwarded to the constructor.

Definition at line 107 of file Factory.h.

Member Typedef Documentation

◆ Constructor

template<class T, typename... Types>
using AeonGames::Factory< T, Types >::Constructor = std::tuple<StringId, std::function < std::unique_ptr<T> ( Types... args ) >>

Tuple pairing a StringId identifier with a constructor function.

Definition at line 111 of file Factory.h.

Member Function Documentation

◆ Construct() [1/2]

template<class T, typename... Types>
std::unique_ptr< T > AeonGames::Factory< T, Types >::Construct ( const std::string & aIdentifier,
Types... args )
inlinestatic

Constructs an object by its string identifier.

Parameters
aIdentifierString identifier (hashed to CRC32 internally).
argsAdditional arguments forwarded to the constructor.
Returns
A unique_ptr to the constructed object, or nullptr if not found.

Definition at line 133 of file Factory.h.

◆ Construct() [2/2]

template<class T, typename... Types>
std::unique_ptr< T > AeonGames::Factory< T, Types >::Construct ( uint32_t aIdentifier,
Types... args )
inlinestatic

Constructs an object by its numeric identifier.

Parameters
aIdentifierCRC32 identifier.
argsAdditional arguments forwarded to the constructor.
Returns
A unique_ptr to the constructed object, or nullptr if not found.

Definition at line 116 of file Factory.h.

◆ EnumerateConstructors()

template<class T, typename... Types>
void AeonGames::Factory< T, Types >::EnumerateConstructors ( const std::function< bool(const StringId &) > & aEnumerator)
inlinestatic

Enumerates all registered constructors, calling the provided function for each.

Parameters
aEnumeratorCallback receiving a StringId; return false to stop enumeration.

Definition at line 174 of file Factory.h.

◆ GetConstructorNames()

template<class T, typename... Types>
std::vector< std::string > AeonGames::Factory< T, Types >::GetConstructorNames ( )
inlinestatic

Returns the names of all registered constructors.

Definition at line 186 of file Factory.h.

◆ RegisterConstructor()

template<class T, typename... Types>
bool AeonGames::Factory< T, Types >::RegisterConstructor ( const StringId & aIdentifier,
const std::function< std::unique_ptr< T >(Types... args) > & aConstructor )
inlinestatic

Registers a constructor function with the given identifier.

Parameters
aIdentifierIdentifier for the constructor.
aConstructorFunction that creates instances of T.
Returns
true if registration succeeded, false if the identifier is already registered.

Definition at line 141 of file Factory.h.

◆ UnregisterConstructor()

template<class T, typename... Types>
bool AeonGames::Factory< T, Types >::UnregisterConstructor ( const StringId & aIdentifier)
inlinestatic

Unregisters the constructor with the given identifier.

Parameters
aIdentifierIdentifier of the constructor to remove.
Returns
true if the constructor was found and removed, false otherwise.

Definition at line 158 of file Factory.h.


The documentation for this class was generated from the following file: