FX::FXRefingObject< type > Class Template Reference

#include <FXRefedObject.h>

Inheritance diagram for FX::FXRefingObject< type >:

Inheritance graph
[legend]

List of all members.


Detailed Description

template<class type>
class FX::FXRefingObject< type >

A handle to a reference counted object.

Parameters:
type The type of the data to be reference counted. This must inherit FX::FXRefedObject
FX::FXRefingObject and FX::FXRefedObject are a pair of classes which denote a handle and reference counted object respectively. The basic premise is that a FXRefedObject subclass maintains a count incremented by the construction of a corresponding FXRefingObject pointing to it and decremented by the same's destruction. If the count reaches zero, the virtual method FX::FXRefedObject::noMoreReferrers() is called which typically deletes the object.

In v0.6 of TnFOX the old implementation of this taken from Tornado was replaced with a much superior version based on FX::Generic::ptr. This has enabled a much greater degree of self-determination - now FXRefingObject configures itself automatically according to how you configure its FXRefedObject - you no longer need to reproduce the policies. Also when type inherits a FX::QMutex that mutex is automatically locked around modifications to the referrers list if enabled.

The basic form is as follows:

class Foo : public FXRefedObject<FXAtomicInt>, public QMutex
{
   bool foo();
};
typedef FXRefingObject<Foo> FooHold;
...
bool f(Foo *f)
{
   FooHold fh(f);
   return fh->foo();
}
In addition to the usual PtrPtr(), PtrRef(), PtrRelease() and PtrReset() helper functions there is a PtrDetach() which returns a handle referring to a new copy constructed instance of the pointee.

FXRefingObject can work with FX::FXLRUCache to implement a LRU caching system of reference counted objects.

See also:
FX::FXRefedObject, FX::FXLRUCache

Public Member Functions

 FXRefingObject (type *data=0, const char *file=0, int lineno=0)
 FXRefingObject (FXAutoPtr< type > &ptr)
 FXRefingObject (const FXRefingObject &o, const char *file=0, int lineno=0)
const char * int_allocated_file () const throw ()
int int_allocated_lineno () const throw ()
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

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

Constructor & Destructor Documentation

template<class type>
FX::FXRefingObject< type >::FXRefingObject ( type *  data = 0,
const char *  file = 0,
int  lineno = 0 
) [inline]

Constructs an instance holding a reference to data.


Friends And Related Function Documentation

template<class type>
FXRefingObject PtrDetach ( FXRefingObject< type > &  p  )  [friend]

Makes a copy of the referenced object and returns a holder pointing to the new copy

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

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, inherited]

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:11:39 2008 for TnFOX by doxygen v1.5.6