![]() |
|
Reference counter class. More...
Public Member Functions | |
TfRefCount () | |
Initialize counter to one. More... | |
TfRefCount (const TfRefCount &) | |
Initialize counter to one. More... | |
int | Get () const |
Returns counter's value. More... | |
const TfRefCount & | operator= (const TfRefCount &) const |
Assignment to a reference counter has no effect. More... | |
Friends | |
template<typename T > | |
class | TfRefPtr |
Reference counter class.
This class is intended to be embedded in other classes, for use as a reference counter. Unless you need to provide extraordinary customization, you should forgo direct use of this class and instead make use of the base class TfRefBase
.
Initialization of a reference counter is somewhat counterintuitive. Consider an object T with a reference counter R. When T is initialized, R should be initialized to one, even if T is copy-constructed. This implies that all constructors of TfRefCount
set the counter to one, even the copy constructor.
Conversely, if T is assigned to, the reference counter R in T should not change. This implies that the assignment operator for TfRefCount
does not change the counter's value.
Finally, for thread-safety, the counter should be atomic.
This class was written primarily for use in classes whose access is encapsulated by means of the TfRefPtr
interface; such classes require reference counting semantics as described above. Note that the behavior of a TfRefCount
in a class T is invariant with respect to T's copy constructors and assignment operators.
Again, please do not directly embed a TfRefCount
in a structure unless the functionality of TfRefBase
is insufficient for your needs.
Definition at line 71 of file refCount.h.
|
inline |
Initialize counter to one.
Definition at line 74 of file refCount.h.
|
inline |
Initialize counter to one.
Even if you copy from a reference counter, you want the newly constructed counter to start at one.
Definition at line 81 of file refCount.h.
|
inline |
Returns counter's value.
Definition at line 85 of file refCount.h.
|
inline |
Assignment to a reference counter has no effect.
Definition at line 90 of file refCount.h.