source: webkit/trunk/JavaScriptCore/wtf/OwnPtr.h@ 37333

Last change on this file since 37333 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: 3.8 KB
Line 
1/*
2 * Copyright (C) 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_OwnPtr_h
22#define WTF_OwnPtr_h
23
24#include <algorithm>
25#include <wtf/Assertions.h>
26#include <wtf/Noncopyable.h>
27
28#if PLATFORM(WIN)
29
30typedef struct HBITMAP__* HBITMAP;
31typedef struct HBRUSH__* HBRUSH;
32typedef struct HFONT__* HFONT;
33typedef struct HPALETTE__* HPALETTE;
34typedef struct HPEN__* HPEN;
35typedef struct HRGN__* HRGN;
36
37#endif
38
39namespace WTF {
40
41 // Unlike most of our smart pointers, OwnPtr can take either the pointer type or the pointed-to type.
42
43 // FIXME: Share a single RemovePointer class template with RetainPtr.
44 template <typename T> struct OwnPtrRemovePointer { typedef T type; };
45 template <typename T> struct OwnPtrRemovePointer<T*> { typedef T type; };
46
47 template <typename T> inline void deleteOwnedPtr(T* ptr)
48 {
49 typedef char known[sizeof(T) ? 1 : -1];
50 if (sizeof(known))
51 delete ptr;
52 }
53
54#if PLATFORM(WIN)
55 void deleteOwnedPtr(HBITMAP);
56 void deleteOwnedPtr(HBRUSH);
57 void deleteOwnedPtr(HFONT);
58 void deleteOwnedPtr(HPALETTE);
59 void deleteOwnedPtr(HPEN);
60 void deleteOwnedPtr(HRGN);
61#endif
62
63 template <typename T> class OwnPtr : Noncopyable {
64 public:
65 typedef typename OwnPtrRemovePointer<T>::type ValueType;
66 typedef ValueType* PtrType;
67
68 explicit OwnPtr(PtrType ptr = 0) : m_ptr(ptr) { }
69 ~OwnPtr() { deleteOwnedPtr(m_ptr); }
70
71 PtrType get() const { return m_ptr; }
72 PtrType release() { PtrType ptr = m_ptr; m_ptr = 0; return ptr; }
73
74 void set(PtrType ptr) { ASSERT(!ptr || m_ptr != ptr); deleteOwnedPtr(m_ptr); m_ptr = ptr; }
75 void clear() { deleteOwnedPtr(m_ptr); m_ptr = 0; }
76
77 ValueType& operator*() const { ASSERT(m_ptr); return *m_ptr; }
78 PtrType operator->() const { ASSERT(m_ptr); return m_ptr; }
79
80 bool operator!() const { return !m_ptr; }
81
82 // This conversion operator allows implicit conversion to bool but not to other integer types.
83 typedef PtrType OwnPtr::*UnspecifiedBoolType;
84 operator UnspecifiedBoolType() const { return m_ptr ? &OwnPtr::m_ptr : 0; }
85
86 void swap(OwnPtr& o) { std::swap(m_ptr, o.m_ptr); }
87
88 private:
89 PtrType m_ptr;
90 };
91
92 template <typename T> inline void swap(OwnPtr<T>& a, OwnPtr<T>& b) { a.swap(b); }
93
94 template <typename T, typename U> inline bool operator==(const OwnPtr<T>& a, U* b)
95 {
96 return a.get() == b;
97 }
98
99 template <typename T, typename U> inline bool operator==(T* a, const OwnPtr<U>& b)
100 {
101 return a == b.get();
102 }
103
104 template <typename T, typename U> inline bool operator!=(const OwnPtr<T>& a, U* b)
105 {
106 return a.get() != b;
107 }
108
109 template <typename T, typename U> inline bool operator!=(T* a, const OwnPtr<U>& b)
110 {
111 return a != b.get();
112 }
113
114 template <typename T> inline typename OwnPtr<T>::PtrType getPtr(const OwnPtr<T>& p)
115 {
116 return p.get();
117 }
118
119} // namespace WTF
120
121using WTF::OwnPtr;
122
123#endif // WTF_OwnPtr_h
Note: See TracBrowser for help on using the repository browser.