Scopira  20080306
scopira::tool::count_ptr< T > Class Template Reference

#include <object.h>

Public Types

typedef T data_type
 

Public Member Functions

 count_ptr (void)
 
 count_ptr (T *o)
 
 count_ptr (const count_ptr< T > &o)
 
template<class Y >
 count_ptr (const count_ptr< Y > &o)
 
 ~count_ptr ()
 
void set (T *o)
 
count_ptroperator= (T *o)
 
count_ptroperator= (const count_ptr< T > &o)
 
bool operator== (const count_ptr< T > &rhs) const
 
bool operator== (const T *rhs) const
 
bool operator!= (const count_ptr< T > &rhs) const
 
bool operator!= (const T *rhs) const
 
bool operator< (const count_ptr< T > &rhs) const
 
scopira::tool::oflow_iprint (scopira::tool::oflow_i &o) const
 
T * get (void) const
 
T & ref (void) const
 
T * operator-> (void) const
 
T & operator* (void) const
 
bool is_null (void) const
 

Protected Attributes

T * dm_ptr
 

Detailed Description

template<class T>
class scopira::tool::count_ptr< T >

A reference counting auto pointer of scopira::tool::object and its decendants. This class has the following key characteristics:

  • safe, null initialization
  • always maintain one (and only one) * count to its given pointer

You can use this class like so:

{
scopira::tool::countr_ptr<X> x = new X;
// you need not (and must not) delete explicitly now
}//at this point, x will automatically delete the pointer

Here is a more complex example:

{
scopira::tool::countr_ptr<X> x; //x will be initialized to null
{
scopira::tool::countr_ptr<X> y = new X; // y points to a new instace of X
x = y; // y and x now both reference the same, new instance
}//y is destroyed here, however, the instance is now as x still has a reference
}//x is destroyed, as since its the last reference, so is the actual instance of X
See also
scopira::tool::object
Reference counting
Author
Aleksander Demko

Constructor & Destructor Documentation

◆ count_ptr() [1/4]

template<class T>
scopira::tool::count_ptr< T >::count_ptr ( void  )
inline

Constructor, null initializing

Author
Aleksander Demko

◆ count_ptr() [2/4]

template<class T>
scopira::tool::count_ptr< T >::count_ptr ( T *  o)
inline

Initializing constructor

Author
Aleksander Demko

◆ count_ptr() [3/4]

template<class T>
scopira::tool::count_ptr< T >::count_ptr ( const count_ptr< T > &  o)
inline

Copy constructor

Author
Aleksander Demko

◆ count_ptr() [4/4]

template<class T>
template<class Y >
scopira::tool::count_ptr< T >::count_ptr ( const count_ptr< Y > &  o)
inline

Copy constructor

Author
Aleksander Demko

◆ ~count_ptr()

template<class T>
scopira::tool::count_ptr< T >::~count_ptr ( )
inline

Destructor

Author
Aleksander Demko

Member Function Documentation

◆ get()

template<class T>
T* scopira::tool::count_ptr< T >::get ( void  ) const
inline

◆ is_null()

template<class T>
bool scopira::tool::count_ptr< T >::is_null ( void  ) const
inline

Is the pointer null?

Returns
true if the internal pointer is null.
Author
Aleksander Demko

Referenced by scopira::core::model_i::get_tagged_model().

◆ operator!=() [1/2]

template<class T>
bool scopira::tool::count_ptr< T >::operator!= ( const count_ptr< T > &  rhs) const
inline

Comparison (not equals) operator - compares the internal pointer values.

Author
Aleksander Demko

◆ operator!=() [2/2]

template<class T>
bool scopira::tool::count_ptr< T >::operator!= ( const T *  rhs) const
inline

Comparison (not equals) operator - compares the internal pointer value to the given pointer.

Author
Aleksander Demko

◆ operator*()

template<class T>
T& scopira::tool::count_ptr< T >::operator* ( void  ) const
inline

Convinient * deferencer.

Author
Aleksander Demko

◆ operator->()

template<class T>
T* scopira::tool::count_ptr< T >::operator-> ( void  ) const
inline

Convinient -> accesor to the object

Author
Aleksander Demko

◆ operator<()

template<class T>
bool scopira::tool::count_ptr< T >::operator< ( const count_ptr< T > &  rhs) const
inline

Comparison (less than) operator - compares the internal pointer values.

Author
Aleksander Demko

◆ operator=() [1/2]

template<class T>
count_ptr& scopira::tool::count_ptr< T >::operator= ( T *  o)
inline

Basic assignment.

Author
Aleksander Demko

◆ operator=() [2/2]

template<class T>
count_ptr& scopira::tool::count_ptr< T >::operator= ( const count_ptr< T > &  o)
inline

Basic assignment.

Author
Aleksander Demko

◆ operator==() [1/2]

template<class T>
bool scopira::tool::count_ptr< T >::operator== ( const count_ptr< T > &  rhs) const
inline

Comparison (equals) operator - compares the internal pointer values.

Author
Aleksander Demko

◆ operator==() [2/2]

template<class T>
bool scopira::tool::count_ptr< T >::operator== ( const T *  rhs) const
inline

Comparison (equals) operator - compares the internal pointer value to the given pointer.

Author
Aleksander Demko

◆ print()

template<class T>
scopira::tool::oflow_i& scopira::tool::count_ptr< T >::print ( scopira::tool::oflow_i o) const
inline

Pretty ascii printer, redirects to internal class.

Author
Aleksander Demko

◆ ref()

template<class T>
T& scopira::tool::count_ptr< T >::ref ( void  ) const
inline

Gets the current object, as a reference

Author
Aleksander Demko

◆ set()

template<class T>
void scopira::tool::count_ptr< T >::set ( T *  o)
inline

Sets the current pointer. Any old pointer will ofcourse be unreferenced.

Author
Aleksander Demko

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