greedy_ptr< _Tp > Class Template Reference

A simple smart pointer providing strict ownership semantics. More...

#include <ncutMemory.h>

List of all members.

Public Types

typedef _Tp element_type
 The pointed-to type.

Public Member Functions

 greedy_ptr (element_type *__p=0) throw ()
 A greedy_ptr is usually constructed from a raw pointer.
 greedy_ptr (element_type &__p) throw ()
 A greedy_ptr can be constructed from a reference.
 greedy_ptr (const greedy_ptr &__a) throw ()
 A greedy_ptr can be constructed from another greedy_ptr.
template<typename _Tp1>
 greedy_ptr (std::auto_ptr< _Tp1 > &__a) throw ()
 A greedy_ptr can be constructed from an auto_ptr.
 greedy_ptr (std::auto_ptr< element_type > &__a) throw ()
 A greedy_ptr can be constructed from an auto_ptr.
template<typename _Tp1>
 greedy_ptr (const greedy_ptr< _Tp1 > &__a) throw ()
 A greedy_ptr can be constructed from another greedy_ptr.
greedy_ptroperator= (const greedy_ptr &__a) throw ()
 greedy_ptr assignment operator.
template<typename _Tp1>
greedy_ptroperator= (const greedy_ptr< _Tp1 > &__a) throw ()
 greedy_ptr assignment operator.
greedy_ptroperator= (element_type *__p) throw ()
 greedy_ptr assignment operator.
greedy_ptroperator= (element_type &__p) throw ()
 greedy_ptr assignment operator.
 ~greedy_ptr ()
element_typeoperator * () const throw ()
 Smart pointer dereferencing.
element_typeoperator-> () const throw ()
 Smart pointer dereferencing.
element_typeget () const throw ()
 Bypassing the smart pointer.
bool owns () const throw ()
 Getting ownership status.
element_typerelease () throw ()
 Bypassing the smart pointer.
void reset (element_type *__p=0) throw ()
 Forcibly deletes the managed object.
void reset (element_type &__p=0) throw ()
 Forcibly deletes the managed object.
 greedy_ptr (greedy_ptr_ref< element_type > __ref) throw ()
 Automatic conversions.
greedy_ptroperator= (greedy_ptr_ref< element_type > __ref) throw ()
template<typename _Tp1>
 operator greedy_ptr_ref () throw ()
template<typename _Tp1>
 operator greedy_ptr () throw ()


Detailed Description

template<typename _Tp>
class greedy_ptr< _Tp >

A simple smart pointer providing strict ownership semantics.

A greedy_ptr only owns the object it holds a pointer to, if it was constructed from a raw pointer (i.e. if it was the first greedy_ptr to manage the pointed-to object). Copying a greedy_ptr copies the pointer but does not transfer ownership to the destination, the source greedy_ptr retains ownership. If more than one greedy_ptr owns the same object at the same time the behavior of the program is undefined.


Constructor & Destructor Documentation

template<typename _Tp>
greedy_ptr< _Tp >::greedy_ptr element_type __p = 0  )  throw () [inline, explicit]
 

A greedy_ptr is usually constructed from a raw pointer.

Parameters:
__p A pointer (defaults to NULL).
This object now owns the object pointed to by p.

template<typename _Tp>
greedy_ptr< _Tp >::greedy_ptr element_type __p  )  throw () [inline, explicit]
 

A greedy_ptr can be constructed from a reference.

Parameters:
__p A reference (defaults to NULL).
This object does not own the object p.

template<typename _Tp>
greedy_ptr< _Tp >::greedy_ptr const greedy_ptr< _Tp > &  __a  )  throw () [inline]
 

A greedy_ptr can be constructed from another greedy_ptr.

Parameters:
__a Another greedy_ptr of the same type.
This object does not own the object owned by a, which still holds ownership.

template<typename _Tp>
template<typename _Tp1>
greedy_ptr< _Tp >::greedy_ptr std::auto_ptr< _Tp1 > &  __a  )  throw () [inline]
 

A greedy_ptr can be constructed from an auto_ptr.

Parameters:
__a An auto_ptr of a different but related type.
A pointer-to-Tp1 must be convertible to a pointer-to-Tp/element_type.

This object now owns the object previously owned by a, which has given up ownership.

template<typename _Tp>
greedy_ptr< _Tp >::greedy_ptr std::auto_ptr< element_type > &  __a  )  throw () [inline]
 

A greedy_ptr can be constructed from an auto_ptr.

Parameters:
__a An auto_ptr of the same type.
This object now owns the object previously owned by a, which has given up ownership.

template<typename _Tp>
template<typename _Tp1>
greedy_ptr< _Tp >::greedy_ptr const greedy_ptr< _Tp1 > &  __a  )  throw () [inline]
 

