summaryrefslogtreecommitdiff
path: root/cpp/include/IceUtil/Handle.h
diff options
context:
space:
mode:
authorMarc Laukien <marc@zeroc.com>2002-09-22 15:57:38 +0000
committerMarc Laukien <marc@zeroc.com>2002-09-22 15:57:38 +0000
commitdff71be00b07d293b318fede3167b3c48f2270b8 (patch)
tree35e0236914020cd396dca7675119fb3c435693ac /cpp/include/IceUtil/Handle.h
parentthread fixes (diff)
downloadice-dff71be00b07d293b318fede3167b3c48f2270b8.tar.bz2
ice-dff71be00b07d293b318fede3167b3c48f2270b8.tar.xz
ice-dff71be00b07d293b318fede3167b3c48f2270b8.zip
dos2unix
Diffstat (limited to 'cpp/include/IceUtil/Handle.h')
-rw-r--r--cpp/include/IceUtil/Handle.h462
1 files changed, 231 insertions, 231 deletions
diff --git a/cpp/include/IceUtil/Handle.h b/cpp/include/IceUtil/Handle.h
index de901a65835..b9b625ac1bd 100644
--- a/cpp/include/IceUtil/Handle.h
+++ b/cpp/include/IceUtil/Handle.h
@@ -1,231 +1,231 @@
-// **********************************************************************
-//
-// Copyright (c) 2001
-// Mutable Realms, Inc.
-// Huntsville, AL, USA
-//
-// All Rights Reserved
-//
-// **********************************************************************
-
-#ifndef ICE_UTIL_HANDLE_H
-#define ICE_UTIL_HANDLE_H
-
-#include <IceUtil/Exception.h>
-#include <algorithm>
-
-//
-// "Handle" or "smart pointer" class for classes derived from
-// IceUtil::Shared or IceUtil::SimpleShared.
-//
-namespace IceUtil
-{
-
-template<typename T>
-class HandleBase
-{
-public:
-
- typedef T element_type;
-
- T* get() const
- {
- return _ptr;
- }
-
- T* operator->() const
- {
- if(!_ptr)
- {
- throw NullHandleException(__FILE__, __LINE__);
- }
-
- return _ptr;
- }
-
- operator bool() const
- {
- return _ptr ? true : false;
- }
-
- void swap(HandleBase& other)
- {
- std::swap(_ptr, other._ptr);
- }
-
- T* _ptr;
-};
-
-template<typename T, typename U>
-inline bool operator==(const HandleBase<T>& lhs, const HandleBase<U>& rhs)
-{
- T* l = lhs.get();
- U* r = rhs.get();
- if(l && r)
- {
- return *l == *r;
- }
- else
- {
- return !l && !r;
- }
-}
-
-template<typename T, typename U>
-inline bool operator!=(const HandleBase<T>& lhs, const HandleBase<U>& rhs)
-{
- T* l = lhs.get();
- U* r = rhs.get();
- if(l && r)
- {
- return *l != *r;
- }
- else
- {
- return l || r;
- }
-}
-
-template<typename T, typename U>
-inline bool operator<(const HandleBase<T>& lhs, const HandleBase<U>& rhs)
-{
- T* l = lhs.get();
- U* r = rhs.get();
- if(l && r)
- {
- return *l < *r;
- }
- else
- {
- return !l && r;
- }
-}
-
-template<typename T>
-class Handle : public HandleBase<T>
-{
-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 HandleBase<Y>& r)
- {
- return Handle(dynamic_cast<T*>(r._ptr));
- }
-
- template<class Y>
- static Handle dynamicCast(Y* p)
- {
- return Handle(dynamic_cast<T*>(p));
- }
-};
-
-}
-
-#endif
+// **********************************************************************
+//
+// Copyright (c) 2001
+// Mutable Realms, Inc.
+// Huntsville, AL, USA
+//
+// All Rights Reserved
+//
+// **********************************************************************
+
+#ifndef ICE_UTIL_HANDLE_H
+#define ICE_UTIL_HANDLE_H
+
+#include <IceUtil/Exception.h>
+#include <algorithm>
+
+//
+// "Handle" or "smart pointer" class for classes derived from
+// IceUtil::Shared or IceUtil::SimpleShared.
+//
+namespace IceUtil
+{
+
+template<typename T>
+class HandleBase
+{
+public:
+
+ typedef T element_type;
+
+ T* get() const
+ {
+ return _ptr;
+ }
+
+ T* operator->() const
+ {
+ if(!_ptr)
+ {
+ throw NullHandleException(__FILE__, __LINE__);
+ }
+
+ return _ptr;
+ }
+
+ operator bool() const
+ {
+ return _ptr ? true : false;
+ }
+
+ void swap(HandleBase& other)
+ {
+ std::swap(_ptr, other._ptr);
+ }
+
+ T* _ptr;
+};
+
+template<typename T, typename U>
+inline bool operator==(const HandleBase<T>& lhs, const HandleBase<U>& rhs)
+{
+ T* l = lhs.get();
+ U* r = rhs.get();
+ if(l && r)
+ {
+ return *l == *r;
+ }
+ else
+ {
+ return !l && !r;
+ }
+}
+
+template<typename T, typename U>
+inline bool operator!=(const HandleBase<T>& lhs, const HandleBase<U>& rhs)
+{
+ T* l = lhs.get();
+ U* r = rhs.get();
+ if(l && r)
+ {
+ return *l != *r;
+ }
+ else
+ {
+ return l || r;
+ }
+}
+
+template<typename T, typename U>
+inline bool operator<(const HandleBase<T>& lhs, const HandleBase<U>& rhs)
+{
+ T* l = lhs.get();
+ U* r = rhs.get();
+ if(l && r)
+ {
+ return *l < *r;
+ }
+ else
+ {
+ return !l && r;
+ }
+}
+
+template<typename T>
+class Handle : public HandleBase<T>
+{
+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 HandleBase<Y>& r)
+ {
+ return Handle(dynamic_cast<T*>(r._ptr));
+ }
+
+ template<class Y>
+ static Handle dynamicCast(Y* p)
+ {
+ return Handle(dynamic_cast<T*>(p));
+ }
+};
+
+}
+
+#endif