Caelum  0.6.3
Public Member Functions | List of all members
Caelum::PrivatePtr< PointedT, TraitsT > Class Template Reference

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 PrivatePtroperator= (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
 

Detailed Description

template<class PointedT, typename TraitsT = DefaultPrivatePtrTraits<PointedT>>
class Caelum::PrivatePtr< PointedT, TraitsT >

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.

See also
DefaultPrivatePtrTraits

Member Function Documentation

template<class PointedT, typename TraitsT = DefaultPrivatePtrTraits<PointedT>>
void Caelum::PrivatePtr< PointedT, TraitsT >::reset ( const InnerPointerType &  newInner = TraitsT::getNullValue())
inline

Change the inner value.

This will destroy the old value and gain ownership of the new value.


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