#ifndef STAR_LIVE_COUNTER_HPP #define STAR_LIVE_COUNTER_HPP #include "StarConfig.hpp" #include namespace Star { typedef atomic LiveAtomicCounter; void bindLiveCounter(std::type_index const& typeIndex, LiveAtomicCounter*& counter); void dumpLiveCounters(); // Use as class MyClass : LiveCounter { ... } template class LiveCounter { public: #ifdef STAR_ENABLE_LIVECOUNTER LiveCounter() { bindLiveCounter(typeid(T), s_liveCounter); ++(*s_liveCounter); } LiveCounter(LiveCounter const&) { bindLiveCounter(typeid(T), s_liveCounter); ++(*s_liveCounter); } LiveCounter(LiveCounter&&) { bindLiveCounter(typeid(T), s_liveCounter); ++(*s_liveCounter); } void operator=(LiveCounter const&) {} void operator=(LiveCounter&&) {} ~LiveCounter() { --(*s_liveCounter); } private: static LiveAtomicCounter* s_liveCounter; #endif }; #ifdef STAR_ENABLE_LIVECOUNTER template LiveAtomicCounter* LiveCounter::s_liveCounter = nullptr; #endif } #endif