Gazebo Gazebo

API Reference

6.16.0

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

#include <Factory.hh>

Public Member Functions

 Factory ()=default
 
 Factory (const Factory &)=delete
 
 Factory (Factory &)=delete
 
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< components::BaseComponentNew (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)
 Register a component so that the factory can create instances of the component based on an ID. More...
 
template<typename ComponentTypeT >
void Register (const std::string &_type, ComponentDescriptorBase *_compDesc, RegistrationObjectId _regObjId)
 Register a component so that the factory can create instances of the component based on an ID. 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...
 
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 anymore. More...
 
void Unregister (ComponentTypeId _typeId)
 Unregister a component so that the factory can't create instances of the component anymore. More...
 
void Unregister (ComponentTypeId _typeId, RegistrationObjectId _regObjId)
 Unregister a component so that the factory can't create instances of the component anymore. More...
 
template<typename ComponentTypeT >
void Unregister (RegistrationObjectId _regObjId)
 Unregister a component so that the factory can't create instances of the component anymore. More...
 

Static Public Member Functions

static FactoryInstance ()
 Get an instance of the singleton. More...
 

Public Attributes

std::map< ComponentTypeId, std::stringnamesById
 A list of IDs and their equivalent names. More...
 
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.

Constructor & Destructor Documentation

◆ Factory() [1/3]

Factory ( Factory )
delete

◆ Factory() [2/3]

Factory ( const Factory )
delete

◆ Factory() [3/3]

Factory ( )
default

Member Function Documentation

◆ HasType()

bool HasType ( ComponentTypeId  _typeId)
inline

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

◆ Instance()

static Factory* Instance ( )
static

Get an instance of the singleton.

◆ 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/3]

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/3]

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.

◆ New() [3/3]

std::unique_ptr<components::BaseComponent> New ( const ComponentTypeId _type,
const components::BaseComponent _data 
)
inline

Create a new instance of a component, initialized with particular data.

Parameters
[in]_typeComponent id to create.
[in]_dataThe 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()

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

Create a new instance of a component storage.

Parameters
[in]_typeIdType of component which the storage will hold.
Returns
Always returns nullptr.
Deprecated:
Storages aren't necessary anymore.

◆ Register() [1/3]

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

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

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

◆ Register() [2/3]

void Register ( const std::string _type,
ComponentDescriptorBase _compDesc,
RegistrationObjectId  _regObjId 
)
inline

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

Parameters
[in]_typeType of component to register.
[in]_compDescObject to manage the creation of ComponentTypeT objects.
[in]_regObjIdAn ID that identifies the registration object. This is generally derived from the this pointer of the static component registration object created when calling IGN_GAZEBO_REGISTER_COMPONENT.
Template Parameters
ComponentTypeTType of component to register.

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

◆ Register() [3/3]

void Register ( const std::string _type,
ComponentDescriptorBase _compDesc,
StorageDescriptorBase  
)
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]_storageDescIgnored.
Template Parameters
ComponentTypeTType of component to register.
Deprecated:
See function that doesn't accept a storage

◆ 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/4]

void Unregister ( )
inline

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

Template Parameters
ComponentTypeTType of component to unregister.

Referenced by Factory::Unregister().

◆ Unregister() [2/4]

void Unregister ( ComponentTypeId  _typeId)
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]_typeIdType of component to unregister.

References Factory::Unregister().

◆ Unregister() [3/4]

void Unregister ( ComponentTypeId  _typeId,
RegistrationObjectId  _regObjId 
)
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]_typeIdType of component to unregister.
[in]_regObjIdAn ID that identifies the registration object. This is generally derived from the this pointer of the static component registration object created when calling IGN_GAZEBO_REGISTER_COMPONENT.

◆ Unregister() [4/4]

void Unregister ( RegistrationObjectId  _regObjId)
inline

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

Template Parameters
ComponentTypeTType of component to unregister.
Parameters
[in]_regObjIdAn ID that identifies the registration object. This is generally derived from the this pointer of the static component registration object created when calling IGN_GAZEBO_REGISTER_COMPONENT.

References Factory::Unregister().

Member Data Documentation

◆ namesById

A list of IDs and their equivalent names.

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

◆ 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.

Referenced by Factory::Register().


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