|
PSCF v1.4.0
|
Reference counter. More...
#include <ReferenceCounter.h>
Public Member Functions | |
| ReferenceCounter () | |
| Constructor. | |
| int | nRef () const |
| Get the number of references to a shareable resource. | |
| bool | hasRefs () const |
| Does this counter have references (is nRef > 0)? | |
Reference counter.
A ReferenceCounter may be associated with zero or more CountedReference objects. A class that owns a shareable resource such as a dynamically allocated array, known as a resource owner, may have a private ReferenceCounter member variable that it uses to keep track of the number of objects that currently have access to the resource. A class that can access a reference counted resource that it does not own, known as a resource user, may have a private CountedReference member variable to keep track of the relationship.
A ReferenceCounter has an integer counter that is equal of the number of associated CountedReference objects. The value of this counter is returned by the nRef() member function. A CountedReference has a pointer member that can hold the address of a single associated Referrence counter. The CountedReference class is a friend of the RefererenceCounter class. This allows a CountedReference to directly increment or decrement the integer counter maintained by an associated ReferenceCounter when the association is created or destroyed.
While nRef() returns a nonzero value, the parent resource owner class should attempt to prevent actions that de-allocate or otherwise invalidate a shared resource, and output a warning of such actions when they cannot be prevented (e.g., during destruction).
Definition at line 42 of file ReferenceCounter.h.
| Util::ReferenceCounter::ReferenceCounter | ( | ) |
Constructor.
Definition at line 15 of file ReferenceCounter.cpp.
|
inline |
Get the number of references to a shareable resource.
Definition at line 72 of file ReferenceCounter.h.
|
inline |
Does this counter have references (is nRef > 0)?
Definition at line 76 of file ReferenceCounter.h.