Loading...
Searching...
No Matches
TfRefCount Class Reference

Reference counter class. More...

#include <refCount.h>

Public Member Functions

 TfRefCount ()
 Initialize counter to one.
 
 TfRefCount (const TfRefCount &)
 Initialize counter to one.
 
int Get () const
 Returns counter's value.
 
const TfRefCountoperator= (const TfRefCount &) const
 Assignment to a reference counter has no effect.
 

Friends

template<typename T >
class TfRefPtr
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ TfRefCount() [1/2]

TfRefCount ( )
inline

Initialize counter to one.

Definition at line 74 of file refCount.h.

◆ TfRefCount() [2/2]

TfRefCount ( const TfRefCount )
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.

Member Function Documentation

◆ Get()

int Get ( ) const
inline

Returns counter's value.

Definition at line 85 of file refCount.h.

◆ operator=()

const TfRefCount & operator= ( const TfRefCount ) const
inline

Assignment to a reference counter has no effect.

Definition at line 90 of file refCount.h.

Friends And Related Function Documentation

◆ TfRefPtr

friend class TfRefPtr
friend

Definition at line 106 of file refCount.h.


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