Common::GaSmartStorage< T > Class Template Reference

GaSmartStorage template class provides reference-counting for smart pointers. GaSmartStorage objects holds address of used data and number of references (smart pointers) which point to the data. Object of this class as well as the data are destroyed and memory is freed when there are no more references which points to the data. Arrays cannot be used with this class. This class has no built-in synchronizator, so LOCK_OBJECT and LOCK_THIS_OBJECT macros cannot be used with instances of this class, but all public method and operators are thread-safe. More...

#include <D:/Temp/vs/gal/source/SmartPtr.h>

List of all members.

Public Member Functions

 GaSmartStorage (T *data)
 Initializes object for counting references to data located at data address.
 ~GaSmartStorage ()
 Destructor is called when there are no more references which points to the data. Destructor frees memory used by the data.
T *GACALL GetData () const
 This method is thread-safe.
int GACALL GetCount () const
 This method is thread-safe.

Static Public Member Functions

static GaSmartPtr< T > GACALL MakeInstance (T *data)
 MakeInstance makes new reference-counting object for data at address data. This method is thread-safe.
static GaSmartStorage< T > *GACALL MakeInstanceDirect (T *data)
 MakeInstance makes new reference-counting object for data at address data. This method is thread-safe.
static int GACALL AddReference (GaSmartStorage< T > *location)
 This method increments number of references to the data. AddReference method is called when smart pointer is set to point to the location. This method is thread-safe.
static int GACALL RemoveReference (GaSmartStorage< T > *location)
 This method decrements number of references, if that number reaches 0, the data is destroyed and memory is freed. RemoveReference method is called when smart pointers are destructed or when set to point to new location. This method is thread-safe.

Private Attributes

int _count
 Holds number of references (smart pointers) to data guarded by this object.
T * _data
 Pointer to user data.

Friends

class GaSmartPtr< T >


Detailed Description

template<typename T>
class Common::GaSmartStorage< T >

GaSmartStorage template class provides reference-counting for smart pointers. GaSmartStorage objects holds address of used data and number of references (smart pointers) which point to the data. Object of this class as well as the data are destroyed and memory is freed when there are no more references which points to the data. Arrays cannot be used with this class. This class has no built-in synchronizator, so LOCK_OBJECT and LOCK_THIS_OBJECT macros cannot be used with instances of this class, but all public method and operators are thread-safe.


Constructor & Destructor Documentation

template<typename T>
Common::GaSmartStorage< T >::GaSmartStorage ( T *  data  )  [inline]

Initializes object for counting references to data located at data address.

Parameters:
data pointer to user data. data cannot be an array.

template<typename T>
Common::GaSmartStorage< T >::~GaSmartStorage (  )  [inline]

Destructor is called when there are no more references which points to the data. Destructor frees memory used by the data.


Member Function Documentation

template<typename T>
static GaSmartPtr<T> GACALL Common::GaSmartStorage< T >::MakeInstance ( T *  data  )  [inline, static]

MakeInstance makes new reference-counting object for data at address data. This method is thread-safe.

Parameters:
data pointer to data. data cannot be an array.
Returns:
Method returns smart pointer which points to data and use newly created object for reference-counting.

template<typename T>
static GaSmartStorage<T>* GACALL Common::GaSmartStorage< T >::MakeInstanceDirect ( T *  data  )  [inline, static]

MakeInstance makes new reference-counting object for data at address data. This method is thread-safe.

Parameters:
data pointer to data. data cannot be an array.
Returns:
Method returns reference to newly created object for reference-counting.

template<typename T>
static int GACALL Common::GaSmartStorage< T >::AddReference ( GaSmartStorage< T > *  location  )  [inline, static]

This method increments number of references to the data. AddReference method is called when smart pointer is set to point to the location. This method is thread-safe.

Parameters:
location pointer to location which is incremented.
Returns:
Method returns new number of references which still points to the data.

template<typename T>
static int GACALL Common::GaSmartStorage< T >::RemoveReference ( GaSmartStorage< T > *  location  )  [inline, static]

This method decrements number of references, if that number reaches 0, the data is destroyed and memory is freed. RemoveReference method is called when smart pointers are destructed or when set to point to new location. This method is thread-safe.

Parameters:
location pointer to location which is decremented.
Returns:
Method returns new number of references which still points to the data.

template<typename T>
T* GACALL Common::GaSmartStorage< T >::GetData (  )  const [inline]

This method is thread-safe.

Returns:
Method returns pointer to user data.

template<typename T>
int GACALL Common::GaSmartStorage< T >::GetCount (  )  const [inline]

This method is thread-safe.

Returns:
Method returns number of references (smart pointers) which points to this location.


Friends And Related Function Documentation

template<typename T>
friend class GaSmartPtr< T > [friend]


Member Data Documentation

template<typename T>
int Common::GaSmartStorage< T >::_count [mutable, private]

Holds number of references (smart pointers) to data guarded by this object.

template<typename T>
T* Common::GaSmartStorage< T >::_data [private]

Pointer to user data.


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

Genetic Algorithm Library
Coolsoft Software Development