Back to index

nordugrid-arc-nox  1.1.0~rc6
Classes | Public Member Functions | Private Attributes
Arc::CountedPointer< T > Class Template Reference

Wrapper for pointer with automatic destruction and mutiple references. More...

#include <Utils.h>

Collaboration diagram for Arc::CountedPointer< T >:
Collaboration graph
[legend]

List of all members.

Classes

class  Base

Public Member Functions

 CountedPointer (T *p)
 CountedPointer (CountedPointer< T > &p)
 ~CountedPointer (void)
CountedPointeroperator= (T *p)
CountedPointeroperator= (CountedPointer &p)
Toperator* (void) const
 For refering wrapped object.
Toperator-> (void) const
 For refering wrapped object.
 operator bool (void) const
 Returns false if pointer is NULL and true otherwise.
bool operator! (void) const
 Returns true if pointer is NULL and false otherwise.
 operator T * (void) const
 Cast to original pointer.

Private Attributes

Base< T > * object

Detailed Description

template<typename T>
class Arc::CountedPointer< T >

Wrapper for pointer with automatic destruction and mutiple references.

If ordinary pointer is wrapped in instance of this class it will be automatically destroyed when all instances refering to it are destroyed. This is useful for maintaing pointers refered from multiple structures wihth automatic destruction of original object when last reference is destroyed. It is similar to Java approach with a difference that desctruction time is strictly defined. Only pointers returned by new() are supported. This class is not thread-safe

Definition at line 85 of file Utils.h.


Constructor & Destructor Documentation

template<typename T>
Arc::CountedPointer< T >::CountedPointer ( T p) [inline]

Definition at line 117 of file Utils.h.

      : object(new Base<T>(p)) {}
template<typename T>
Arc::CountedPointer< T >::CountedPointer ( CountedPointer< T > &  p) [inline]

Definition at line 119 of file Utils.h.

      : object(p.object->add()) {}
template<typename T>
Arc::CountedPointer< T >::~CountedPointer ( void  ) [inline]

Definition at line 121 of file Utils.h.

                          {
      object->rem();
    }

Member Function Documentation

template<typename T>
Arc::CountedPointer< T >::operator bool ( void  ) const [inline]

Returns false if pointer is NULL and true otherwise.

Definition at line 147 of file Utils.h.

                              {
      return ((object->ptr) != NULL);
    }
template<typename T>
Arc::CountedPointer< T >::operator T * ( void  ) const [inline]

Cast to original pointer.

Definition at line 155 of file Utils.h.

                            {
      return (object->ptr);
    }
template<typename T>
bool Arc::CountedPointer< T >::operator! ( void  ) const [inline]

Returns true if pointer is NULL and false otherwise.

Definition at line 151 of file Utils.h.

                               {
      return ((object->ptr) == NULL);
    }
template<typename T>
T& Arc::CountedPointer< T >::operator* ( void  ) const [inline]

For refering wrapped object.

Definition at line 139 of file Utils.h.

                             {
      return *(object->ptr);
    }
template<typename T>
T* Arc::CountedPointer< T >::operator-> ( void  ) const [inline]

For refering wrapped object.

Definition at line 143 of file Utils.h.

                              {
      return (object->ptr);
    }
template<typename T>
CountedPointer& Arc::CountedPointer< T >::operator= ( T p) [inline]

Definition at line 124 of file Utils.h.

                                    {
      if (p != object->ptr) {
        object->rem();
        object = new Base<T>(p);
      }
      return *this;
    }
template<typename T>
CountedPointer& Arc::CountedPointer< T >::operator= ( CountedPointer< T > &  p) [inline]

Definition at line 131 of file Utils.h.

                                                 {
      if (p.object->ptr != object->ptr) {
        object->rem();
        object = p.object->add();
      }
      return *this;
    }

Here is the call graph for this function:


Member Data Documentation

template<typename T>
Base<T>* Arc::CountedPointer< T >::object [private]

Definition at line 115 of file Utils.h.


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