A factory that generates a component based on a string type. More...
#include <Factory.hh>
Public Member Functions | |
bool | HasType (ComponentTypeId _typeId) |
Check if a component type has been registered. return True if registered. More... | |
std::string | Name (ComponentTypeId _typeId) const |
Get a component's type name given its type ID. return Unique component name. More... | |
template<typename ComponentTypeT > | |
std::unique_ptr< ComponentTypeT > | New () |
Create a new instance of a component. More... | |
std::unique_ptr< components::BaseComponent > | New (const ComponentTypeId &_type) |
Create a new instance of a component. More... | |
std::unique_ptr< components::BaseComponent > | New (const ComponentTypeId &_type, const components::BaseComponent *_data) |
Create a new instance of a component, initialized with particular data. More... | |
std::unique_ptr< ComponentStorageBase > | NewStorage (const ComponentTypeId &) |
Create a new instance of a component storage. More... | |
template<typename ComponentTypeT > | |
void | Register (const std::string &_type, ComponentDescriptorBase *_compDesc, StorageDescriptorBase *) |
Register a component so that the factory can create instances of the component and its storage based on an ID. More... | |
template<typename ComponentTypeT > | |
void | Register (const std::string &_type, ComponentDescriptorBase *_compDesc) |
Register a component so that the factory can create instances of the component based on an ID. More... | |
std::vector< ComponentTypeId > | TypeIds () const |
Get all the registered component types by ID. return Vector of component IDs. More... | |
template<typename ComponentTypeT > | |
void | Unregister () |
Unregister a component so that the factory can't create instances of the component anymore. More... | |
void | Unregister (ComponentTypeId _typeId) |
Unregister a component so that the factory can't create instances of the component anymore. More... | |
Public Attributes | |
std::map< ComponentTypeId, std::string > | namesById |
A list of IDs and their equivalent names. More... | |
std::map< ComponentTypeId, std::string > | runtimeNamesById |
Keep track of the runtime names for types and warn the user if they try to register different types with the same typeName. More... | |
Additional Inherited Members | |
Static Public Member Functions inherited from SingletonT< Factory > | |
static Factory * | Instance () |
Protected Member Functions inherited from SingletonT< Factory > | |
SingletonT () | |
virtual | ~SingletonT () |
Detailed Description
A factory that generates a component based on a string type.
Member Function Documentation
◆ HasType()
|
inline |
Check if a component type has been registered. return True if registered.
◆ Name()
|
inline |
Get a component's type name given its type ID. return Unique component name.
References string::at().
◆ New() [1/3]
|
inline |
Create a new instance of a component.
- Returns
- Pointer to a component. Null if the component type could not be handled.
- Template Parameters
-
ComponentTypeT component type requested
◆ New() [2/3]
|
inline |
Create a new instance of a component.
- Parameters
-
[in] _type Component id to create.
- Returns
- Pointer to a component. Null if the component type could not be handled.
◆ New() [3/3]
|
inline |
Create a new instance of a component, initialized with particular data.
- Parameters
-
[in] _type Component id to create. [in] _data The data to populate the component instance with.
- Returns
- Pointer to a component. Null if the component type could not be handled.
References std::endl(), ignerr, and BaseComponent::TypeId().
◆ NewStorage()
|
inline |
Create a new instance of a component storage.
- Parameters
-
[in] _typeId Type of component which the storage will hold.
- Returns
- Always returns nullptr.
- Deprecated:
- Storages aren't necessary anymore.
◆ Register() [1/2]
|
inline |
Register a component so that the factory can create instances of the component and its storage based on an ID.
- Parameters
-
[in] _type Type of component to register. [in] _compDesc Object to manage the creation of ComponentTypeT objects. [in] _storageDesc Ignored.
- Template Parameters
-
ComponentTypeT Type of component to register.
- Deprecated:
- See function that doesn't accept a storage
◆ Register() [2/2]
|
inline |
Register a component so that the factory can create instances of the component based on an ID.
- Parameters
-
[in] _type Type of component to register. [in] _compDesc Object to manage the creation of ComponentTypeT objects.
- Template Parameters
-
ComponentTypeT Type of component to register.
References std::endl(), ignition::common::env(), string::find(), and ignition::common::hash64().
◆ TypeIds()
|
inline |
Get all the registered component types by ID. return Vector of component IDs.
References vector< T >::push_back().
◆ Unregister() [1/2]
|
inline |
Unregister a component so that the factory can't create instances of the component anymore.
- Template Parameters
-
ComponentTypeT Type of component to unregister.
◆ Unregister() [2/2]
|
inline |
Unregister a component so that the factory can't create instances of the component anymore.
This function will not reset the typeId
static variable within the component type itself. Prefer using the templated Unregister
function when possible.
- Parameters
-
[in] _typeId Type of component to unregister.
Member Data Documentation
◆ namesById
std::map<ComponentTypeId, std::string> namesById |
A list of IDs and their equivalent names.
◆ runtimeNamesById
std::map<ComponentTypeId, std::string> runtimeNamesById |
Keep track of the runtime names for types and warn the user if they try to register different types with the same typeName.
The documentation for this class was generated from the following file: