source: webkit/trunk/JavaScriptCore/wtf/PassRefPtr.h@ 36124

Last change on this file since 36124 was 35900, checked in by [email protected], 17 years ago

2008-08-23 Cameron Zwarich <[email protected]>

Rubber-stamped by Mark Rowe.

Remove modelines.

JavaScriptCore:

  • API/APICast.h:
  • API/JSBase.cpp:
  • API/JSCallbackConstructor.cpp:
  • API/JSCallbackConstructor.h:
  • API/JSCallbackFunction.cpp:
  • API/JSCallbackFunction.h:
  • API/JSCallbackObject.cpp:
  • API/JSCallbackObject.h:
  • API/JSCallbackObjectFunctions.h:
  • API/JSClassRef.cpp:
  • API/JSContextRef.cpp:
  • API/JSObjectRef.cpp:
  • API/JSProfilerPrivate.cpp:
  • API/JSStringRef.cpp:
  • API/JSStringRefBSTR.cpp:
  • API/JSStringRefCF.cpp:
  • API/JSValueRef.cpp:
  • API/tests/JSNode.c:
  • API/tests/JSNode.h:
  • API/tests/JSNodeList.c:
  • API/tests/JSNodeList.h:
  • API/tests/Node.c:
  • API/tests/Node.h:
  • API/tests/NodeList.c:
  • API/tests/NodeList.h:
  • API/tests/minidom.c:
  • API/tests/minidom.js:
  • API/tests/testapi.c:
  • API/tests/testapi.js:
  • JavaScriptCore.pro:
  • kjs/FunctionConstructor.h:
  • kjs/FunctionPrototype.h:
  • kjs/JSArray.h:
  • kjs/JSString.h:
  • kjs/JSWrapperObject.cpp:
  • kjs/NumberConstructor.h:
  • kjs/NumberObject.h:
  • kjs/NumberPrototype.h:
  • kjs/lexer.h:
  • kjs/lookup.h:
  • wtf/Assertions.cpp:
  • wtf/Assertions.h:
  • wtf/HashCountedSet.h:
  • wtf/HashFunctions.h:
  • wtf/HashIterators.h:
  • wtf/HashMap.h:
  • wtf/HashSet.h:
  • wtf/HashTable.h:
  • wtf/HashTraits.h:
  • wtf/ListHashSet.h:
  • wtf/ListRefPtr.h:
  • wtf/Noncopyable.h:
  • wtf/OwnArrayPtr.h:
  • wtf/OwnPtr.h:
  • wtf/PassRefPtr.h:
  • wtf/Platform.h:
  • wtf/RefPtr.h:
  • wtf/RefPtrHashMap.h:
  • wtf/RetainPtr.h:
  • wtf/UnusedParam.h:
  • wtf/Vector.h:
  • wtf/VectorTraits.h:
  • wtf/unicode/Unicode.h:
  • wtf/unicode/icu/UnicodeIcu.h:

