diff --git a/typefactory/typefactory.h b/typefactory/typefactory.h index 67568ff..b7a0cd6 100644 --- a/typefactory/typefactory.h +++ b/typefactory/typefactory.h @@ -47,8 +47,8 @@ * typefactory.registerType("one"); * typefactory.registerType("2"); * - * auto d1 = typefactory.create ("one")(10); - * auto d2 = typefactory.create ("2")(10); + * auto d1 = typefactory.creator ("one")(10); + * auto d2 = typefactory.creator ("2")(10); * * d1->get(); * d2->get(); @@ -79,24 +79,25 @@ class TypeFactory { template void registerType (const ClassId& id) { /// Register Derived type by storing its constructor wrapper - - static_assert(std::is_base_of_v, - "Derived must inherit from BaseClass"); - static_assert(std::is_constructible_v, - "Derived must be constructible from Args..."); + "Derived must inherit from BaseClass"); + static_assert(std::is_constructible_v, + "Derived must be constructible from Args..."); classes[id] = &typefactory; } /** - * @brief create - Returns creator function for id. + * @brief creator - Returns creator function for id. * @param id - unique class identification - * @return shared pointer to new class. + * @returns creator function. * @throws std::out_of_range when id not found in map */ - typefactoryFunction create (const ClassId& id) const { + typefactoryFunction creator (const ClassId& id) const { return classes.at (id); } + BaseClass_SP create(const ClassId& id, Args... args) const { + return creator(id)(args...); + } protected: /** * @brief classes - Not thread-safe. Register types during initialization phase only. @@ -105,7 +106,7 @@ class TypeFactory { private: /** - * @brief typefactory - main functionality, create registered object + * @brief typefactory - main functionality, creator registered object * @param Derived - class type * @param args - constructor arguments * @return shared pointer to register Derived class