Class CodeRegistry

Class Documentation

class CodeRegistry

Registry for client object factories.

Public Functions

template<typename T>
void RegisterFactory(const std::string &id, std::function<T*()> factory, std::type_index type)

Register a factory for a type of code object.

Template Parameters:

Code – object base type

Parameters:
  • id – The ID of the object factory

  • factory – A factory function to make the object

  • type – The type of the object that will be returned from the factory

Throws:

ExistingValueException – If another factory of the same base type already has the provided ID

template<typename T>
bool HasFactory(const std::string &id)

Check if a factory for a given type of code object has been registered.

Parameters:

id – The ID of the object factory

Returns:

If the factory has been registered

template<typename T>
std::pair<T*, std::type_index> Instantiate(const std::string &id)

Create an object instance using a registered factory.

Template Parameters:

Code – object base type

Parameters:

id – The ID of the factory to use

Throws:

NonexistentValueException – If no factory has been registered with the provided ID for the provided base type

Returns:

A pair containing the instantiated object and its actual type

void ClearAllFactories()

Clear all factories from the registry.

Warning

For use only by the engine or runtimes

Public Static Functions

static CodeRegistry &Get()

Get the instance and create one if there isn’t one.

Returns:

The instance