#include <ReferenceCountedObject.h>
A base class which provides methods for reference-counting.
To add reference-counting to a class, derive it from this class, and use the ReferenceCountedObjectPtr class to point to it.
e.g.
{
void foo();
};
MyClass::Ptr
p =
new MyClass();
p2->foo();
ReferenceCountedObject()
Definition ReferenceCountedObject.h:107
Definition ReferenceCountedObject.h:227
uch * p
Definition crypt.c:594
Once a new ReferenceCountedObject has been assigned to a pointer, be careful not to delete the object manually.
This class uses an Atomic<int> value to hold the reference count, so that it the pointers can be passed between threads safely. For a faster but non-thread-safe version, use SingleThreadedReferenceCountedObject instead.
- See also
- ReferenceCountedObjectPtr, ReferenceCountedArray, SingleThreadedReferenceCountedObject
◆ ReferenceCountedObject()
| water::ReferenceCountedObject::ReferenceCountedObject |
( |
| ) |
|
|
inlineprotected |
Creates the reference-counted object (with an initial ref count of zero).
◆ ~ReferenceCountedObject()
| virtual water::ReferenceCountedObject::~ReferenceCountedObject |
( |
| ) |
|
|
inlineprotectedvirtual |
◆ decReferenceCount()
| void water::ReferenceCountedObject::decReferenceCount |
( |
| ) |
|
|
inlinenoexcept |
Decreases the object's reference count. If the count gets to zero, the object will be deleted.
◆ decReferenceCountWithoutDeleting()
| bool water::ReferenceCountedObject::decReferenceCountWithoutDeleting |
( |
| ) |
|
|
inlinenoexcept |
Decreases the object's reference count. If the count gets to zero, the object will not be deleted, but this method will return true, allowing the caller to take care of deletion.
◆ getReferenceCount()
| int water::ReferenceCountedObject::getReferenceCount |
( |
| ) |
const |
|
inlinenoexcept |
Returns the object's current reference count.
◆ incReferenceCount()
| void water::ReferenceCountedObject::incReferenceCount |
( |
| ) |
|
|
inlinenoexcept |
Increments the object's reference count.
This is done automatically by the smart pointer, but is public just in case it's needed for nefarious purposes.
◆ resetReferenceCount()
| void water::ReferenceCountedObject::resetReferenceCount |
( |
| ) |
|
|
inlineprotectednoexcept |
Resets the reference count to zero without deleting the object. You should probably never need to use this!
◆ refCount
| Atomic<int> water::ReferenceCountedObject::refCount |
|
private |
The documentation for this class was generated from the following file: