Gazebo Gazebo

API Reference

3.15.2

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::BaseComponentNew (const ComponentTypeId &_type)
 Create a new instance of a component. More...
 
std::unique_ptr< ComponentStorageBase > NewStorage (const ComponentTypeId &_typeId)
 Create a new instance of a component storage. More...
 
template<typename ComponentTypeT >
void Register (const std::string &_type, ComponentDescriptorBase *_compDesc, StorageDescriptorBase *_storageDesc)
 Register a component so that the factory can create instances of the component and its storage based on an ID. More...
 
std::vector< ComponentTypeIdTypeIds () 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 or its storage anymore. More...
 
void Unregister (ComponentTypeId _typeId)
 Unregister a component so that the factory can't create instances of the component or its storage anymore. More...
 

Static Public Attributes

static std::map< ComponentTypeId, std::stringnamesById
 A list of IDs and their equivalent names. More...
 
static std::map< ComponentTypeId, std::stringruntimeNamesById
 Keep track of the runtime names for types and warn the user if they try to register different types with the same typeName. More...
 

Detailed Description

A factory that generates a component based on a string type.

Member Function Documentation

◆ HasType()

bool HasType ( ComponentTypeId  _typeId)
inline

Check if a component type has been registered. return True if registered.

◆ Name()

std::string Name ( ComponentTypeId  _typeId) const
inline

Get a component's type name given its type ID. return Unique component name.

References map< K, T >::at(), string::end(), map< K, T >::find(), and Factory::namesById.

◆ New() [1/2]

std::unique_ptr<ComponentTypeT> New ( )
inline

Create a new instance of a component.

Returns
Pointer to a component. Null if the component type could not be handled.
Template Parameters
ComponentTypeTcomponent type requested

◆ New() [2/2]

Create a new instance of a component.

Parameters
[in]_typeComponent id to create.
Returns
Pointer to a component. Null if the component type could not be handled.

◆ NewStorage()

std::unique_ptr<ComponentStorageBase> NewStorage ( const ComponentTypeId _typeId)
inline

Create a new instance of a component storage.

Parameters
[in]_typeIdType of component which the storage will hold.
Returns
Pointer to a storage. Null if the component type could not be handled.

◆ Register()

void Register ( const std::string _type,
ComponentDescriptorBase _compDesc,
StorageDescriptorBase _storageDesc 
)
inline

Register a component so that the factory can create instances of the component and its storage based on an ID.

Parameters
[in]_typeType of component to register.
[in]_compDescObject to manage the creation of ComponentTypeT objects.
[in]_storageDescObject to manage the creation of storages for objects of type ComponentTypeT.
Template Parameters
ComponentTypeTType of component to register.

References map< K, T >::end(), std::endl(), map< K, T >::find(), Factory::namesById, and Factory::runtimeNamesById.

◆ TypeIds()

std::vector<ComponentTypeId> TypeIds ( ) const
inline

Get all the registered component types by ID. return Vector of component IDs.

References vector< T >::push_back().

◆ Unregister() [1/2]

void Unregister ( )
inline

Unregister a component so that the factory can't create instances of the component or its storage anymore.

Template Parameters
ComponentTypeTType of component to unregister.

◆ Unregister() [2/2]

void Unregister ( ComponentTypeId  _typeId)
inline

Unregister a component so that the factory can't create instances of the component or its storage 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]_typeIdType of component to unregister.

References map< K, T >::end(), map< K, T >::erase(), map< K, T >::find(), Factory::namesById, and Factory::runtimeNamesById.

Member Data Documentation

◆ namesById

std::map<ComponentTypeId, std::string> namesById
inlinestatic

A list of IDs and their equivalent names.

Make it non-static on version 2.0.

Referenced by Factory::Name(), Factory::Register(), and Factory::Unregister().

◆ runtimeNamesById

std::map<ComponentTypeId, std::string> runtimeNamesById
inlinestatic

Keep track of the runtime names for types and warn the user if they try to register different types with the same typeName.

Make it non-static on version 2.0.

Referenced by Factory::Register(), and Factory::Unregister().


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