Skip to content
Snippets Groups Projects
Commit 768795c7 authored by Joan Vallvé Navarro's avatar Joan Vallvé Navarro
Browse files

added debug methods to factory.h

parent 582d383a
No related branches found
No related tags found
1 merge request!451After cmake and const refactor
Pipeline #10728 failed
...@@ -307,6 +307,8 @@ class Factory ...@@ -307,6 +307,8 @@ class Factory
static bool unregisterCreator(const std::string& _type); static bool unregisterCreator(const std::string& _type);
static TypeBasePtr create(const std::string& _type, TypeInput... _input); static TypeBasePtr create(const std::string& _type, TypeInput... _input);
std::string getClass() const; std::string getClass() const;
static void printAddress();
static void printCallbacks();
private: private:
CallbackMap callbacks_; CallbackMap callbacks_;
...@@ -321,9 +323,15 @@ class Factory ...@@ -321,9 +323,15 @@ class Factory
void operator=(Factory const&) = delete; void operator=(Factory const&) = delete;
private: private:
Factory() { } 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> template<class TypeBase, typename... TypeInput>
inline bool Factory<TypeBase, TypeInput...>::registerCreator(const std::string& _type, CreatorCallback createFn) 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 ...@@ -358,7 +366,7 @@ inline typename Factory<TypeBase, TypeInput...>::TypeBasePtr Factory<TypeBase, T
template<class TypeBase, typename... TypeInput> template<class TypeBase, typename... TypeInput>
inline Factory<TypeBase, TypeInput...>& Factory<TypeBase, TypeInput...>::get() inline Factory<TypeBase, TypeInput...>& Factory<TypeBase, TypeInput...>::get()
{ {
static Factory instance_; static Factory<TypeBase, TypeInput...> instance_;
return instance_; return instance_;
} }
...@@ -368,6 +376,21 @@ inline std::string Factory<TypeBase, TypeInput...>::getClass() const ...@@ -368,6 +376,21 @@ inline std::string Factory<TypeBase, TypeInput...>::getClass() const
return "Factory<class TypeBase>"; 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
namespace wolf namespace wolf
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment