Spinning Topp Logo BlackTopp Studios
inc
Public Types | Public Member Functions | List of all members
Mezzanine::ManagedPtr< Handle > Class Template Reference

This is used to get RAII semantics when not provided inherently. More...

#include <managedptr.h>

Public Types

typedef Handle::TargetPtrType TargetPtrType
 Used to set the return type of pointer like returns (could be a smartpointer)
 
typedef Handle::TargetType TargetType
 Used to set the value and reference type for returns.
 

Public Member Functions

 ManagedPtr (Handle StatefulHandle=Handle())
 Constructs the target after passing it the desired state information. More...
 
 ManagedPtr (ManagedPtr &Other)
 Creates the Target from an already constructed one but invalidates Other ManagedPtr. More...
 
 ~ManagedPtr ()
 Destroy the target and invalidate it.
 
TargetPtrType Get ()
 Get the raw pointer to the managed object. More...
 
TargetPtrType get ()
 Get the raw pointer to the managed object. More...
 
 operator Boole ()
 Returns true if this pointer points to something. More...
 
TargetTypeoperator* ()
 Dereference operator. More...
 
TargetPtrType operator-> ()
 The Structure dereference operator. More...
 
ManagedPtroperator= (ManagedPtr &Other)
 Assigns the Target but invalidates Other ManagedPtr. More...
 
Boole operator== (ManagedPtr &Other)
 Compares the underlying pointer of this and another ManagedPtr, (This had better return false) More...
 

Detailed Description

template<class Handle>
class Mezzanine::ManagedPtr< Handle >

This is used to get RAII semantics when not provided inherently.

Some APIs have functions that return raw pointers and expect the call to clean up the mess. Even worse sometimes doing this involves more than This is exactly the size of the handle class used. It could be as small as raw pointer if constructed carefully.

To use this a 'Handle' must be created first. A good handle is trivial copyable, assignable and implements a few functions. This is similar to the Pimpl idiom in that the details of the implemention could be abstracted into this 'Handle'. The 'Handle' will encapsulate/have the knowledge of how to correctly create and destroy the pointer while the ManagedPtr provides The pointer-like semantics and esures it is destructed exactly once. This is expected to have members:

The semantics of this class also presume that copying and assigning a Handle is safe. To do that uses these functions as well. It is intended that pointer copies be shallow copies.

Definition at line 115 of file managedptr.h.

Constructor & Destructor Documentation

template<class Handle >
Mezzanine::ManagedPtr< Handle >::ManagedPtr ( Handle  StatefulHandle = Handle())
inline

Constructs the target after passing it the desired state information.

Parameters
StatefulHandleA way to pass parameters into the constructors of the underlying class being targeted.

The Handle class can be implemented any way that is appropriate for the underlying data. So it is not limited to the members defined here. This constructor will call the copy copystructor of the handle before Calling Construct() on it.

Definition at line 153 of file managedptr.h.

template<class Handle >
Mezzanine::ManagedPtr< Handle >::ManagedPtr ( ManagedPtr< Handle > &  Other)
inline

Creates the Target from an already constructed one but invalidates Other ManagedPtr.

This transfer ownership (who will deconstruct the handle) from the Other ManagedPtr to this one. This Does not call Construct().

Parameters
OtherThe ManagedPtr to copy then invalidate.

Definition at line 163 of file managedptr.h.

Member Function Documentation

template<class Handle >
TargetPtrType Mezzanine::ManagedPtr< Handle >::Get ( )
inline

Get the raw pointer to the managed object.

Returns
The raw pointer to the managed object or 0 if this pointer is invalid.
Note
This name was chosen to match standard compliant names, and should be usable in templates that require this function.

Definition at line 206 of file managedptr.h.

template<class Handle >
TargetPtrType Mezzanine::ManagedPtr< Handle >::get ( )
inline

Get the raw pointer to the managed object.

Returns
The raw pointer to the managed object or 0 if this pointer is invalid.
Note
This name was chosen to match standard compliant names, and should be usable in templates that require this function.
Provided to match method names on standard smart pointers

Definition at line 211 of file managedptr.h.

template<class Handle >
Mezzanine::ManagedPtr< Handle >::operator Boole ( )
inline

Returns true if this pointer points to something.

Warning
Without C++11 this can be accidentally easily be cast to a bool and can do silly things, like bogus pointer multiplication.

Definition at line 216 of file managedptr.h.

template<class Handle >
TargetType& Mezzanine::ManagedPtr< Handle >::operator* ( )
inline

Dereference operator.

Returns
The managed object is returned by reference.
Exceptions
Ifthe pointerNothing This member function does not throw exceptions unless the underlying handle does.

Definition at line 183 of file managedptr.h.

template<class Handle >
TargetPtrType Mezzanine::ManagedPtr< Handle >::operator-> ( )
inline

The Structure dereference operator.

Returns
Makes it appear, syntactically, as though you are dereferencing the raw pointer.

Definition at line 194 of file managedptr.h.

template<class Handle >
ManagedPtr& Mezzanine::ManagedPtr< Handle >::operator= ( ManagedPtr< Handle > &  Other)
inline

Assigns the Target but invalidates Other ManagedPtr.

This transfer ownership (who will deconstruct the handle) from the Other ManagedPtr to this one. This Does not call Construct().

Parameters
OtherThe ManagedPtr to copy then invalidate.
Returns
A reference to this ManagedPtr to allow operator chaining.

Definition at line 174 of file managedptr.h.

template<class Handle >
Boole Mezzanine::ManagedPtr< Handle >::operator== ( ManagedPtr< Handle > &  Other)
inline

Compares the underlying pointer of this and another ManagedPtr, (This had better return false)

Parameters
OtherThe right hand portion of the comparison
Returns
Bool Hopefully thi is false, becase

Definition at line 222 of file managedptr.h.


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