Caelum
0.6.4
|
Template for smart pointers with strict unique ownership. More...
#include <PrivatePtr.h>
Public Member Functions | |
void | reset (const InnerPointerType &newInner=TraitsT::getNullValue()) |
Change the inner value. More... | |
InnerPointerType | release () |
PrivatePtr () | |
Constructor; always initialize to 0. | |
PrivatePtr (const InnerPointerType &inner) | |
Initializing constructur. | |
~PrivatePtr () | |
Non-virtual destructor (don't derive from this). | |
PrivatePtr (PrivatePtr &rhs) | |
Copy constructor; clears right-hand-side. | |
const PrivatePtr & | operator= (PrivatePtr &rhs) |
Assignment. | |
bool | isNull () const |
Check if this is null. | |
void | setNull () |
Set to null and destroy contents (if any). | |
PointedT * | getPointer () const |
PointedT * | get () const |
PointedT * | operator-> () const |
PointedT & | operator* () const |
Template for smart pointers with strict unique ownership.
A lot of objects in Ogre are created and destroyed through other "Manager" objects. Even though the memory for such objects is never actually leaked better lifetime control is frequently useful.
PrivatePtr is very similar in behaviour to std::auto_ptr but tries to mimic Ogre::SharedPtr method names. Only one PrivatePtr must exist to a certain object at any one time. Assignment and copy construction will in fact pass away ownership and set the original PrivatePtr to null.
This very limited functionality makes PrivatePtr very efficient; it should have no overhead compared to doing the same thing manually.
PrivatePtr supports customization through a static traits class which can customize what happens when the PrivatePtr is destroyed. This makes it possible to use PrivatePtr classes for fine control over the lifetime of objects which are otherwise managed by an external class.
|
inline |
Change the inner value.
This will destroy the old value and gain ownership of the new value.
Referenced by Caelum::PrivatePtr< PointedT, TraitsT >::operator=(), and Caelum::PrivatePtr< PointedT, TraitsT >::PrivatePtr().