|
DBC Framework
DBC parsing and CAN signal decoding framework
|
Registry-based factory for creating objects by runtime identifier. More...
#include <typefactory.h>
Inheritance diagram for TypeFactory< ClassId, BaseClass, Args >:Public Types | |
| using | BasePtr = std::shared_ptr< BaseClass > |
| Shared ownership handle returned for created instances. | |
| using | CreatorFn = BasePtr(*)(Args...) |
| Registered creator function signature. | |
Public Member Functions | |
| template<class Derived > | |
| void | registerType (const ClassId &id) |
| Registers a Derived type under the given id. | |
| CreatorFn | creator (const ClassId &id) const |
| Returns creator function for the given id. | |
| BasePtr | create (const ClassId &id, Args... args) const |
| Creates an instance for the given id using provided arguments. | |
| bool | contains (const ClassId &id) const |
| Checks whether an id is registered. | |
Protected Attributes | |
| std::unordered_map< ClassId, CreatorFn > | classes |
| Registered creators; accessible to derived factories. | |
Registry-based factory for creating objects by runtime identifier.
Allows registering derived types and instantiating them using a ClassId key.
Notes:
| ClassId | Unique class identifier type (e.g. std::string, int, enum). |
| BaseClass | Base type for all created objects. |
| Args | Constructor arguments forwarded to registered derived types (by value). |
Usage example:
Definition at line 59 of file typefactory.h.
| using TypeFactory< ClassId, BaseClass, Args >::BasePtr = std::shared_ptr<BaseClass> |
Shared ownership handle returned for created instances.
Definition at line 62 of file typefactory.h.
| using TypeFactory< ClassId, BaseClass, Args >::CreatorFn = BasePtr (*)(Args...) |
Registered creator function signature.
Definition at line 64 of file typefactory.h.
|
inline |
Registers a Derived type under the given id.
Requirements (checked at compile-time):
Re-registering the same id overwrites the previous entry ("last wins").
Definition at line 78 of file typefactory.h.
References TypeFactory< ClassId, BaseClass, Args >::classes.
Referenced by DbcStatementDispatcher::RegisterType().
|
inline |
Returns creator function for the given id.
| std::out_of_range | when id is not registered. |
Definition at line 91 of file typefactory.h.
References TypeFactory< ClassId, BaseClass, Args >::classes.
Referenced by TypeFactory< ClassId, BaseClass, Args >::create().
|
inline |
Creates an instance for the given id using provided arguments.
| std::out_of_range | when id is not registered. |
Definition at line 99 of file typefactory.h.
References TypeFactory< ClassId, BaseClass, Args >::creator().
Referenced by DbcStatementDispatcher::RegisterType().
|
inline |
Checks whether an id is registered.
Definition at line 106 of file typefactory.h.
References TypeFactory< ClassId, BaseClass, Args >::classes.
|
protected |
Registered creators; accessible to derived factories.
Definition at line 112 of file typefactory.h.
Referenced by TypeFactory< ClassId, BaseClass, Args >::contains(), TypeFactory< ClassId, BaseClass, Args >::creator(), and TypeFactory< ClassId, BaseClass, Args >::registerType().