Claw  1.7.3
Public Types | Public Member Functions | List of all members
claw::memory::smart_ptr< T > Class Template Reference

A pointer with a reference counter. More...

#include <smart_ptr.hpp>

Public Types

typedef T value_type
 The type of the pointed data.
typedef smart_ptr< value_typeself_type
 The type of the current class.
typedef T & reference
 Reference on the type of the stored data.
typedef T * pointer
 Pointer on the type of the stored data.
typedef const T & const_reference
 Constant reference on the type of the stored data.
typedef const T *const const_pointer
 Constant pointer on the type of the stored data.

Public Member Functions

 smart_ptr ()
 Default constructor.
 smart_ptr (pointer data)
 Constructor from a pointer.
 smart_ptr (const self_type &that)
 Copy constructor.
 ~smart_ptr ()
 Destructor. The memory is freed only if no more smart_ptr point on it.
self_typeoperator= (const self_type &that)
 Assignment operator.
bool operator== (const self_type &that) const
 Equality operator.
bool operator!= (const self_type &that) const
 Disequality operator.
bool operator< (const self_type &that) const
 "Less than" operator.
bool operator<= (const self_type &that) const
 "Less or equal" operator.
bool operator> (const self_type &that) const
 "Greater than" operator.
bool operator>= (const self_type &that) const
 "Greater or equal" operator.
pointer operator-> ()
 Dereference operator.
pointer operator-> () const
 Dereference operator.
reference operator* ()
 Dereference operator.
reference operator* () const
 Dereference operator.

Detailed Description

template<typename T>
class claw::memory::smart_ptr< T >

A pointer with a reference counter.

Smart pointers allow the user to stop caring about the release of dynamically allocated memory. When no more pointers point to the allocated memory, this memory is released.

Template parameters:

Author
Julien Jorge

Definition at line 51 of file smart_ptr.hpp.

Constructor & Destructor Documentation

template<typename T >
claw::memory::smart_ptr< T >::smart_ptr ( pointer  data)

Constructor from a pointer.

Parameters
dataPointer on the data.

Warning: this constructor allows expressions like

int a; smart_ptr<int> p(&a);

Nevertheless, you should never fo that.

Definition at line 56 of file smart_ptr.tpp.

template<typename T >
claw::memory::smart_ptr< T >::smart_ptr ( const self_type that)

Copy constructor.

Parameters
thatThe smart_pointer to copy.

Definition at line 72 of file smart_ptr.tpp.

Member Function Documentation

template<typename T >
bool claw::memory::smart_ptr< T >::operator!= ( const self_type that) const

Disequality operator.

Parameters
thatThe pointer to compare to.
Returns
(*this < that) || (that < *this).

Definition at line 124 of file smart_ptr.tpp.

template<typename T >
bool claw::memory::smart_ptr< T >::operator< ( const self_type that) const

"Less than" operator.

Parameters
thatThe pointer to compare to.
Returns
True if the address pointed by this is lower than the address pointed by that.

Definition at line 137 of file smart_ptr.tpp.

template<typename T >
bool claw::memory::smart_ptr< T >::operator<= ( const self_type that) const

"Less or equal" operator.

Parameters
thatThe pointer to compare to.
Returns
!(that < *this).

Definition at line 149 of file smart_ptr.tpp.

template<typename T >
claw::memory::smart_ptr< T >::self_type & claw::memory::smart_ptr< T >::operator= ( const self_type that)

Assignment operator.

Parameters
thatThe smart_ptr to copy.

Definition at line 94 of file smart_ptr.tpp.

template<typename T >
bool claw::memory::smart_ptr< T >::operator== ( const self_type that) const

Equality operator.

Parameters
thatThe pointer to compare to.
Returns
!(*this < that) && !(that < *this).

Definition at line 112 of file smart_ptr.tpp.

template<typename T >
bool claw::memory::smart_ptr< T >::operator> ( const self_type that) const

"Greater than" operator.

Parameters
thatThe pointer to compare to.
Returns
that < *this.

Definition at line 161 of file smart_ptr.tpp.

template<typename T >
bool claw::memory::smart_ptr< T >::operator>= ( const self_type that) const

"Greater or equal" operator.

Parameters
thatThe pointer to compare to.
Returns
!(*this < that).

Definition at line 173 of file smart_ptr.tpp.


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