#pragma once // AbstractRefCount.h - base for reference counting #include "IComponentFactory.h" #include "Logger.h" class AbstractRefCount { public: void addRef() { ++refCount_; if (pLog) pLog->log("\n AddRef: refCount = " + Converter::toString(refCount_)); } void release() { --refCount_; if (pLog) pLog->log("\n Release: refCount = " + Converter::toString(refCount_)); if (refCount_ == 0) { delete this; } } AbstractRefCount() { addRef(); } AbstractRefCount(const AbstractRefCount& rc) = delete; AbstractRefCount& operator=(const AbstractRefCount& rc) = delete; static void doLog(bool log = true) { if (log) pLog = new Logger(); else pLog = new Logger(); } virtual ~AbstractRefCount() { // don't delete pLog, it's static } protected: static ILogger* pLog; private: size_t refCount_ = 0; };