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

#include <FXGenericTools.h>

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

FX::FXRefingObject< type > FX::TnFXVTKHold< type > 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

Definition at line 495 of file FXGenericTools.h.

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)


The documentation for this class was generated from the following file:
(C) 2002-2009 Niall Douglas. Some parts (C) to assorted authors.
Generated on Fri Nov 20 18:37:57 2009 for TnFOX by doxygen v1.4.7