Changeset 65130 in webkit for trunk/JavaScriptCore/API/JSRetainPtr.h
- Timestamp:
- Aug 11, 2010, 12:08:23 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/API/JSRetainPtr.h
r29663 r65130 1 1 /* 2 * Copyright (C) 2005, 2006, 2007 Apple Inc. All rights reserved.2 * Copyright (C) 2005, 2006, 2007, 2010 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 38 38 enum AdoptTag { Adopt }; 39 39 40 template 40 template<typename T> class JSRetainPtr { 41 41 public: 42 JSRetainPtr() : m_ptr(0) { }42 JSRetainPtr() : m_ptr(0) { } 43 43 JSRetainPtr(T ptr) : m_ptr(ptr) { if (ptr) JSRetain(ptr); } 44 45 44 JSRetainPtr(AdoptTag, T ptr) : m_ptr(ptr) { } 46 47 JSRetainPtr(const JSRetainPtr& o) : m_ptr(o.m_ptr) { if (T ptr = m_ptr) JSRetain(ptr); } 48 49 ~JSRetainPtr() { if (T ptr = m_ptr) JSRelease(ptr); } 50 51 template <typename U> JSRetainPtr(const JSRetainPtr<U>& o) : m_ptr(o.get()) { if (T ptr = m_ptr) JSRetain(ptr); } 45 JSRetainPtr(const JSRetainPtr&); 46 template<typename U> JSRetainPtr(const JSRetainPtr<U>&); 47 ~JSRetainPtr(); 52 48 53 49 T get() const { return m_ptr; } 54 50 55 T releaseRef() { T tmp = m_ptr; m_ptr = 0; return tmp; } 56 51 void clear(); 52 T leakRef(); 53 57 54 T operator->() const { return m_ptr; } 58 55 … … 64 61 65 62 JSRetainPtr& operator=(const JSRetainPtr&); 66 template 63 template<typename U> JSRetainPtr& operator=(const JSRetainPtr<U>&); 67 64 JSRetainPtr& operator=(T); 68 template 65 template<typename U> JSRetainPtr& operator=(U*); 69 66 70 67 void adopt(T); 71 68 72 69 void swap(JSRetainPtr&); 70 71 // FIXME: Remove releaseRef once we change all callers to call leakRef instead. 72 T releaseRef() { return leakRef(); } 73 73 74 74 private: … … 76 76 }; 77 77 78 template <typename T> inline JSRetainPtr<T>& JSRetainPtr<T>::operator=(const JSRetainPtr<T>& o) 78 template<typename T> inline JSRetainPtr<T>::JSRetainPtr(const JSRetainPtr& o) 79 : m_ptr(o.m_ptr) 80 { 81 if (m_ptr) 82 JSRetain(m_ptr); 83 } 84 85 template<typename T> template<typename U> inline JSRetainPtr<T>::JSRetainPtr(const JSRetainPtr<U>& o) 86 : m_ptr(o.get()) 87 { 88 if (m_ptr) 89 JSRetain(m_ptr); 90 } 91 92 template<typename T> inline JSRetainPtr<T>::~JSRetainPtr() 93 { 94 if (m_ptr) 95 JSRelease(m_ptr); 96 } 97 98 template<typename T> inline void JSRetainPtr<T>::clear() 99 { 100 if (T ptr = m_ptr) { 101 m_ptr = 0; 102 JSRelease(ptr); 103 } 104 } 105 106 template<typename T> inline T JSRetainPtr<T>::leakRef() 107 { 108 T ptr = m_ptr; 109 m_ptr = 0; 110 return ptr; 111 } 112 113 template<typename T> inline JSRetainPtr<T>& JSRetainPtr<T>::operator=(const JSRetainPtr<T>& o) 79 114 { 80 115 T optr = o.get(); … … 88 123 } 89 124 90 template <typename T> template<typename U> inline JSRetainPtr<T>& JSRetainPtr<T>::operator=(const JSRetainPtr<U>& o)125 template<typename T> template<typename U> inline JSRetainPtr<T>& JSRetainPtr<T>::operator=(const JSRetainPtr<U>& o) 91 126 { 92 127 T optr = o.get(); … … 100 135 } 101 136 102 template 103 { 104 if (optr) 105 JSRetain(optr); 106 T ptr = m_ptr; 107 m_ptr = optr; 108 if (ptr) 109 JSRelease(ptr); 110 return *this; 111 } 112 113 template 114 { 115 T ptr = m_ptr; 116 m_ptr = optr; 117 if (ptr) 118 JSRelease(ptr); 119 } 120 121 template <typename T> template<typename U> inline JSRetainPtr<T>& JSRetainPtr<T>::operator=(U* optr)122 { 123 if (optr) 124 JSRetain(optr); 125 T ptr = m_ptr; 126 m_ptr = optr; 127 if (ptr) 128 JSRelease(ptr); 129 return *this; 130 } 131 132 template <classT> inline void JSRetainPtr<T>::swap(JSRetainPtr<T>& o)137 template<typename T> inline JSRetainPtr<T>& JSRetainPtr<T>::operator=(T optr) 138 { 139 if (optr) 140 JSRetain(optr); 141 T ptr = m_ptr; 142 m_ptr = optr; 143 if (ptr) 144 JSRelease(ptr); 145 return *this; 146 } 147 148 template<typename T> inline void JSRetainPtr<T>::adopt(T optr) 149 { 150 T ptr = m_ptr; 151 m_ptr = optr; 152 if (ptr) 153 JSRelease(ptr); 154 } 155 156 template<typename T> template<typename U> inline JSRetainPtr<T>& JSRetainPtr<T>::operator=(U* optr) 157 { 158 if (optr) 159 JSRetain(optr); 160 T ptr = m_ptr; 161 m_ptr = optr; 162 if (ptr) 163 JSRelease(ptr); 164 return *this; 165 } 166 167 template<typename T> inline void JSRetainPtr<T>::swap(JSRetainPtr<T>& o) 133 168 { 134 169 std::swap(m_ptr, o.m_ptr); 135 170 } 136 171 137 template <classT> inline void swap(JSRetainPtr<T>& a, JSRetainPtr<T>& b)172 template<typename T> inline void swap(JSRetainPtr<T>& a, JSRetainPtr<T>& b) 138 173 { 139 174 a.swap(b); 140 175 } 141 176 142 template 177 template<typename T, typename U> inline bool operator==(const JSRetainPtr<T>& a, const JSRetainPtr<U>& b) 143 178 { 144 179 return a.get() == b.get(); 145 180 } 146 181 147 template 182 template<typename T, typename U> inline bool operator==(const JSRetainPtr<T>& a, U* b) 148 183 { 149 184 return a.get() == b; 150 185 } 151 186 152 template 187 template<typename T, typename U> inline bool operator==(T* a, const JSRetainPtr<U>& b) 153 188 { 154 189 return a == b.get(); 155 190 } 156 191 157 template 192 template<typename T, typename U> inline bool operator!=(const JSRetainPtr<T>& a, const JSRetainPtr<U>& b) 158 193 { 159 194 return a.get() != b.get(); 160 195 } 161 196 162 template 197 template<typename T, typename U> inline bool operator!=(const JSRetainPtr<T>& a, U* b) 163 198 { 164 199 return a.get() != b; 165 200 } 166 201 167 template 202 template<typename T, typename U> inline bool operator!=(T* a, const JSRetainPtr<U>& b) 168 203 { 169 204 return a != b.get();
Note:
See TracChangeset
for help on using the changeset viewer.