diff --git a/include/core/common/factory.h b/include/core/common/factory.h index d533ff0da8b627dd0d12ca9a32637956da871af5..1e18985f9a047dea575af0852b24eac6ff6305bd 100644 --- a/include/core/common/factory.h +++ b/include/core/common/factory.h @@ -307,6 +307,8 @@ class Factory static bool unregisterCreator(const std::string& _type); static TypeBasePtr create(const std::string& _type, TypeInput... _input); std::string getClass() const; + static void printAddress(); + static void printCallbacks(); private: CallbackMap callbacks_; @@ -321,9 +323,15 @@ class Factory void operator=(Factory const&) = delete; private: Factory() { } - ~Factory() { } + ~Factory(); }; +template<class TypeBase, typename... TypeInput> +inline Factory<TypeBase, TypeInput...>::~Factory<TypeBase, TypeInput...>() +{ + std::cout << " Factory destructor " << this->getClass() << std::endl; +} + template<class TypeBase, typename... TypeInput> inline bool Factory<TypeBase, TypeInput...>::registerCreator(const std::string& _type, CreatorCallback createFn) { @@ -358,7 +366,7 @@ inline typename Factory<TypeBase, TypeInput...>::TypeBasePtr Factory<TypeBase, T template<class TypeBase, typename... TypeInput> inline Factory<TypeBase, TypeInput...>& Factory<TypeBase, TypeInput...>::get() { - static Factory instance_; + static Factory<TypeBase, TypeInput...> instance_; return instance_; } @@ -368,6 +376,21 @@ inline std::string Factory<TypeBase, TypeInput...>::getClass() const return "Factory<class TypeBase>"; } +template<class TypeBase, typename... TypeInput> +inline void Factory<TypeBase, TypeInput...>::printAddress() +{ + std::cout << get().getClass() << " address: " << &get() << std::endl; +} + +template<class TypeBase, typename... TypeInput> +inline void Factory<TypeBase, TypeInput...>::printCallbacks() +{ + std::cout << get().getClass() << " callbacks size: " << get().callbacks_.size() << std::endl; + for (auto cb: get().callbacks_){ + std::cout << "\t" << cb.first << std::endl; + } +} + } // namespace wolf namespace wolf