#include <intrusive_ptr.h>
Public Types | |
typedef T | element_type |
typedef T *(this_type::* | bool_) () const |
Public Member Functions | |
intrusive_ptr () | |
intrusive_ptr (T *p, bool bAddRef=true) | |
intrusive_ptr (const intrusive_ptr &ip) | |
intrusive_ptr (intrusive_ptr &&ip) | |
template<typename U > | |
intrusive_ptr (const intrusive_ptr< U > &ip) | |
~intrusive_ptr () | |
intrusive_ptr & | operator= (const intrusive_ptr &ip) |
intrusive_ptr & | operator= (intrusive_ptr &&ip) |
template<typename U > | |
intrusive_ptr & | operator= (const intrusive_ptr< U > &ip) |
intrusive_ptr & | operator= (T *pObject) |
T & | operator* () const |
T * | operator-> () const |
T * | get () const |
void | reset () |
void | swap (this_type &ip) |
void | attach (T *pObject) |
T * | detach () |
operator bool_ () const | |
bool | operator! () const |
Protected Types | |
typedef intrusive_ptr< T > | this_type |
Protected Attributes | |
T * | mpObject |
This is a class that acts like the C++ auto_ptr class except that instead of deleting its member data when it goes out of scope, it releases its member data when it goes out of scope. This class thus requires that the templated data type have an AddRef and Release function (or whatever is configured to be the two refcount functions).
This class is useful for automatically releasing an object when this class goes out of scope. See below for some usage. You should be careful about putting instances of this class as members of another class. If you do so, then the intrusive_ptr destructor will only be called if the object that owns it is destructed. This creates a potential chicken-and-egg situation. What if the intrusive_ptr member contains a pointer to an object that has a reference on the object that owns the intrusive_ptr member? The answer is that the neither object can ever be destructed. The solution is to: 1) Be very careful about what objects you put into member intrusive_ptr objects. 2) Clear out your intrusive_ptr members in your shutdown function. 3) Simply don't use intrusive_ptr objects as class members.
Example usage: intrusive_ptr<IWidget> pWidget = new Widget; pWidget = new Widget; pWidget->Reset();
typedef T*(this_type::* eastl::intrusive_ptr< T >::bool_) () const |
Implicit operator bool Allows for using a intrusive_ptr as a boolean. Example usage: intrusive_ptr<Widget> ptr = new Widget; if(ptr) ++*ptr;
Note that below we do not use operator bool(). The reason for this is that booleans automatically convert up to short, int, float, etc. The result is that this: if(intrusivePtr == 1) would yield true (bad).
typedef T eastl::intrusive_ptr< T >::element_type |
element_type This typedef is present for consistency with the C++ standard library auto_ptr template. It allows users to refer to the templated type via a typedef. This is sometimes useful to be able to do.
Example usage: intrusive_ptr<IWidget> ip; void DoSomething(intrusive_ptr<IWidget>::element_type someType);
|
inline |
intrusive_ptr Default constructor. The member object is set to NULL.
|
inline |
intrusive_ptr Provides a constructor which takes ownership of a pointer. The incoming pointer is AddRefd.
Example usage: intrusive_ptr<Widget> pWidget(new Widget);
|
inline |
intrusive_ptr Construction from self type.
|
inline |
intrusive_ptr move constructor
|
inline |
intrusive_ptr Provides a constructor which copies a pointer from another intrusive_ptr. The incoming pointer is AddRefd. The source intrusive_ptr object maintains its AddRef on the pointer.
Example usage: intrusive_ptr<Widget> pWidget1; intrusive_ptr<Widget> pWidget2(pWidget1);
|
inline |
intrusive_ptr Releases the owned pointer.
|
inline |
attach Sets an intrusive_ptr pointer without calling AddRef() on the pointed object. The intrusive_ptr thus eventually only does a Release() on the object. This is useful for assuming a reference that someone else has handed you and making sure it is always released, even if you return in the middle of a function or an exception is thrown.
|
inline |
detach Surrenders the reference held by an intrusive_ptr pointer – it returns the current reference and nulls the pointer. If the returned pointer is non-null it must be released. This is useful in functions that must return a reference while possibly being aborted by a return or thrown exception:
bool GetFoo(T** pp){ intrusive_ptr<T> p(PrivateGetFoo()); if(p->Method()) return false; *pp = p.detach(); return true; }
|
inline |
get() Returns a pointer to the contained object.
|
inline |
operator! This returns the opposite of operator bool; it returns true if the owned pointer is null. Some compilers require this and some don't. intrusive_ptr<Widget> ptr = new Widget; if(!ptr) assert(false);
|
inline |
operator * Returns a reference to the contained object.
|
inline |
operator * Returns a pointer to the contained object, allowing the user to use this container as if it were contained pointer itself.
|
inline |
operator= Assignment to self type.
|
inline |
operator = Assigns an intrusive_ptr object to this intrusive_ptr object. The incoming pointer is AddRefd. The source intrusive_ptr object maintains its AddRef on the pointer. If there is an existing member pointer, it is Released before the incoming pointer is assigned. If the incoming pointer is equal to the existing pointer, no
action is taken. The incoming pointer is AddRefd before any member pointer is Released.
|
inline |
operator= Move assignment operator
|
inline |
operator= Assigns an intrusive_ptr object to this intrusive_ptr object. The incoming pointer is AddRefd. If there is an existing member pointer, it is Released before the incoming pointer is assigned. If the incoming pointer is equal to the existing pointer, no
action is taken. The incoming pointer is AddRefd before any member pointer is Released.
|
inline |
reset Releases the owned object and clears our reference to it.
|
inline |
swap Exchanges the owned pointer beween two intrusive_ptr objects.