WebCore:

  • WebCore.pro:
  • bridge/testbindings.cpp:
  • dom/DocPtr.h:
  • loader/SubstituteData.h:
  • page/Chrome.cpp:
  • page/Chrome.h:
  • page/ChromeClient.h:
  • page/Frame.h:
  • page/FrameLoadRequest.h:
  • page/FrameTree.cpp:
  • page/FrameTree.h:
  • page/Page.h:
  • page/mac/ChromeMac.mm:
  • platform/network/HTTPHeaderMap.h:
  • platform/network/ResourceErrorBase.cpp:
  • platform/network/ResourceErrorBase.h:
  • platform/network/ResourceHandleInternal.h:
  • platform/network/ResourceRequestBase.cpp:
  • platform/network/ResourceRequestBase.h:
  • platform/network/ResourceResponseBase.cpp:
  • platform/network/ResourceResponseBase.h:
  • platform/network/cf/ResourceError.h:
  • platform/network/cf/ResourceRequest.h:
  • platform/network/cf/ResourceRequestCFNet.h:
  • platform/network/cf/ResourceResponse.h:
  • platform/network/cf/ResourceResponseCFNet.h:
  • platform/network/curl/ResourceError.h:
  • platform/network/curl/ResourceRequest.h:
  • platform/network/curl/ResourceResponse.h:
  • platform/network/mac/ResourceError.h:
  • platform/network/mac/ResourceErrorMac.mm:
  • platform/network/mac/ResourceRequest.h:
  • platform/network/mac/ResourceRequestMac.mm:
  • platform/network/mac/ResourceResponse.h:
  • platform/network/mac/ResourceResponseMac.mm:
  • platform/network/qt/ResourceError.h:
  • platform/network/qt/ResourceRequest.h:
  • platform/network/qt/ResourceResponse.h:
  • platform/network/soup/CookieJarSoup.cpp:
  • platform/network/soup/ResourceError.h:
  • platform/network/soup/ResourceRequest.h:
  • platform/network/soup/ResourceResponse.h:
  • Property svn:eol-style set to native
