The Nebula Device 3: Ptr< TYPE > Class Template Reference

The Nebula Device 3

Ptr< TYPE > Class Template Reference

#include <ptr.h>


Detailed Description

template<class TYPE>
class Ptr< TYPE >

Nebula3's smart pointer class which manages the life time of RefCounted objects. Can be used like a normal C++ pointer in most cases.

NOTE: the Ptr class is not part of the Core namespace for convenience reasons.

(C) 2006 RadonLabs GmbH


Public Member Functions

 Ptr ()
 constructor
 Ptr (TYPE *p)
 construct from C++ pointer
 Ptr (const Ptr< TYPE > &p)
 construct from smart pointer
 ~Ptr ()
 destructor
void operator= (const Ptr< TYPE > &rhs)
 assignment operator
void operator= (TYPE *rhs)
 assignment operator
bool operator== (const Ptr< TYPE > &rhs) const
 equality operator
bool operator!= (const Ptr< TYPE > &rhs) const
 inequality operator
bool operator== (const TYPE *rhs) const
 shortcut equality operator
bool operator!= (const TYPE *rhs) const
 shortcut inequality operator
TYPE * operator-> () const
 safe -> operator
TYPE & operator * () const
 safe dereference operator
 operator TYPE * () const
 safe pointer cast operator
template<class DERIVED>
const Ptr< DERIVED > & downcast () const
 type-safe downcast operator to other smart pointer
template<class BASE>
const Ptr< BASE > & upcast () const
 type-safe upcast operator to other smart pointer
template<class OTHERTYPE>
const Ptr< OTHERTYPE > & cast () const
bool isvalid () const
 check if pointer is valid
TYPE * get () const
 return direct pointer (asserts if null pointer)
TYPE * get_unsafe () const
 return direct pointer (returns null pointer)

Member Function Documentation

template<class TYPE>
template<class OTHERTYPE>
const Ptr< OTHERTYPE > & Ptr< TYPE >::cast (  )  const

unsafe(!) cast to anything, unless classes have no inheritance-relationship, call upcast/downcast instead, they are type-safe