Comments refactoring.
This commit is contained in:
@@ -4,7 +4,11 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The TypeFsactory class - base typefactory (abstract factory) template
|
* @brief Registry-based factory for creating objects by runtime identifier.
|
||||||
|
*
|
||||||
|
* Allows registering derived types and instantiating them
|
||||||
|
* using a ClassId key.
|
||||||
|
*
|
||||||
* @param ClassId - unique class identification class. For example string, or integer id.
|
* @param ClassId - unique class identification class. For example string, or integer id.
|
||||||
* @param BaseClass - all objects should have one base class. For example vehicle or parameter
|
* @param BaseClass - all objects should have one base class. For example vehicle or parameter
|
||||||
* @param Args - constructor arguments
|
* @param Args - constructor arguments
|
||||||
@@ -52,9 +56,6 @@
|
|||||||
template<class ClassId, class BaseClass, class ... Args>
|
template<class ClassId, class BaseClass, class ... Args>
|
||||||
class TypeFsactory {
|
class TypeFsactory {
|
||||||
public:
|
public:
|
||||||
/**
|
|
||||||
* @brief BaseClass_SP - base class shared pointer type
|
|
||||||
*/
|
|
||||||
typedef std::shared_ptr<BaseClass> BaseClass_SP;
|
typedef std::shared_ptr<BaseClass> BaseClass_SP;
|
||||||
/**
|
/**
|
||||||
* @brief typefactoryFunction - typefactory function pointer type. Generally speaking it is pointer to constructor.
|
* @brief typefactoryFunction - typefactory function pointer type. Generally speaking it is pointer to constructor.
|
||||||
@@ -76,7 +77,7 @@ class TypeFsactory {
|
|||||||
*/
|
*/
|
||||||
template<class Derived>
|
template<class Derived>
|
||||||
void registerType (const ClassId& id) {
|
void registerType (const ClassId& id) {
|
||||||
/// store pointer to constructor of Derived class
|
/// Register Derived type by storing its constructor wrapper
|
||||||
classes[id] = &typefactory<Derived>;
|
classes[id] = &typefactory<Derived>;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,12 +88,11 @@ class TypeFsactory {
|
|||||||
* @throws std::out_of_range when id not found in map
|
* @throws std::out_of_range when id not found in map
|
||||||
*/
|
*/
|
||||||
typefactoryFunction createInstance (const ClassId& id) const {
|
typefactoryFunction createInstance (const ClassId& id) const {
|
||||||
/// constructor of registered type will call here
|
|
||||||
return classes.at (id);
|
return classes.at (id);
|
||||||
}
|
}
|
||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
* @brief classes - main storage for pointers to constructors of registered types
|
* @brief classes - Not thread-safe. Register types during initialization phase only.
|
||||||
*/
|
*/
|
||||||
std::unordered_map<ClassId, typefactoryFunction> classes;
|
std::unordered_map<ClassId, typefactoryFunction> classes;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user