Back to index

enigmail  1.4.3
Public Member Functions | Private Attributes | Friends
mozilla::RefCounted< T > Class Template Reference

RefCounted<T> is a sort of a "mixin" for a class T. More...

#include <RefPtr.h>

List of all members.

Public Member Functions

 RefCounted ()
 ~RefCounted ()
void AddRef ()
void Release ()
void ref ()
void deref ()
int refCount () const
bool hasOneRef () const

Private Attributes

int refCnt

Friends

class RefPtr< T >

Detailed Description

template<typename T>
class mozilla::RefCounted< T >

RefCounted<T> is a sort of a "mixin" for a class T.

RefCounted manages, well, refcounting for T, and because RefCounted is parameterized on T, RefCounted<T> can call T's destructor directly. This means T doesn't need to have a virtual dtor and so doesn't need a vtable.

RefCounted<T> is created with refcount == 0. Newly-allocated RefCounted<T> must immediately be assigned to a RefPtr to make the refcount > 0. It's an error to allocate and free a bare RefCounted<T>, i.e. outside of the RefPtr machinery. Attempts to do so will abort DEBUG builds.

Live RefCounted<T> have refcount > 0. The lifetime (refcounts) of live RefCounted<T> are controlled by RefPtr<T> and RefPtr<super/subclass of T>. Upon a transition from refcounted==1 to 0, the RefCounted<T> "dies" and is destroyed. The "destroyed" state is represented in DEBUG builds by refcount==-0xdead. This state distinguishes use-before-ref (refcount==0) from use-after-destroy (refcount==-0xdead).

Definition at line 79 of file RefPtr.h.


Constructor & Destructor Documentation

template<typename T >
mozilla::RefCounted< T >::RefCounted ( ) [inline]

Definition at line 84 of file RefPtr.h.

: refCnt(0) { }
template<typename T >
mozilla::RefCounted< T >::~RefCounted ( ) [inline]

Definition at line 85 of file RefPtr.h.

{ MOZ_ASSERT(refCnt == -0xdead); }

Member Function Documentation

template<typename T >
void mozilla::RefCounted< T >::AddRef ( ) [inline]

Definition at line 88 of file RefPtr.h.

                  {
        MOZ_ASSERT(refCnt >= 0);
        ++refCnt;
    }

Here is the caller graph for this function:

template<typename T >
void mozilla::RefCounted< T >::deref ( ) [inline]

Definition at line 105 of file RefPtr.h.

{ Release(); }

Here is the call graph for this function:

template<typename T >
bool mozilla::RefCounted< T >::hasOneRef ( ) const [inline]

Definition at line 107 of file RefPtr.h.

                           {
        MOZ_ASSERT(refCnt > 0);
        return refCnt == 1;
    }
template<typename T >
void mozilla::RefCounted< T >::ref ( ) [inline]

Definition at line 104 of file RefPtr.h.

{ AddRef(); }

Here is the call graph for this function:

template<typename T >
int mozilla::RefCounted< T >::refCount ( ) const [inline]

Definition at line 106 of file RefPtr.h.

{ return refCnt; }
template<typename T >
void mozilla::RefCounted< T >::Release ( ) [inline]

Definition at line 93 of file RefPtr.h.

                   {
        MOZ_ASSERT(refCnt > 0);
        if (0 == --refCnt) {
#ifdef DEBUG
            refCnt = -0xdead;
#endif
            delete static_cast<T*>(this);
        }
    }

Here is the caller graph for this function:


Friends And Related Function Documentation

template<typename T >
friend class RefPtr< T > [friend]

Definition at line 81 of file RefPtr.h.


Member Data Documentation

template<typename T >
int mozilla::RefCounted< T >::refCnt [private]

Definition at line 113 of file RefPtr.h.


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