OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009, 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2009, 2010 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
12 * | 12 * |
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY | 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 */ | 24 */ |
25 | 25 |
26 #ifndef WTF_PassOwnPtr_h | 26 #ifndef WTF_PassOwnPtr_h |
27 #define WTF_PassOwnPtr_h | 27 #define WTF_PassOwnPtr_h |
28 | 28 |
29 #include "wtf/Assertions.h" | 29 #include "wtf/Assertions.h" |
30 #include "wtf/NullPtr.h" | 30 #include "wtf/NullPtr.h" |
31 #include "wtf/OwnPtrCommon.h" | 31 #include "wtf/OwnPtrCommon.h" |
32 #include "wtf/TypeTraits.h" | 32 #include "wtf/TypeTraits.h" |
33 | 33 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 mutable PtrType m_ptr; | 86 mutable PtrType m_ptr; |
87 }; | 87 }; |
88 | 88 |
89 template<typename T> inline typename PassOwnPtr<T>::PtrType PassOwnPtr<T>::l
eakPtr() const | 89 template<typename T> inline typename PassOwnPtr<T>::PtrType PassOwnPtr<T>::l
eakPtr() const |
90 { | 90 { |
91 PtrType ptr = m_ptr; | 91 PtrType ptr = m_ptr; |
92 m_ptr = 0; | 92 m_ptr = 0; |
93 return ptr; | 93 return ptr; |
94 } | 94 } |
95 | 95 |
96 template<typename T, typename U> inline bool operator==(const PassOwnPtr<T>&
a, const PassOwnPtr<U>& b) | 96 template<typename T, typename U> inline bool operator==(const PassOwnPtr<T>&
a, const PassOwnPtr<U>& b) |
97 { | 97 { |
98 return a.get() == b.get(); | 98 return a.get() == b.get(); |
99 } | 99 } |
100 | 100 |
101 template<typename T, typename U> inline bool operator==(const PassOwnPtr<T>&
a, const OwnPtr<U>& b) | 101 template<typename T, typename U> inline bool operator==(const PassOwnPtr<T>&
a, const OwnPtr<U>& b) |
102 { | 102 { |
103 return a.get() == b.get(); | 103 return a.get() == b.get(); |
104 } | 104 } |
105 | 105 |
106 template<typename T, typename U> inline bool operator==(const OwnPtr<T>& a,
const PassOwnPtr<U>& b) | 106 template<typename T, typename U> inline bool operator==(const OwnPtr<T>& a,
const PassOwnPtr<U>& b) |
107 { | 107 { |
108 return a.get() == b.get(); | 108 return a.get() == b.get(); |
109 } | 109 } |
110 | 110 |
111 template<typename T, typename U> inline bool operator==(const PassOwnPtr<T>&
a, U* b) | 111 template<typename T, typename U> inline bool operator==(const PassOwnPtr<T>&
a, U* b) |
112 { | 112 { |
113 return a.get() == b; | 113 return a.get() == b; |
114 } | 114 } |
115 | 115 |
116 template<typename T, typename U> inline bool operator==(T* a, const PassOwnP
tr<U>& b) | 116 template<typename T, typename U> inline bool operator==(T* a, const PassOwnP
tr<U>& b) |
117 { | 117 { |
118 return a == b.get(); | 118 return a == b.get(); |
119 } | 119 } |
120 | 120 |
121 template<typename T, typename U> inline bool operator!=(const PassOwnPtr<T>&
a, const PassOwnPtr<U>& b) | 121 template<typename T, typename U> inline bool operator!=(const PassOwnPtr<T>&
a, const PassOwnPtr<U>& b) |
122 { | 122 { |
123 return a.get() != b.get(); | 123 return a.get() != b.get(); |
124 } | 124 } |
125 | 125 |
126 template<typename T, typename U> inline bool operator!=(const PassOwnPtr<T>&
a, const OwnPtr<U>& b) | 126 template<typename T, typename U> inline bool operator!=(const PassOwnPtr<T>&
a, const OwnPtr<U>& b) |
127 { | 127 { |
128 return a.get() != b.get(); | 128 return a.get() != b.get(); |
129 } | 129 } |
130 | 130 |
131 template<typename T, typename U> inline bool operator!=(const OwnPtr<T>& a,
const PassOwnPtr<U>& b) | 131 template<typename T, typename U> inline bool operator!=(const OwnPtr<T>& a,
const PassOwnPtr<U>& b) |
132 { | 132 { |
133 return a.get() != b.get(); | 133 return a.get() != b.get(); |
134 } | 134 } |
135 | 135 |
136 template<typename T, typename U> inline bool operator!=(const PassOwnPtr<T>&
a, U* b) | 136 template<typename T, typename U> inline bool operator!=(const PassOwnPtr<T>&
a, U* b) |
137 { | 137 { |
138 return a.get() != b; | 138 return a.get() != b; |
139 } | 139 } |
140 | 140 |
141 template<typename T, typename U> inline bool operator!=(T* a, const PassOwnP
tr<U>& b) | 141 template<typename T, typename U> inline bool operator!=(T* a, const PassOwnP
tr<U>& b) |
142 { | 142 { |
143 return a != b.get(); | 143 return a != b.get(); |
144 } | 144 } |
145 | 145 |
146 template<typename T> inline PassOwnPtr<T> adoptPtr(T* ptr) | 146 template<typename T> inline PassOwnPtr<T> adoptPtr(T* ptr) |
147 { | 147 { |
148 return PassOwnPtr<T>(ptr); | 148 return PassOwnPtr<T>(ptr); |
149 } | 149 } |
150 | 150 |
151 template<typename T, typename U> inline PassOwnPtr<T> static_pointer_cast(co
nst PassOwnPtr<U>& p) | 151 template<typename T, typename U> inline PassOwnPtr<T> static_pointer_cast(co
nst PassOwnPtr<U>& p) |
152 { | 152 { |
153 return adoptPtr(static_cast<T*>(p.leakPtr())); | 153 return adoptPtr(static_cast<T*>(p.leakPtr())); |
154 } | 154 } |
155 | 155 |
156 template<typename T, typename U> inline PassOwnPtr<T> const_pointer_cast(con
st PassOwnPtr<U>& p) | 156 template<typename T, typename U> inline PassOwnPtr<T> const_pointer_cast(con
st PassOwnPtr<U>& p) |
157 { | 157 { |
158 return adoptPtr(const_cast<T*>(p.leakPtr())); | 158 return adoptPtr(const_cast<T*>(p.leakPtr())); |
159 } | 159 } |
160 | 160 |
161 template<typename T> inline T* getPtr(const PassOwnPtr<T>& p) | 161 template<typename T> inline T* getPtr(const PassOwnPtr<T>& p) |
162 { | 162 { |
163 return p.get(); | 163 return p.get(); |
164 } | 164 } |
165 | 165 |
166 } // namespace WTF | 166 } // namespace WTF |
167 | 167 |
168 using WTF::PassOwnPtr; | 168 using WTF::PassOwnPtr; |
169 using WTF::adoptPtr; | 169 using WTF::adoptPtr; |
170 using WTF::const_pointer_cast; | 170 using WTF::const_pointer_cast; |
171 using WTF::static_pointer_cast; | 171 using WTF::static_pointer_cast; |
172 | 172 |
173 #endif // WTF_PassOwnPtr_h | 173 #endif // WTF_PassOwnPtr_h |
OLD | NEW |