source: webkit/trunk/JavaScriptCore/wtf/RefPtr.h@ 35900

Last change on this file since 35900 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, 2008 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_RefPtr_h
22#define WTF_RefPtr_h
23
24#include <algorithm>
25#include "AlwaysInline.h"
26
27namespace WTF {
28
29 enum PlacementNewAdoptType { PlacementNewAdopt };
30
31 template <typename T> class PassRefPtr;
32
33 enum HashTableDeletedValueType { HashTableDeletedValue };
34
35 template <typename T> class RefPtr {
36 public:
37 RefPtr() : m_ptr(0) { }
38 RefPtr(T* ptr) : m_ptr(ptr) { if (ptr) ptr->ref(); }
39 RefPtr(const RefPtr& o) : m_ptr(o.m_ptr) { if (T* ptr = m_ptr) ptr->ref(); }
40 // see comment in PassRefPtr.h for why this takes const reference
41 template <typename U> RefPtr(const PassRefPtr<U>&);
42
43 // Special constructor for cases where we overwrite an object in place.
44 RefPtr(PlacementNewAdoptType) { }
45
46 // Hash table deleted values, which are only constructed and never copied or destroyed.
47 RefPtr(HashTableDeletedValueType) : m_ptr(hashTableDeletedValue()) { }
48 bool isHashTableDeletedValue() const { return m_ptr == hashTableDeletedValue(); }
49
50 ~RefPtr() { if (T* ptr = m_ptr) ptr->deref(); }
51
52 template <typename U> RefPtr(const RefPtr<U>& o) : m_ptr(o.get()) { if (T* ptr = m_ptr) ptr->ref(); }
53
54 T* get() const { return m_ptr; }
55
56 void clear() { if (T* ptr = m_ptr) ptr->deref(); m_ptr = 0; }
57 PassRefPtr<T> release() { PassRefPtr<T> tmp = adoptRef(m_ptr); m_ptr = 0; return tmp; }
58
59 T& operator*() const { return *m_ptr; }
60 ALWAYS_INLINE T* operator->() const { return m_ptr; }
61
62 bool operator!() const { return !m_ptr; }
63
64 // This conversion operator allows implicit conversion to bool but not to other integer types.
65 typedef T* RefPtr::*UnspecifiedBoolType;
66 operator UnspecifiedBoolType() const { return m_ptr ? &RefPtr::m_ptr : 0; }
67
68 RefPtr& operator=(const RefPtr&);
69 RefPtr& operator=(T*);
70 RefPtr& operator=(const PassRefPtr<T>&);
71 template <typename U> RefPtr& operator=(const RefPtr<U>&);
72 template <typename U> RefPtr& operator=(const PassRefPtr<U>&);
73
74 void swap(RefPtr&);
75
76 private:
77 static T* hashTableDeletedValue() { return reinterpret_cast<T*>(-1); }
78
79 T* m_ptr;
80 };
81
82 template <typename T> template <typename U> inline RefPtr<T>::RefPtr(const PassRefPtr<U>& o)
83 : m_ptr(o.releaseRef())
84 {
85 }
86
87 template <typename T> inline RefPtr<T>& RefPtr<T>::operator=(const RefPtr<T>& o)
88 {
89 T* optr = o.get();
90 if (optr)
91 optr->ref();
92 T* ptr = m_ptr;
93 m_ptr = optr;
94 if (ptr)
95 ptr->deref();
96 return *this;
97 }
98
99 template <typename T> template <typename U> inline RefPtr<T>& RefPtr<T>::operator=(const RefPtr<U>& o)
100 {
101 T* optr = o.get();
102 if (optr)
103 optr->ref();
104 T* ptr = m_ptr;
105 m_ptr = optr;
106 if (ptr)
107 ptr->deref();
108 return *this;
109 }
110
111 template <typename T> inline RefPtr<T>& RefPtr<T>::operator=(T* optr)
112 {
113 if (optr)
114 optr->ref();
115 T* ptr = m_ptr;
116 m_ptr = optr;
117 if (ptr)
118 ptr->deref();
119 return *this;
120 }
121
122 template <typename T> inline RefPtr<T>& RefPtr<T>::operator=(const PassRefPtr<T>& o)
123 {
124 T* ptr = m_ptr;
125 m_ptr = o.releaseRef();
126 if (ptr)
127 ptr->deref();
128 return *this;
129 }
130
131 template <typename T> template <typename U> inline RefPtr<T>& RefPtr<T>::operator=(const PassRefPtr<U>& o)
132 {
133 T* ptr = m_ptr;
134 m_ptr = o.releaseRef();
135 if (ptr)
136 ptr->deref();
137 return *this;
138 }
139
140 template <class T> inline void RefPtr<T>::swap(RefPtr<T>& o)
141 {
142 std::swap(m_ptr, o.m_ptr);
143 }
144
145 template <class T> inline void swap(RefPtr<T>& a, RefPtr<T>& b)
146 {
147 a.swap(b);
148 }
149
150 template <typename T, typename U> inline bool operator==(const RefPtr<T>& a, const RefPtr<U>& b)
151 {
152 return a.get() == b.get();
153 }
154
155 template <typename T, typename U> inline bool operator==(const RefPtr<T>& a, U* b)
156 {
157 return a.get() == b;
158 }
159
160 template <typename T, typename U> inline bool operator==(T* a, const RefPtr<U>& b)
161 {
162 return a == b.get();
163 }
164
165 template <typename T, typename U> inline bool operator!=(const RefPtr<T>& a, const RefPtr<U>& b)
166 {
167 return a.get() != b.get();
168 }
169
170 template <typename T, typename U> inline bool operator!=(const RefPtr<T>& a, U* b)
171 {
172 return a.get() != b;
173 }
174
175 template <typename T, typename U> inline bool operator!=(T* a, const RefPtr<U>& b)
176 {
177 return a != b.get();
178 }
179
180 template <typename T, typename U> inline RefPtr<T> static_pointer_cast(const RefPtr<U>& p)
181 {
182 return RefPtr<T>(static_cast<T*>(p.get()));
183 }
184
185 template <typename T, typename U> inline RefPtr<T> const_pointer_cast(const RefPtr<U>& p)
186 {
187 return RefPtr<T>(const_cast<T*>(p.get()));
188 }
189
190 template <typename T> inline T* getPtr(const RefPtr<T>& p)
191 {
192 return p.get();
193 }
194
195} // namespace WTF
196
197using WTF::RefPtr;
198using WTF::static_pointer_cast;
199using WTF::const_pointer_cast;
200
201#endif // WTF_RefPtr_h
Note: See TracBrowser for help on using the repository browser.