C4 Engine
C4 Engine API Documentation

class Creator

Defined in:  C4Creation.h
The Creator class template encapsulates a creator callback function for application-defined subclasses.
Definition

template <class type, typename param = Unpacker&> class Creator : public ListElement<Creator<type, param>>

Template Parameters
type The type of the base class for the application-defined class.
param The type of the data passed to the creator callback function.
Constructor

Creator(CreatorCallback *callback);

Parameters
callback A pointer to the creator callback function.
Description
The Creator class template encapsulates a creator callback function that is called when the engine encounters an object that is a subclass of the template parameter, but is of an application-defined type. The CreatorCallback type is defined as follows.

typedef type *CreatorCallback(param data);

An application should define a function having this signature, create a Creator instance to encapsulate it, and then install the creator object by calling the Creatable::InstallCreator function.

When the engine calls the creator callback function specified by the callback parameter, it passes in the custom data type specified by the param template parameter, which is normally a reference to an Unpacker object. The application should examine this data (normally by calling the Unpacker::GetType function) and return a newly created class instance corresponding to that type if it is recognized. If the type is not recognized, then the callback function should return nullptr to indicate that the remaining installed creator objects are to be given the opportunity to create the subclass.
Base Classes
ListElement<Creator<type, param>> The Creatable class holds a list of Creator instances.
See Also

Creatable