|
bool | Register (const IdentifierType &id, ProductCreator creator) |
| Registers the class given by the creator function, linking it to id. Registration must happen prior to calling CreateObject. More...
|
|
bool | Contains (const IdentifierType &id) |
|
bool | Unregister (const IdentifierType &id) |
| Unregisters the class with the given identifier. More...
|
|
void | Clear () |
|
bool | Empty () const |
|
template<typename... Args> |
std::unique_ptr< AbstractProduct > | CreateObjectOrNull (const IdentifierType &id, Args &&... args) |
| Creates and transfers membership of an object of type matching id. Need to register id before CreateObject is called. May return nullptr silently. More...
|
|
template<typename... Args> |
std::unique_ptr< AbstractProduct > | CreateObject (const IdentifierType &id, Args &&... args) |
| Creates and transfers membership of an object of type matching id. Need to register id before CreateObject is called. More...
|
|
template<typename IdentifierType, class AbstractProduct, class ProductCreator = AbstractProduct *(*)(), class MapContainer = std::map<IdentifierType, ProductCreator>>
class apollo::common::util::Factory< IdentifierType, AbstractProduct, ProductCreator, MapContainer >
Implements a Factory design pattern with Register and Create methods.
The objects created by this factory all implement the same interface (namely, AbstractProduct). This design pattern is useful in settings where multiple implementations of an interface are available, and one wishes to defer the choice of the implementation in use.
- Parameters
-
IdentifierType | Type used for identifying the registered classes, typically std::string. |
AbstractProduct | The interface implemented by the registered classes |
ProductCreator | Function returning a pointer to an instance of the registered class |
MapContainer | Internal implementation of the function mapping IdentifierType to ProductCreator, by default std::unordered_map |
template<typename IdentifierType, class AbstractProduct, class ProductCreator = AbstractProduct *(*)(), class MapContainer = std::map<IdentifierType, ProductCreator>>
template<typename... Args>
std::unique_ptr<AbstractProduct> apollo::common::util::Factory< IdentifierType, AbstractProduct, ProductCreator, MapContainer >::CreateObject |
( |
const IdentifierType & |
id, |
|
|
Args &&... |
args |
|
) |
| |
|
inline |
Creates and transfers membership of an object of type matching id. Need to register id before CreateObject is called.
- Parameters
-
id | The identifier of the class we which to instantiate |
args | the object construction arguments |
template<typename IdentifierType, class AbstractProduct, class ProductCreator = AbstractProduct *(*)(), class MapContainer = std::map<IdentifierType, ProductCreator>>
template<typename... Args>
std::unique_ptr<AbstractProduct> apollo::common::util::Factory< IdentifierType, AbstractProduct, ProductCreator, MapContainer >::CreateObjectOrNull |
( |
const IdentifierType & |
id, |
|
|
Args &&... |
args |
|
) |
| |
|
inline |
Creates and transfers membership of an object of type matching id. Need to register id before CreateObject is called. May return nullptr silently.
- Parameters
-
id | The identifier of the class we which to instantiate |
args | the object construction arguments |
template<typename IdentifierType, class AbstractProduct, class ProductCreator = AbstractProduct *(*)(), class MapContainer = std::map<IdentifierType, ProductCreator>>
bool apollo::common::util::Factory< IdentifierType, AbstractProduct, ProductCreator, MapContainer >::Register |
( |
const IdentifierType & |
id, |
|
|
ProductCreator |
creator |
|
) |
| |
|
inline |
Registers the class given by the creator function, linking it to id. Registration must happen prior to calling CreateObject.
- Parameters
-
id | Identifier of the class being registered |
creator | Function returning a pointer to an instance of the registered class |
- Returns
- True if the key id is still available