File size: 6.0 KB
Line 
1/*
2 * Copyright (C) 2005, 2006, 2007 Apple Inc. All rights reserved.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 *
19 */
20
21#ifndef WTF_PassRefPtr_h
22#define WTF_PassRefPtr_h
23
24#include "AlwaysInline.h"
25
26namespace WTF {
27
28 template<typename T> class RefPtr;
29 template<typename T> class PassRefPtr;
30 template <typename T> PassRefPtr<T> adoptRef(T*);
31
32 template<typename T> class PassRefPtr {
33 public:
34 PassRefPtr() : m_ptr(0) {}
35 PassRefPtr(T* ptr) : m_ptr(ptr) { if (ptr) ptr->ref(); }
36 // It somewhat breaks the type system to allow transfer of ownership out of
37 // a const PassRefPtr. However, it makes it much easier to work with PassRefPtr
38 // temporaries, and we don't really have a need to use real const PassRefPtrs
39 // anyway.
40 PassRefPtr(const PassRefPtr& o) : m_ptr(o.releaseRef()) {}
41 template <typename U> PassRefPtr(const PassRefPtr<U>& o) : m_ptr(o.releaseRef()) { }
42
43 ALWAYS_INLINE ~PassRefPtr() { if (T* ptr = m_ptr) ptr->deref(); }
44
45 template <class U>
46 PassRefPtr(const RefPtr<U>& o) : m_ptr(o.get()) { if (T* ptr = m_ptr) ptr->ref(); }
47
48 T* get() const { return m_ptr; }
49
50 void clear() { if (T* ptr = m_ptr) ptr->deref(); m_ptr = 0; }
51 T* releaseRef() const { T* tmp = m_ptr; m_ptr = 0; return tmp; }
52
53 T& operator*() const { return *m_ptr; }
54 T* operator->() const { return m_ptr; }
55
56 bool operator!() const { return !m_ptr; }
57
58 // This conversion operator allows implicit conversion to bool but not to other integer types.
59 typedef T* PassRefPtr::*UnspecifiedBoolType;
60 operator UnspecifiedBoolType() const { return m_ptr ? &PassRefPtr::m_ptr : 0; }
61
62 PassRefPtr& operator=(T*);
63 PassRefPtr& operator=(const PassRefPtr&);
64 template <typename U> PassRefPtr& operator=(const PassRefPtr<U>&);
65 template <typename U> PassRefPtr& operator=(const RefPtr<U>&);
66
67 friend PassRefPtr adoptRef<T>(T*);
68 private:
69 // adopting constructor
70 PassRefPtr(T* ptr, bool) : m_ptr(ptr) {}
71 mutable T* m_ptr;
72 };
73
74 template <typename T> template <typename U> inline PassRefPtr<T>& PassRefPtr<T>::operator=(const RefPtr<U>& o)
75 {
76 T* optr = o.get();
77 if (optr)
78 optr->ref();
79 T* ptr = m_ptr;
80 m_ptr = optr;
81 if (ptr)
82 ptr->deref();
83 return *this;
84 }
85
86 template <typename T> inline PassRefPtr<T>& PassRefPtr<T>::operator=(T* optr)
87 {
88 if (optr)
89 optr->ref();
90 T* ptr = m_ptr;
91 m_ptr = optr;
92 if (ptr)
93 ptr->deref();
94 return *this;
95 }
96
97 template <typename T> inline PassRefPtr<T>& PassRefPtr<T>::operator=(const PassRefPtr<T>& ref)
98 {
99 T* ptr = m_ptr;
100 m_ptr = ref.releaseRef();
101 if (ptr)
102 ptr->deref();
103 return *this;
104 }
105
106 template <typename T> template <typename U> inline PassRefPtr<T>& PassRefPtr<T>::operator=(const PassRefPtr<U>& ref)
107 {
108 T* ptr = m_ptr;
109 m_ptr = ref.releaseRef();
110 if (ptr)
111 ptr->deref();
112 return *this;
113 }
114
115 template <typename T, typename U> inline bool operator==(const PassRefPtr<T>& a, const PassRefPtr<U>& b)
116 {
117 return a.get() == b.get();
118 }
119
120 template <typename T, typename U> inline bool operator==(const PassRefPtr<T>& a, const RefPtr<U>& b)
121 {
122 return a.get() == b.get();
123 }
124
125 template <typename T, typename U> inline bool operator==(const RefPtr<T>& a, const PassRefPtr<U>& b)
126 {
127 return a.get() == b.get();
128 }
129
130 template <typename T, typename U> inline bool operator==(const PassRefPtr<T>& a, U* b)
131 {
132 return a.get() == b;
133 }
134
135 template <typename T, typename U> inline bool operator==(T* a, const PassRefPtr<U>& b)
136 {
137 return a == b.get();
138 }
139
140 template <typename T, typename U> inline bool operator!=(const PassRefPtr<T>& a, const PassRefPtr<U>& b)
141 {
142 return a.get() != b.get();
143 }
144
145 template <typename T, typename U> inline bool operator!=(const PassRefPtr<T>& a, const RefPtr<U>& b)
146 {
147 return a.get() != b.get();
148 }
149
150 template <typename T, typename U> inline bool operator!=(const RefPtr<T>& a, const PassRefPtr<U>& b)
151 {
152 return a.get() != b.get();
153 }
154
155 template <typename T, typename U> inline bool operator!=(const PassRefPtr<T>& a, U* b)
156 {
157 return a.get() != b;
158 }
159
160 template <typename T, typename U> inline bool operator!=(T* a, const PassRefPtr<U>& b)
161 {
162 return a != b.get();
163 }
164
165 template <typename T> inline PassRefPtr<T> adoptRef(T* p)
166 {
167 return PassRefPtr<T>(p, true);
168 }
169
170 template <typename T, typename U> inline PassRefPtr<T> static_pointer_cast(const PassRefPtr<U>& p)
171 {
172 return adoptRef(static_cast<T*>(p.releaseRef()));
173 }
174
175 template <typename T, typename U> inline PassRefPtr<T> const_pointer_cast(const PassRefPtr<U>& p)
176 {
177 return adoptRef(const_cast<T*>(p.releaseRef()));
178 }
179
180 template <typename T> inline T* getPtr(const PassRefPtr<T>& p)
181 {
182 return p.get();
183 }
184
185} // namespace WTF
186
187using WTF::PassRefPtr;
188using WTF::adoptRef;
189using WTF::static_pointer_cast;
190using WTF::const_pointer_cast;
191
192#endif // WTF_PassRefPtr_h
Note: See TracBrowser for help on using the repository browser.