Thrive
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
thrive::ComponentFactory Class Reference

A factory for components. More...

#include <component_factory.h>

Classes

struct  Implementation
 

Public Types

using ComponentLoader = std::function< std::unique_ptr< Component >(const StorageContainer &storage) >
 Typedef for a component factory function. More...
 

Public Member Functions

 ComponentFactory ()
 Constructor. More...
 
 ~ComponentFactory ()
 Destructor.
 
ComponentTypeId getTypeId (const std::string &name) const
 Looks up a component type name and returns its id. More...
 
std::string getTypeName (ComponentTypeId typeId) const
 Looks up a component type id and returns its name. More...
 
std::unique_ptr< Component > load (const std::string &typeName, const StorageContainer &storage) const
 Loads a component from storage. More...
 
ComponentTypeId registerComponentType (const std::string &name, ComponentLoader loader)
 Registers a component type with this factory. More...
 
void unregisterComponentType (const std::string &name)
 Unregisters a component type. More...
 

Static Public Member Functions

static luabind::scope luaBindings ()
 Lua bindings. More...
 
template<typename C >
static ComponentTypeId registerGlobalComponentType ()
 Registers a component type for all factories. More...
 

Detailed Description

A factory for components.

Duh.

Member Typedef Documentation

using thrive::ComponentFactory::ComponentLoader = std::function< std::unique_ptr<Component>(const StorageContainer& storage) >

Typedef for a component factory function.

Takes a storage container and returns a std::unique_ptr to the new component.

Constructor & Destructor Documentation

ComponentFactory::ComponentFactory ( )

Constructor.

Usually only used by the Engine.

Member Function Documentation

ComponentTypeId ComponentFactory::getTypeId ( const std::string &  name) const

Looks up a component type name and returns its id.

Parameters
nameThe component type name
Returns
The component type's unique id or NULL_COMPONENT_TYPE if the type name is not registered.
std::string ComponentFactory::getTypeName ( ComponentTypeId  typeId) const

Looks up a component type id and returns its name.

Parameters
typeIdThe component type id
Returns
The component type name or an empty string if the type id is unknown.
std::unique_ptr< Component > ComponentFactory::load ( const std::string &  typeName,
const StorageContainer &  storage 
) const

Loads a component from storage.

Parameters
typeNameThe name of the component type
storageThe component's storage container. May be empty.
Returns
A new component
luabind::scope ComponentFactory::luaBindings ( )
static
ComponentTypeId ComponentFactory::registerComponentType ( const std::string &  name,
ComponentLoader  loader 
)

Registers a component type with this factory.

Parameters
nameThe type name
loaderThe function used for loading this component type
Returns
The type's unique id
template<typename C >
static ComponentTypeId thrive::ComponentFactory::registerGlobalComponentType ( )
inlinestatic

Registers a component type for all factories.

Template Parameters
CThe subclass of Component.
Returns
The type's unique id
Note
You should probably use the REGISTER_COMPONENT macro instead of calling this directly.
void ComponentFactory::unregisterComponentType ( const std::string &  name)

Unregisters a component type.

Parameters
nameThe type's name

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