Changeset 11727 in webkit for trunk/JavaScriptCore/kxmlcore/RefPtr.h
- Timestamp:
- Dec 22, 2005, 8:48:08 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kxmlcore/RefPtr.h
r11684 r11727 26 26 namespace KXMLCore { 27 27 28 template < classT> class PassRefPtr;29 template < classT> class PassRefPtr_Ref;28 template <typename T> class PassRefPtr; 29 template <typename T> class PassRefPtr_Ref; 30 30 31 template < classT> class RefPtr31 template <typename T> class RefPtr 32 32 { 33 33 public: … … 35 35 RefPtr(T *ptr) : m_ptr(ptr) { if (ptr) ptr->ref(); } 36 36 RefPtr(const RefPtr& o) : m_ptr(o.m_ptr) { if (T *ptr = m_ptr) ptr->ref(); } 37 template <typename U> RefPtr(PassRefPtr<U>&); 38 template <typename U> RefPtr(PassRefPtr_Ref<U>); 37 39 38 40 ~RefPtr() { if (T *ptr = m_ptr) ptr->deref(); } 39 41 40 template < classU> RefPtr(const RefPtr<U>& o) : m_ptr(o.get()) { if (T *ptr = m_ptr) ptr->ref(); }42 template <typename U> RefPtr(const RefPtr<U>& o) : m_ptr(o.get()) { if (T *ptr = m_ptr) ptr->ref(); } 41 43 42 44 T *get() const { return m_ptr; } … … 55 57 RefPtr& operator=(PassRefPtr<T>&); 56 58 RefPtr& operator=(PassRefPtr_Ref<T>); 59 template <typename U> RefPtr& operator=(const RefPtr<U>&); 60 template <typename U> RefPtr& operator=(PassRefPtr<U>&); 61 template <typename U> RefPtr& operator=(PassRefPtr_Ref<U>); 57 62 58 63 private: … … 60 65 }; 61 66 62 template <class T> RefPtr<T>& RefPtr<T>::operator=(const RefPtr<T>& o) 67 template <typename T> template <typename U> inline RefPtr<T>::RefPtr(PassRefPtr_Ref<U> ref) 68 : m_ptr(ref.m_ptr) 69 { 70 } 71 72 template <typename T> template <typename U> inline RefPtr<T>::RefPtr(PassRefPtr<U>& o) 73 : m_ptr(o.release()) 74 { 75 } 76 77 template <typename T> RefPtr<T>& RefPtr<T>::operator=(const RefPtr<T>& o) 63 78 { 64 79 T *optr = o.m_ptr; 65 80 if (optr) 66 81 optr->ref(); 67 if ( T *ptr =m_ptr)68 ptr->deref();82 if (m_ptr) 83 m_ptr->deref(); 69 84 m_ptr = optr; 70 85 return *this; 71 86 } 72 87 73 template <class T> inline RefPtr<T>& RefPtr<T>::operator=(T *optr) 88 template <typename T> template <typename U> RefPtr<T>& RefPtr<T>::operator=(const RefPtr<U>& o) 89 { 90 T *optr = o.m_ptr; 91 if (optr) 92 optr->ref(); 93 if (m_ptr) 94 m_ptr->deref(); 95 m_ptr = optr; 96 return *this; 97 } 98 99 template <typename T> inline RefPtr<T>& RefPtr<T>::operator=(T* optr) 74 100 { 75 101 if (optr) 76 102 optr->ref(); 77 if ( T *ptr =m_ptr)78 ptr->deref();103 if (m_ptr) 104 m_ptr->deref(); 79 105 m_ptr = optr; 80 106 return *this; 81 107 } 82 108 83 template < class T> inline RefPtr<T>& RefPtr<T>::operator=(PassRefPtr_Ref<T> ref)109 template <typename T> template <typename U> inline RefPtr<T>& RefPtr<T>::operator=(PassRefPtr_Ref<U> ref) 84 110 { 85 111 if (m_ptr) … … 89 115 } 90 116 91 template < class T> inline RefPtr<T>& RefPtr<T>::operator=(PassRefPtr<T>& o)117 template <typename T> inline RefPtr<T>& RefPtr<T>::operator=(PassRefPtr<T>& o) 92 118 { 93 if ( T *ptr =m_ptr)94 ptr->deref();119 if (m_ptr) 120 m_ptr->deref(); 95 121 m_ptr = o.release(); 96 122 return *this; 97 123 } 98 124 99 template <class T> inline bool operator==(const RefPtr<T>& a, const RefPtr<T>& b) 125 template <typename T> inline RefPtr<T>& RefPtr<T>::operator=(PassRefPtr_Ref<T> ref) 126 { 127 if (m_ptr) 128 m_ptr->deref(); 129 m_ptr = ref.m_ptr; 130 return *this; 131 } 132 133 template <typename T> template <typename U> inline RefPtr<T>& RefPtr<T>::operator=(PassRefPtr<U>& o) 134 { 135 if (m_ptr) 136 m_ptr->deref(); 137 m_ptr = o.release(); 138 return *this; 139 } 140 141 template <typename T, typename U> inline bool operator==(const RefPtr<T>& a, const RefPtr<U>& b) 100 142 { 101 143 return a.get() == b.get(); 102 144 } 103 145 104 template < class T> inline bool operator==(const RefPtr<T>& a, const T *b)146 template <typename T, typename U> inline bool operator==(const RefPtr<T>& a, U* b) 105 147 { 106 148 return a.get() == b; 107 149 } 108 150 109 template < class T> inline bool operator==(const T *a, const RefPtr<T>& b)151 template <typename T, typename U> inline bool operator==(T* a, const RefPtr<U>& b) 110 152 { 111 153 return a == b.get(); 112 154 } 113 155 114 template < class T> inline bool operator!=(const RefPtr<T>& a, const RefPtr<T>& b)156 template <typename T, typename U> inline bool operator!=(const RefPtr<T>& a, const RefPtr<U>& b) 115 157 { 116 158 return a.get() != b.get(); 117 159 } 118 160 119 template < class T> inline bool operator!=(const RefPtr<T>& a, const T *b)161 template <typename T, typename U> inline bool operator!=(const RefPtr<T>& a, U* b) 120 162 { 121 163 return a.get() != b; 122 164 } 123 165 124 template < class T> inline bool operator!=(const T *a, const RefPtr<T>& b)166 template <typename T, typename U> inline bool operator!=(T* a, const RefPtr<U>& b) 125 167 { 126 168 return a != b.get(); 127 169 } 128 170 129 template < class T, class U> inline RefPtr<T> static_pointer_cast(const RefPtr<U>& p)171 template <typename T, typename U> inline RefPtr<T> static_pointer_cast(const RefPtr<U>& p) 130 172 { 131 173 return RefPtr<T>(static_cast<T *>(p.get())); 132 174 } 133 175 134 template < class T, class U> inline RefPtr<T> const_pointer_cast(const RefPtr<U>& p)176 template <typename T, typename U> inline RefPtr<T> const_pointer_cast(const RefPtr<U>& p) 135 177 { 136 178 return RefPtr<T>(const_cast<T *>(p.get()));
Note:
See TracChangeset
for help on using the changeset viewer.