| 1 | // ********************************************************************** | 
|---|
| 2 | // | 
|---|
| 3 | // Copyright (c) 2000 | 
|---|
| 4 | // Object Oriented Concepts, Inc. | 
|---|
| 5 | // Billerica, MA, USA | 
|---|
| 6 | // | 
|---|
| 7 | // All Rights Reserved | 
|---|
| 8 | // | 
|---|
| 9 | // ********************************************************************** | 
|---|
| 10 |  | 
|---|
| 11 | #ifndef JTC_HANDLE_I_H | 
|---|
| 12 | #define JTC_HANDLE_I_H | 
|---|
| 13 |  | 
|---|
| 14 | // ---------------------------------------------------------------------- | 
|---|
| 15 | // JTCHandleT constructors and destructor | 
|---|
| 16 | // ---------------------------------------------------------------------- | 
|---|
| 17 |  | 
|---|
| 18 | template <class T> | 
|---|
| 19 | JTCHandleT<T>::JTCHandleT(T* tg) | 
|---|
| 20 | : tg_(tg) | 
|---|
| 21 | { | 
|---|
| 22 | if(tg_ != 0) | 
|---|
| 23 | { | 
|---|
| 24 | tg_ -> refMutex_.lock(); | 
|---|
| 25 | ++tg_ -> _jtc_refCount_; // Boost reference count. | 
|---|
| 26 | tg_ -> refMutex_.unlock(); | 
|---|
| 27 | } | 
|---|
| 28 | } | 
|---|
| 29 |  | 
|---|
| 30 | template <class T> | 
|---|
| 31 | JTCHandleT<T>::~JTCHandleT() | 
|---|
| 32 | { | 
|---|
| 33 | bool deleteIt = false; | 
|---|
| 34 | { | 
|---|
| 35 | if(tg_ != 0) | 
|---|
| 36 | { | 
|---|
| 37 | tg_ -> refMutex_.lock(); | 
|---|
| 38 | if(--tg_ -> _jtc_refCount_ == 0) | 
|---|
| 39 | deleteIt = true; | 
|---|
| 40 | tg_ -> refMutex_.unlock(); | 
|---|
| 41 | } | 
|---|
| 42 | } | 
|---|
| 43 | if(deleteIt) | 
|---|
| 44 | delete tg_; | 
|---|
| 45 | } | 
|---|
| 46 |  | 
|---|
| 47 | // ---------------------------------------------------------------------- | 
|---|
| 48 | // JTCHandle public member implementation | 
|---|
| 49 | // ---------------------------------------------------------------------- | 
|---|
| 50 | template <class T> | 
|---|
| 51 | JTCHandleT<T>::JTCHandleT(const JTCHandleT<T>& rhs) | 
|---|
| 52 | : tg_(rhs.tg_) | 
|---|
| 53 | { | 
|---|
| 54 | if(tg_ != 0) | 
|---|
| 55 | { | 
|---|
| 56 | tg_ -> refMutex_.lock(); | 
|---|
| 57 | ++tg_ -> _jtc_refCount_; // Boost reference count. | 
|---|
| 58 | tg_ -> refMutex_.unlock(); | 
|---|
| 59 | } | 
|---|
| 60 | } | 
|---|
| 61 |  | 
|---|
| 62 |  | 
|---|
| 63 | template <class T> | 
|---|
| 64 | JTCHandleT<T>& | 
|---|
| 65 | JTCHandleT<T>::operator=(const JTCHandleT<T>& rhs) | 
|---|
| 66 | { | 
|---|
| 67 | bool deleteIt = false; | 
|---|
| 68 | { | 
|---|
| 69 | if(tg_ == rhs.tg_) | 
|---|
| 70 | return *this; | 
|---|
| 71 |  | 
|---|
| 72 | if(tg_ != 0) | 
|---|
| 73 | { | 
|---|
| 74 | tg_ -> refMutex_.lock(); | 
|---|
| 75 | if(--tg_ -> _jtc_refCount_ == 0) // Time to clean out object? | 
|---|
| 76 | deleteIt = true; | 
|---|
| 77 | tg_ -> refMutex_.unlock(); | 
|---|
| 78 | } | 
|---|
| 79 | } | 
|---|
| 80 | if(deleteIt) | 
|---|
| 81 | delete tg_; | 
|---|
| 82 |  | 
|---|
| 83 | tg_ = rhs.tg_; // Copy in RHS contents. | 
|---|
| 84 | if(tg_ != 0) | 
|---|
| 85 | { | 
|---|
| 86 | tg_ -> refMutex_.lock(); | 
|---|
| 87 | ++tg_ -> _jtc_refCount_; // Boost reference count. | 
|---|
| 88 | tg_ -> refMutex_.unlock(); | 
|---|
| 89 | } | 
|---|
| 90 |  | 
|---|
| 91 | return *this; | 
|---|
| 92 | } | 
|---|
| 93 |  | 
|---|
| 94 | template <class T> void | 
|---|
| 95 | JTCHandleT<T>::_jtc_deref() | 
|---|
| 96 | { | 
|---|
| 97 | if (tg_ != 0) | 
|---|
| 98 | { | 
|---|
| 99 | bool deleteIt = false; | 
|---|
| 100 | { | 
|---|
| 101 | tg_ -> refMutex_.lock(); | 
|---|
| 102 | if (--tg_ -> _jtc_refCount_ == 0) | 
|---|
| 103 | deleteIt = true; | 
|---|
| 104 | tg_ -> refMutex_.unlock(); | 
|---|
| 105 | } | 
|---|
| 106 | if(deleteIt) | 
|---|
| 107 | delete tg_; | 
|---|
| 108 | tg_ = 0; | 
|---|
| 109 | } | 
|---|
| 110 | } | 
|---|
| 111 |  | 
|---|
| 112 | #endif | 
|---|