FX::Generic::ptr< type, ownershipPolicy > Class Template Reference
[Generic Tools in TnFOX]

#include <FXGenericTools.h>

Inheritance diagram for FX::Generic::ptr< type, ownershipPolicy >:

Inheritance graph
[legend]

List of all members.


Detailed Description

template<typename type, template< class > class ownershipPolicy = FX::Pol::destructiveCopy>
class FX::Generic::ptr< type, ownershipPolicy >

A policy-based smart pointer.

I was very much taken by Alexandrescu's policy-based smart pointer and though the one I offer here is considerably reduced in scope, it can be easily expanded into the future - and almost certainly shall be.

Until then, you have the following policies available:

For all these except where specified, deleting the smart pointer deletes its pointee.

You'll also want to know about the helper functions:

These helper functions work via Koenig lookup and thus do not need namespace qualification.

Usage:

Like Alexandrescu's smart pointer, this smart pointer is not entirely a pointer replacement. It enables smart pointer semantics which aren't the same as pointer semantics. Smart pointer semantics enabled by the policies such as listed above are defeated if you have direct access to the held pointer so no implicit conversions are provided nor the address-of operator. However, you can test the smart pointer for equality against other pointers including other smart pointers and implicit conversion to base classes is correctly handled.

If you are used to using smart pointers to enable exception-safety, TnFOX isn't built around that - I personally find it easy to get it wrong when using smart pointers for that purpose as different policies enable quite different smart pointer behaviour and well, to me they're all smart pointers! I prefer to use a pointer holder (FX::FXPtrHold) or transaction rollbacks to enable exception-safety - they are much clearer in saying what they're doing and if you forget them it's obvious when looking at the code. This IMHO is better than the implicit behaviour of some reconfigurable abstract entity.

See also:
FXAutoPtr, FX::FXPtrHold

Public Member Functions

 ptr (type *data=0)
 ptr (const ptr &o)
ptroperator= (type *data)
type & operator* ()
const type & operator* () const
type * operator-> ()
const type * operator-> () const
template<typename T>
bool operator== (const ptr< T > &o) const
template<typename T>
bool operator== (T *o) const
 operator Tester * () const
bool operator! () const
template<typename T>
bool operator!= (const ptr< T > &o) const
template<typename T>
bool operator!= (T *o) const

Friends

type * PtrRelease (ptr &p)
void PtrReset (ptr &p, type *data)

Constructor & Destructor Documentation

template<typename type, template< class > class ownershipPolicy = FX::Pol::destructiveCopy>
FX::Generic::ptr< type, ownershipPolicy >::ptr ( type *  data = 0  )  [inline]

Constructs a smart pointer pointing to data.


Member Function Documentation

template<typename type, template< class > class ownershipPolicy = FX::Pol::destructiveCopy>
ptr& FX::Generic::ptr< type, ownershipPolicy >::operator= ( type *  data  )  [inline]

Resets the pointer to data.


Friends And Related Function Documentation

template<typename type, template< class > class ownershipPolicy = FX::Pol::destructiveCopy>
type* PtrRelease ( ptr< type, ownershipPolicy > &  p  )  [friend]

Releases the pointer (sets it to zero, returns the former contents).

template<typename type, template< class > class ownershipPolicy = FX::Pol::destructiveCopy>
void PtrReset ( ptr< type, ownershipPolicy > &  p,
type *  data 
) [friend]

Resets the pointer (deletes the old contents, sets to new contents).

Referenced by FX::Generic::ptr< FX::TnFXSQLDBCursor, FX::FXRefingObjectImpl::refedObject< type > >::operator=().


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

(C) 2002-2008 Niall Douglas. Some parts (C) to assorted authors.
Generated on Fri Jun 13 22:30:06 2008 for TnFOX by doxygen v1.5.6