mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-10 14:51:40 +00:00
- added RefCountedBase without virtual destructor
This commit is contained in:
parent
bbcd522052
commit
76ecf44549
1 changed files with 17 additions and 8 deletions
|
@ -1,20 +1,29 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
// Simple lightweight reference counting pointer alternative for std::shared_ptr which stores the reference counter in the handled object itself.
|
// 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
|
class RefCountedBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void IncRef() { refCount++; }
|
void IncRef() { refCount++; }
|
||||||
void DecRef() { if (--refCount <= 0) delete this; }
|
void DecRef() { if (--refCount <= 0) delete this; }
|
||||||
private:
|
private:
|
||||||
int refCount = 0;
|
int refCount = 0;
|
||||||
protected:
|
protected:
|
||||||
virtual ~RefCountedBase() = default;
|
virtual ~RefCountedBase() = default;
|
||||||
};
|
};
|
||||||
|
|
||||||
// The actual pointer object
|
// The actual pointer object
|
||||||
template<class T>
|
template<class T>
|
||||||
class RefCountedPtr
|
class RefCountedPtr
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue