ns3::Ptr< T > Class Template Reference
[Smart Pointer]

smart pointer class similar to boost::intrusive_ptr More...

#include <ptr.h>

List of all members.

Classes

class  Tester

Public Member Functions

 Ptr ()
 Ptr (T *ptr)
 Ptr (T *ptr, bool ref)
 Ptr (Ptr const &o)
template<typename U >
 Ptr (Ptr< U > const &o)
 ~Ptr ()
Ptr< T > & operator= (Ptr const &o)
T * operator-> () const
T * operator-> ()
const T & operator* () const
const T & operator* ()
bool operator! ()
 operator Tester * () const

Private Member Functions

void Acquire (void) const

Private Attributes

T * m_ptr

Friends

class Ptr< const T >
template<typename U >
U * GetPointer (const Ptr< U > &p)
template<typename U >
U * PeekPointer (const Ptr< U > &p)

Related Functions

(Note that these are not member functions.)



template<typename T >
T * PeekPointer (const Ptr< T > &p)
template<typename T >
T * GetPointer (const Ptr< T > &p)

Detailed Description

template<typename T>
class ns3::Ptr< T >

smart pointer class similar to boost::intrusive_ptr

This smart-pointer class assumes that the underlying type provides a pair of Ref and Unref methods which are expected to increment and decrement the internal refcount of the object instance.

This implementation allows you to manipulate the smart pointer as if it was a normal pointer: you can compare it with zero, compare it against other pointers, assign zero to it, etc.

It is possible to extract the raw pointer from this smart pointer with the GetPointer and PeekPointer methods.

If you want to store a newed object into a smart pointer, we recommend you to use the Create template functions to create the object and store it in a smart pointer to avoid memory leaks. These functions are really small conveniance functions and their goal is just is save you a small bit of typing.

Definition at line 59 of file ptr.h.


Constructor & Destructor Documentation

template<typename T >
ns3::Ptr< T >::Ptr (  )  [inline]

Create an empty smart pointer

Definition at line 392 of file ptr.h.

template<typename T>
ns3::Ptr< T >::Ptr ( T *  ptr  )  [inline]
Parameters:
ptr raw pointer to manage

Create a smart pointer which points to the object pointed to by the input raw pointer ptr. This method creates its own reference to the pointed object. The caller is responsible for Unref()'ing its own reference, and the smart pointer will eventually do the same, so that object is deleted if no more references to it remain.

Definition at line 397 of file ptr.h.

References ns3::Ptr< T >::Acquire().

template<typename T>
ns3::Ptr< T >::Ptr ( T *  ptr,
bool  ref 
) [inline]
Parameters:
ptr raw pointer to manage
ref if set to true, this method calls Ref, otherwise, it does not call Ref.

Create a smart pointer which points to the object pointed to by the input raw pointer ptr.

Definition at line 404 of file ptr.h.

References ns3::Ptr< T >::Acquire().

template<typename T>
ns3::Ptr< T >::Ptr ( Ptr< T > const &  o  )  [inline]

Definition at line 414 of file ptr.h.

References ns3::Ptr< T >::Acquire().

template<typename T >
template<typename U >
ns3::Ptr< T >::Ptr ( Ptr< U > const &  o  )  [inline]

Definition at line 421 of file ptr.h.

References ns3::Ptr< T >::Acquire().

template<typename T >
ns3::Ptr< T >::~Ptr (  )  [inline]

Definition at line 428 of file ptr.h.

References ns3::Ptr< T >::m_ptr.


Member Function Documentation

template<typename T >
void ns3::Ptr< T >::Acquire ( void   )  const [inline, private]

Definition at line 383 of file ptr.h.

References ns3::Ptr< T >::m_ptr.

Referenced by ns3::GetPointer(), ns3::Ptr< T >::operator=(), and ns3::Ptr< T >::Ptr().

template<typename T >
ns3::Ptr< T >::operator Tester * (  )  const [inline]

Definition at line 489 of file ptr.h.

References ns3::Ptr< T >::m_ptr.

template<typename T >
bool ns3::Ptr< T >::operator! (  )  [inline]

Definition at line 483 of file ptr.h.

References ns3::Ptr< T >::m_ptr.

template<typename T >
const T & ns3::Ptr< T >::operator* (  )  [inline]

Definition at line 476 of file ptr.h.

References ns3::Ptr< T >::m_ptr.

template<typename T >
const T & ns3::Ptr< T >::operator* (  )  const [inline]

Definition at line 469 of file ptr.h.

References ns3::Ptr< T >::m_ptr.

template<typename T >
T * ns3::Ptr< T >::operator-> (  )  [inline]

Definition at line 455 of file ptr.h.

References ns3::Ptr< T >::m_ptr.

template<typename T >
T * ns3::Ptr< T >::operator-> (  )  const [inline]

Definition at line 462 of file ptr.h.

References ns3::Ptr< T >::m_ptr.

template<typename T >
Ptr< T > & ns3::Ptr< T >::operator= ( Ptr< T > const &  o  )  [inline]

Definition at line 438 of file ptr.h.

References ns3::Ptr< T >::Acquire(), and ns3::Ptr< T >::m_ptr.


Friends And Related Function Documentation

template<typename T >
T * GetPointer ( const Ptr< T > &  p  )  [related]
Returns:
the pointer managed by this smart pointer.

The underlying refcount is incremented prior to returning to the caller so the caller is responsible for calling Unref himself.

Definition at line 283 of file ptr.h.

template<typename T>
template<typename U >
U* GetPointer ( const Ptr< U > &  p  )  [friend]
template<typename T >
T * PeekPointer ( const Ptr< T > &  p  )  [related]
Returns:
the pointer managed by this smart pointer.

The underlying refcount is not incremented prior to returning to the caller so the caller is not responsible for calling Unref himself.

Definition at line 277 of file ptr.h.

template<typename T>
template<typename U >
U* PeekPointer ( const Ptr< U > &  p  )  [friend]
template<typename T>
friend class Ptr< const T > [friend]

Definition at line 67 of file ptr.h.


Member Data Documentation

template<typename T>
T* ns3::Ptr< T >::m_ptr [private]

The documentation for this class was generated from the following file:
Generated on Thu Dec 3 14:10:25 2009 for NS-3 by  doxygen 1.6.3