A greedy_ptr can be constructed from another greedy_ptr.

Parameters:
__a Another greedy_ptr of a different but related type.
A pointer-to-Tp1 must be convertible to a pointer-to-Tp/element_type.

This object does not own the object owned by a, which still holds ownership.

template<typename _Tp>
greedy_ptr< _Tp >::~greedy_ptr  )  [inline]
 

When the greedy_ptr goes out of scope, the object it owns is deleted. If it no longer owns anything then this has no effect.

The C++ standard says there is supposed to be an empty throw specification here, but omitting it is standard conforming. Its presence can be detected only if _Tp::~_Tp() throws, but this is prohibited. [17.4.3.6]/2

template<typename _Tp>
greedy_ptr< _Tp >::greedy_ptr greedy_ptr_ref< element_type __ref  )  throw () [inline]
 

Automatic conversions.

These operations convert an greedy_ptr into and from an greedy_ptr_ref automatically as needed. This allows constructs such as

    greedy_ptr<Derived>  func_returning_greedy_ptr(.....);
    ...
    greedy_ptr<Base> ptr = func_returning_greedy_ptr(.....);


Member Function Documentation

template<typename _Tp>
element_type* greedy_ptr< _Tp >::get  )  const throw () [inline]
 

Bypassing the smart pointer.

Returns:
The raw pointer being managed.
You can get a copy of the pointer that this object owns, for situations such as passing to a function which only accepts a raw pointer.

Note:
If this greedy_ptr was owning the memory, it still does.

template<typename _Tp>
element_type& greedy_ptr< _Tp >::operator *  )  const throw () [inline]
 

Smart pointer dereferencing.

If this greedy_ptr is a null pointer, then this operation will crash.

template<typename _Tp>
element_type* greedy_ptr< _Tp >::operator->  )  const throw () [inline]
 

Smart pointer dereferencing.

This returns the pointer itself, which the language then will automatically cause to be dereferenced.

template<typename _Tp>
greedy_ptr& greedy_ptr< _Tp >::operator= element_type __p  )  throw () [inline]
 

greedy_ptr assignment operator.

Parameters:
__p A reference.
A convenience function, does exactly the same thing as reset(__p).

template<typename _Tp>
greedy_ptr& greedy_ptr< _Tp >::operator= element_type __p  )  throw () [inline]
 

greedy_ptr assignment operator.

Parameters:
__p A pointer.
A convenience function, does exactly the same thing as reset(__p).

template<typename _Tp>
template<typename _Tp1>
greedy_ptr& greedy_ptr< _Tp >::operator= const greedy_ptr< _Tp1 > &  __a  )  throw () [inline]
 

greedy_ptr assignment operator.

Parameters:
__a Another greedy_ptr of a different but related type.
A pointer-to-Tp1 must be convertible to a pointer-to-Tp/element_type.

This object does not own the object owned by a, which still holds ownership. If this greedy_ptr used to own an object, that object has been deleted.

template<typename _Tp>
greedy_ptr& greedy_ptr< _Tp >::operator= const greedy_ptr< _Tp > &  __a  )  throw () [inline]
 

greedy_ptr assignment operator.

Parameters:
__a Another greedy_ptr of the same type.
This object does not own the object owned by a, which still holds ownership. If this greedy_ptr used to own an object, that object has been deleted.

template<typename _Tp>
bool greedy_ptr< _Tp >::owns  )  const throw () [inline]
 

Getting ownership status.

Returns:
true if this greedy_ptr owns the object being managed, false otherwise.
You can query the greedy_ptr for ownership of the object being managed. NULL pointers are never owned.

template<typename _Tp>
element_type* greedy_ptr< _Tp >::release  )  throw () [inline]
 

Bypassing the smart pointer.

Returns:
The raw pointer being managed.
You can get a copy of the pointer that this object owns, for situations such as passing to a function which only accepts a raw pointer.

Note:
This greedy_ptr no longer owns the memory. When this object goes out of scope, nothing will happen.

template<typename _Tp>
void greedy_ptr< _Tp >::reset element_type __p = 0  )  throw () [inline]
 

Forcibly deletes the managed object.

Parameters:
__p A reference.
This object now holds a pointer to p , but does not own it. The previously held object has been deleted.

template<typename _Tp>
void greedy_ptr< _Tp >::reset element_type __p = 0  )  throw () [inline]
 

Forcibly deletes the managed object.

Parameters:
__p A pointer (defaults to NULL).
This object now owns the object pointed to by p. The previous object has been deleted.


The documentation for this class was generated from the following file:
Generated on Thu Jun 22 14:47:20 2006 for ncut.kdevelop by  doxygen 1.4.6