1 // Licensed GNU LGPL v3 or later: http://www.gnu.org/licenses/lgpl.html 2 3 #ifndef SPECTMORPH_LEAK_DEBUGGER_HH 4 #define SPECTMORPH_LEAK_DEBUGGER_HH 5 6 #include <map> 7 #include <string> 8 #include <mutex> 9 #include <functional> 10 11 namespace SpectMorph 12 { 13 14 class LeakDebugger 15 { 16 std::mutex mutex; 17 std::map<void *, int> ptr_map; 18 std::string type; 19 std::function<void()> cleanup_function; 20 21 void ptr_add (void *p); 22 void ptr_del (void *p); 23 24 public: 25 LeakDebugger (const std::string& name, std::function<void()> cleanup_function = nullptr); 26 ~LeakDebugger(); 27 28 template<class T> void add (T *instance) { ptr_add (static_cast<void *> (instance)); } 29 template<class T> void del (T *instance) { ptr_del (static_cast<void *> (instance)); } 30 }; 31 32 } 33 34 #endif 35