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 * Copyright (C) 2013 Intel Corporation. All rights reserved. | 3 * Copyright (C) 2013 Intel Corporation. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 typedef PtrType PassOwnPtr::*UnspecifiedBoolType; | 66 typedef PtrType PassOwnPtr::*UnspecifiedBoolType; |
67 operator UnspecifiedBoolType() const { return m_ptr ? &PassOwnPtr::m_ptr
: 0; } | 67 operator UnspecifiedBoolType() const { return m_ptr ? &PassOwnPtr::m_ptr
: 0; } |
68 | 68 |
69 template<typename U> friend PassOwnPtr<U> adoptPtr(U*); | 69 template<typename U> friend PassOwnPtr<U> adoptPtr(U*); |
70 template<typename U> friend PassOwnPtr<U[]> adoptArrayPtr(U*); | 70 template<typename U> friend PassOwnPtr<U[]> adoptArrayPtr(U*); |
71 template<typename U> friend class OwnPtr; | 71 template<typename U> friend class OwnPtr; |
72 | 72 |
73 private: | 73 private: |
74 explicit PassOwnPtr(PtrType ptr) : m_ptr(ptr) { } | 74 explicit PassOwnPtr(PtrType ptr) : m_ptr(ptr) { } |
75 | 75 |
76 PassOwnPtr& operator=(const PassOwnPtr&) { COMPILE_ASSERT(!sizeof(T*), P
assOwnPtr_should_never_be_assigned_to); return *this; } | 76 PassOwnPtr& operator=(const PassOwnPtr&) { static_assert(!sizeof(T*), "P
assOwnPtr should never be assigned to"); return *this; } |
77 | 77 |
78 // We should never have two OwnPtrs for the same underlying object (othe
rwise we'll get | 78 // We should never have two OwnPtrs for the same underlying object (othe
rwise we'll get |
79 // double-destruction), so these equality operators should never be need
ed. | 79 // double-destruction), so these equality operators should never be need
ed. |
80 template<typename U> bool operator==(const PassOwnPtr<U>&) const { COMPI
LE_ASSERT(!sizeof(U*), OwnPtrs_should_never_be_equal); return false; } | 80 template<typename U> bool operator==(const PassOwnPtr<U>&) const { stati
c_assert(!sizeof(U*), "OwnPtrs should never be equal"); return false; } |
81 template<typename U> bool operator!=(const PassOwnPtr<U>&) const { COMPI
LE_ASSERT(!sizeof(U*), OwnPtrs_should_never_be_equal); return false; } | 81 template<typename U> bool operator!=(const PassOwnPtr<U>&) const { stati
c_assert(!sizeof(U*), "OwnPtrs should never be equal"); return false; } |
82 template<typename U> bool operator==(const OwnPtr<U>&) const { COMPILE_A
SSERT(!sizeof(U*), OwnPtrs_should_never_be_equal); return false; } | 82 template<typename U> bool operator==(const OwnPtr<U>&) const { static_as
sert(!sizeof(U*), "OwnPtrs should never be equal"); return false; } |
83 template<typename U> bool operator!=(const OwnPtr<U>&) const { COMPILE_A
SSERT(!sizeof(U*), OwnPtrs_should_never_be_equal); return false; } | 83 template<typename U> bool operator!=(const OwnPtr<U>&) const { static_as
sert(!sizeof(U*), "OwnPtrs should never be equal"); return false; } |
84 | 84 |
85 mutable PtrType m_ptr; | 85 mutable PtrType m_ptr; |
86 }; | 86 }; |
87 | 87 |
88 template<typename T> template<typename U> inline PassOwnPtr<T>::PassOwnPtr(c
onst PassOwnPtr<U>& o, EnsurePtrConvertibleArgDefn(U, T)) | 88 template<typename T> template<typename U> inline PassOwnPtr<T>::PassOwnPtr(c
onst PassOwnPtr<U>& o, EnsurePtrConvertibleArgDefn(U, T)) |
89 : m_ptr(o.leakPtr()) | 89 : m_ptr(o.leakPtr()) |
90 { | 90 { |
91 COMPILE_ASSERT(!IsArray<T>::value, Pointers_to_array_must_never_be_conve
rted); | 91 static_assert(!IsArray<T>::value, "pointers to array must never be conve
rted"); |
92 } | 92 } |
93 | 93 |
94 template<typename T> inline typename PassOwnPtr<T>::PtrType PassOwnPtr<T>::l
eakPtr() const | 94 template<typename T> inline typename PassOwnPtr<T>::PtrType PassOwnPtr<T>::l
eakPtr() const |
95 { | 95 { |
96 PtrType ptr = m_ptr; | 96 PtrType ptr = m_ptr; |
97 m_ptr = 0; | 97 m_ptr = 0; |
98 return ptr; | 98 return ptr; |
99 } | 99 } |
100 | 100 |
101 template<typename T, typename U> inline bool operator==(const PassOwnPtr<T>&
a, U* b) | 101 template<typename T, typename U> inline bool operator==(const PassOwnPtr<T>&
a, U* b) |
(...skipping 21 matching lines...) Expand all Loading... |
123 return PassOwnPtr<T>(ptr); | 123 return PassOwnPtr<T>(ptr); |
124 } | 124 } |
125 | 125 |
126 template<typename T> inline PassOwnPtr<T[]> adoptArrayPtr(T* ptr) | 126 template<typename T> inline PassOwnPtr<T[]> adoptArrayPtr(T* ptr) |
127 { | 127 { |
128 return PassOwnPtr<T[]>(ptr); | 128 return PassOwnPtr<T[]>(ptr); |
129 } | 129 } |
130 | 130 |
131 template<typename T, typename U> inline PassOwnPtr<T> static_pointer_cast(co
nst PassOwnPtr<U>& p) | 131 template<typename T, typename U> inline PassOwnPtr<T> static_pointer_cast(co
nst PassOwnPtr<U>& p) |
132 { | 132 { |
133 COMPILE_ASSERT(!IsArray<T>::value, Pointers_to_array_must_never_be_conve
rted); | 133 static_assert(!IsArray<T>::value, "pointers to array must never be conve
rted"); |
134 return adoptPtr(static_cast<T*>(p.leakPtr())); | 134 return adoptPtr(static_cast<T*>(p.leakPtr())); |
135 } | 135 } |
136 | 136 |
137 template<typename T> inline T* getPtr(const PassOwnPtr<T>& p) | 137 template<typename T> inline T* getPtr(const PassOwnPtr<T>& p) |
138 { | 138 { |
139 return p.get(); | 139 return p.get(); |
140 } | 140 } |
141 | 141 |
142 } // namespace WTF | 142 } // namespace WTF |
143 | 143 |
144 using WTF::PassOwnPtr; | 144 using WTF::PassOwnPtr; |
145 using WTF::adoptPtr; | 145 using WTF::adoptPtr; |
146 using WTF::adoptArrayPtr; | 146 using WTF::adoptArrayPtr; |
147 using WTF::static_pointer_cast; | 147 using WTF::static_pointer_cast; |
148 | 148 |
149 #endif // WTF_PassOwnPtr_h | 149 #endif // WTF_PassOwnPtr_h |
OLD | NEW |