diff options
Diffstat (limited to 'cpp/include/Ice/Handle.h')
-rw-r--r-- | cpp/include/Ice/Handle.h | 208 |
1 files changed, 7 insertions, 201 deletions
diff --git a/cpp/include/Ice/Handle.h b/cpp/include/Ice/Handle.h index d82a73848c6..c9da16af1c5 100644 --- a/cpp/include/Ice/Handle.h +++ b/cpp/include/Ice/Handle.h @@ -16,27 +16,14 @@ // // "Handle" or "smart pointer" classes for classes derived from -// Ice::Shared or Ice::SimpleShared. +// IceUtil::Shared or IceUtil::SimpleShared. // -// IceInternal::Handle -// =================== -// -// Generic handle class, using intrusive reference counting. Two -// global operations IceInternal::incRef(T*) and -// IceInternal::decRef(T*) must be declared for each T before using -// this template. The use of global operations allows this template to -// be used for types which are declared but not defined, provided that -// the two above mentioned operations are declared as well. -// -// Ice::Handle -// =========== -// -// A simplified handle class similar to IceInternal::Handle, but -// intended to be used by application code, and therfore in the Ice -// namespace instead of in IceInternal. No global operations -// incRef(T*) and decRef(T*) must be declared for this handle -// class. Instead, this handle class call __incRef() and __decRef() on -// T directly. +// In constrast to IceUtil::Handle, IceInternal::Handle requires the +// declaration of the two global operations IceInternal::incRef(T*) +// and IceInternal::decRef(T*). The use of global operations allows +// this template to be used for types which are declared but not +// defined, provided that the two above mentioned operations are +// declared. // namespace IceInternal @@ -220,185 +207,4 @@ inline bool operator>=(const Handle<T>& a, const Handle<U>& b) } -namespace Ice -{ - -template<typename T> -class Handle -{ -public: - - Handle(T* p = 0) : - _ptr(p) - { - if (_ptr) - { - _ptr->__incRef(); - } - } - - template<typename Y> - Handle(const Handle<Y>& r) : - _ptr(r._ptr) - { - if (_ptr) - { - _ptr->__incRef(); - } - } - -#ifdef WIN32 // COMPILERBUG: Is VC++ or GNU C++ right here??? - template<> - Handle(const Handle<T>& r) : -#else - Handle(const Handle& r) : -#endif - _ptr(r._ptr) - { - if (_ptr) - { - _ptr->__incRef(); - } - } - - ~Handle() - { - if (_ptr) - { - _ptr->__decRef(); - } - } - - Handle& operator=(T* p) - { - if (_ptr != p) - { - if (p) - { - p->__incRef(); - } - - if (_ptr) - { - _ptr->__decRef(); - } - - _ptr = p; - } - return *this; - } - - template<typename Y> - Handle& operator=(const Handle<Y>& r) - { - if (_ptr != r._ptr) - { - if (r._ptr) - { - r._ptr->__incRef(); - } - - if (_ptr) - { - _ptr->__decRef(); - } - - _ptr = r._ptr; - } - return *this; - } - -#ifdef WIN32 // COMPILERBUG: Is VC++ or GNU C++ right here??? - template<> - Handle& operator=(const Handle<T>& r) -#else - Handle& operator=(const Handle& r) -#endif - { - if (_ptr != r._ptr) - { - if (r._ptr) - { - r._ptr->__incRef(); - } - - if (_ptr) - { - _ptr->__decRef(); - } - - _ptr = r._ptr; - } - return *this; - } - - template<class Y> - static Handle dynamicCast(const Handle<Y>& r) - { - return Handle(dynamic_cast<T*>(r._ptr)); - } - - template<class Y> - static Handle dynamicCast(Y* p) - { - return Handle(dynamic_cast<T*>(p)); - } - - typedef T element_type; - - T* get() const { return _ptr; } - T* operator->() const { return _ptr; } - operator bool() const { return _ptr ? true : false; } - - void swap(Handle& other) { std::swap(_ptr, other._ptr); } - -#ifndef WIN32 // COMPILERBUG: VC++ 6.0 doesn't understand this - - template<typename Y> friend class Handle; - -protected: - -#endif - - T* _ptr; -}; - -template<typename T, typename U> -inline bool operator==(const Handle<T>& a, const Handle<U>& b) -{ - return *a.get() == *b.get(); -} - -template<typename T, typename U> -inline bool operator!=(const Handle<T>& a, const Handle<U>& b) -{ - return *a.get() != *b.get(); -} - -template<typename T, typename U> -inline bool operator<(const Handle<T>& a, const Handle<U>& b) -{ - return *a.get() < *b.get(); -} - -template<typename T, typename U> -inline bool operator<=(const Handle<T>& a, const Handle<U>& b) -{ - return *a.get() <= *b.get(); -} - -template<typename T, typename U> -inline bool operator>(const Handle<T>& a, const Handle<U>& b) -{ - return *a.get() > *b.get(); -} - -template<typename T, typename U> -inline bool operator>=(const Handle<T>& a, const Handle<U>& b) -{ - return *a.get() >= *b.get(); -} - -} - #endif |