EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
RefObject Class Reference

A reference-counted object. More...

#include "RefPtr.h"

Inheritance diagram for RefObject:

Public Member Functions

 RefObject (size_t initRefCount)
 Initializes reference count. More...
 
virtual ~RefObject ()
 Destructor; must be virtual. More...
 
size_t GetCount ()
 

Protected Member Functions

void IncRef () const
 Increments reference count of object by one. More...
 
void DecRef () const
 Decrements reference count of object by one. More...
 

Protected Attributes

size_t mRefCount
 Reference count of instance. More...
 
bool mDeleted
 

Friends

template<typename X >
class RefPtr
 

Detailed Description

A reference-counted object.

This class has all stuff needed to cooperate with RefPtr. If you want your class to be reference-counted, derive them from this class.

NOTE: this class does NOT increment count on creation (whereas RefPtr does)

Author
Bloody.Rabbit

Definition at line 48 of file RefPtr.h.

Constructor & Destructor Documentation

RefObject::RefObject ( size_t  initRefCount)
inline

Initializes reference count.

Parameters
[in]initRefCountInitial reference count.

Definition at line 59 of file RefPtr.h.

References mDeleted.

60  : mRefCount( initRefCount )
61  {
62  mDeleted = false;
63  }
bool mDeleted
Definition: RefPtr.h:120
size_t mRefCount
Reference count of instance.
Definition: RefPtr.h:119
virtual RefObject::~RefObject ( )
inlinevirtual

Destructor; must be virtual.

Must be virtual for proper destructor to be invoked upon destruction.

Definition at line 71 of file RefPtr.h.

References mDeleted.

72  {
73  // this isnt completely accurate yet. disable to avoid crashes i cant trace
74  //assert( mRefCount == 0);
75  mDeleted = true;
76  }
bool mDeleted
Definition: RefPtr.h:120

Member Function Documentation

void RefObject::DecRef ( ) const
inlineprotected

Decrements reference count of object by one.

If reference count of object reaches zero, object is deleted.

Definition at line 101 of file RefPtr.h.

References _log, mDeleted, mRefCount, and EvE::traceStack().

102  {
103  if (mDeleted) {
104  _log(REFPTR__ERROR, "DecRef() - mDeleted = true. Count is %u", mRefCount);
105  EvE::traceStack();
106  return;
107  }
108 
109  assert( mDeleted == false );
110  assert( mRefCount > 0 );
111  --mRefCount;
112  //_log(REFPTR__DEC, "DecRef() is %u.", mRefCount);
113 
114  if (mRefCount < 1)
115  delete this;
116  }
#define _log(type, fmt,...)
Definition: logsys.h:124
bool mDeleted
Definition: RefPtr.h:120
size_t mRefCount
Reference count of instance.
Definition: RefPtr.h:119
void traceStack(void)
Definition: misc.cpp:169

Here is the call graph for this function:

size_t RefObject::GetCount ( )
inline

Definition at line 78 of file RefPtr.h.

References mRefCount.

78 { return mRefCount; }
size_t mRefCount
Reference count of instance.
Definition: RefPtr.h:119
void RefObject::IncRef ( ) const
inlineprotected

Increments reference count of object by one.

Definition at line 84 of file RefPtr.h.

References _log, mDeleted, mRefCount, and EvE::traceStack().

85  {
86  if (mDeleted) {
87  _log(REFPTR__ERROR, "IncRef() - mDeleted = true. Count is %u", mRefCount);
89  return;
90  }
91  assert( mDeleted == false );
92  ++mRefCount;
93  //assert( mRefCount > 0 ); // RefPtr objects are created with a ref count of 0, then incremented during RefPtr c'tor
94  //_log(REFPTR__INC, "IncRef() is %u.", mRefCount);
95  }
#define _log(type, fmt,...)
Definition: logsys.h:124
bool mDeleted
Definition: RefPtr.h:120
size_t mRefCount
Reference count of instance.
Definition: RefPtr.h:119
void traceStack(void)
Definition: misc.cpp:169

Here is the call graph for this function:

Friends And Related Function Documentation

template<typename X >
friend class RefPtr
friend

Definition at line 51 of file RefPtr.h.

Member Data Documentation

bool RefObject::mDeleted
mutableprotected

Definition at line 120 of file RefPtr.h.

Referenced by DecRef(), IncRef(), RefObject(), and ~RefObject().

size_t RefObject::mRefCount
mutableprotected

Reference count of instance.

Definition at line 119 of file RefPtr.h.

Referenced by DecRef(), GetCount(), and IncRef().


The documentation for this class was generated from the following file: