HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TfRefCount Class Reference

#include <refCount.h>

Public Member Functions

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

Friends

template<typename T >
class TfRefPtr
 
struct Tf_RefPtr_UniqueChangedCounter
 
struct Tf_RefPtr_Counter
 

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::TfRefCount ( )
inline

Initialize counter to one.

Definition at line 74 of file refCount.h.

TfRefCount::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

int TfRefCount::Get ( ) const
inline

Returns counter's value.

Definition at line 85 of file refCount.h.

const TfRefCount& 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

friend struct Tf_RefPtr_Counter
friend

Definition at line 108 of file refCount.h.

friend struct Tf_RefPtr_UniqueChangedCounter
friend

Definition at line 107 of file refCount.h.

template<typename T >
friend class TfRefPtr
friend

Definition at line 106 of file refCount.h.


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