Main Page   Packages   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Search  

Handle Class Reference

#include <Handle.hpp>

List of all members.

Public Methods

 Handle ()
 Handle (JObject *obj)
 Handle (const Handle &right)
 Handle (JObject *obj, ULONG *rc, pthread_mutexattr_t *a, pthread_mutex_t *m)
virtual ~Handle ()
Handle & operator= (const Handle &right)
JObjectoperator-> () const
JObjectoperator * () const
 operator bool () const

Private Methods

__inline void addRef ()
void removeRef ()

Private Attributes

JObjectobject
ULONGrefCount
pthread_mutexattr_t * mutexAttr
pthread_mutex_t * mutex


Constructor & Destructor Documentation

Handle::Handle  
 

Definition at line 51 of file Handle.cpp.

00051                : object( NULL ), refCount(  NULL ),
00052                    mutex(  NULL ), mutexAttr( NULL ) { }

Handle::Handle JObject   obj
 

Definition at line 55 of file Handle.cpp.

00056   : object( obj )
00057 {
00058 
00059   if ( object != NULL ) {
00060     refCount  = new ULONG(1);
00061     mutexAttr = new pthread_mutexattr_t;
00062     mutex     = new pthread_mutex_t;
00063     pthread_mutexattr_init(mutexAttr);
00064     pthread_mutex_init(mutex, mutexAttr);
00065   } else {
00066     refCount  = NULL;
00067     mutexAttr = NULL;
00068     mutex     = NULL;
00069   }
00070 }

Handle::Handle const Handle &    right
 

Definition at line 72 of file Handle.cpp.

00073   : object( right.object ), refCount(  right.refCount  ),
00074     mutex(  right.mutex  ), mutexAttr( right.mutexAttr )
00075 {
00076   addRef();
00077 }

Handle::Handle JObject   obj,
ULONG   rc,
pthread_mutexattr_t *    a,
pthread_mutex_t *    m
 

Definition at line 79 of file Handle.cpp.

00081   : object( obj ), refCount( rc ), mutexAttr( a ), mutex( m )
00082 {
00083   addRef();
00084 }

Handle::~Handle   [virtual]
 

Definition at line 86 of file Handle.cpp.

00086                         {
00087   removeRef();
00088 }


Member Function Documentation

void Handle::addRef   [inline, private]
 

Definition at line 6 of file Handle.cpp.

Referenced by Handle(), and operator=().

00006                            {
00007   if ( object != NULL ) {
00008     pthread_mutex_lock(mutex);
00009     ++(*refCount);
00010     pthread_mutex_unlock(mutex);
00011   }
00012 }

JObject & Handle::operator *   const
 

Definition at line 110 of file Handle.cpp.

00110                                   {
00111   return *object;
00112 }

Handle::operator bool   const
 

JObject * Handle::operator->   const
 

Definition at line 105 of file Handle.cpp.

00105                                    {
00106   return object;
00107 }

Handle & Handle::operator= const Handle &    right
 

Definition at line 90 of file Handle.cpp.

00090                                                 {
00091   if (object != right.object) {
00092     removeRef();
00093     object    = right.object;
00094     mutexAttr = right.mutexAttr;
00095     mutex     = right.mutex;
00096     refCount  = right.refCount;
00097 
00098     addRef();
00099   }
00100 
00101   return *this;
00102 }

void Handle::removeRef   [private]
 

Definition at line 14 of file Handle.cpp.

Referenced by operator=(), and ~Handle().

00014                        {
00015   if ( object != NULL ) {
00016     pthread_mutex_lock(mutex);
00017 
00018     if ( --(*refCount) == 0 ) {
00019       pthread_mutex_unlock(mutex);
00020       pthread_mutex_destroy(mutex);
00021       pthread_mutexattr_destroy(mutexAttr);
00022 
00023       if ( mutex != NULL ) {
00024         delete mutex;
00025         mutex = NULL;
00026       }
00027 
00028       if ( mutexAttr != NULL ) {
00029         delete mutexAttr;
00030         mutexAttr = NULL;
00031       }
00032 
00033       if ( refCount != NULL ) {
00034         delete refCount;
00035         refCount = NULL;
00036       }
00037 
00038       if ( object != NULL ) {
00039         delete object;
00040         object = NULL;
00041       }
00042 
00043     } else {
00044       pthread_mutex_unlock(mutex);
00045     }
00046 
00047   }
00048 }


Member Data Documentation

pthread_mutex_t* Handle::mutex [private]
 

Definition at line 51 of file Handle.hpp.

Referenced by operator=().

pthread_mutexattr_t* Handle::mutexAttr [private]
 

Definition at line 50 of file Handle.hpp.

Referenced by operator=().

JObject* Handle::object [private]
 

Definition at line 48 of file Handle.hpp.

Referenced by operator=().

ULONG* Handle::refCount [private]
 

Definition at line 49 of file Handle.hpp.

Referenced by operator=().


The documentation for this class was generated from the following files:
Generated on Sun Oct 14 18:48:38 2001 for Standard J2K Library by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001