#include <FXGenericTools.h>
Inheritance diagram for FX::Generic::ptr< type, ownershipPolicy >:
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:
copy()
to be available). refCount()
to return a reference to some int
like entity eg; FX::FXAtomicInt). Deletion of the smart pointer decrements the pointee's reference count. You'll also want to know about the helper functions:
operator=
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.
Definition at line 495 of file FXGenericTools.h.
Public Member Functions | |
ptr (type *data=0) | |
ptr (const ptr &o) | |
ptr & | operator= (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) |