From 76ecf445495a9187c345c91543547f07b0fbe6f2 Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Tue, 3 Aug 2021 09:53:21 +0300 Subject: [PATCH] - added RefCountedBase without virtual destructor --- src/common/utility/refcounted.h | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/common/utility/refcounted.h b/src/common/utility/refcounted.h index cff1770294..fd3e82aad1 100644 --- a/src/common/utility/refcounted.h +++ b/src/common/utility/refcounted.h @@ -1,20 +1,29 @@ #pragma once // Simple lightweight reference counting pointer alternative for std::shared_ptr which stores the reference counter in the handled object itself. - - // Base class for handled objects + +// Base classes for handled objects +class NoVirtualRefCountedBase +{ +public: + void IncRef() { refCount++; } + void DecRef() { if (--refCount <= 0) delete this; } +private: + int refCount = 0; +}; + class RefCountedBase { public: - void IncRef() { refCount++; } - void DecRef() { if (--refCount <= 0) delete this; } + void IncRef() { refCount++; } + void DecRef() { if (--refCount <= 0) delete this; } private: - int refCount = 0; + int refCount = 0; protected: - virtual ~RefCountedBase() = default; + virtual ~RefCountedBase() = default; }; - - // The actual pointer object + +// The actual pointer object template class RefCountedPtr {