Changeset 51086 in webkit
- Timestamp:
- Nov 17, 2009 12:38:41 PM (14 years ago)
- Location:
- trunk/JavaScriptCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/ChangeLog
r51068 r51086 1 2009-11-17 Martin Robinson <martin.james.robinson@gmail.com> 2 3 Reviewed by Adam Barth. 4 5 [GTK] Style cleanup for GOwnPtr 6 https://bugs.webkit.org/show_bug.cgi?id=31506 7 8 Remove forward declaration in GOwnPtr and do some style cleanup. 9 10 * wtf/GOwnPtr.cpp: 11 * wtf/GOwnPtr.h: 12 (WTF::GOwnPtr::GOwnPtr): 13 (WTF::GOwnPtr::~GOwnPtr): 14 (WTF::GOwnPtr::get): 15 (WTF::GOwnPtr::release): 16 (WTF::GOwnPtr::outPtr): 17 (WTF::GOwnPtr::set): 18 (WTF::GOwnPtr::clear): 19 (WTF::GOwnPtr::operator*): 20 (WTF::GOwnPtr::operator->): 21 (WTF::GOwnPtr::operator!): 22 (WTF::GOwnPtr::operator UnspecifiedBoolType): 23 (WTF::GOwnPtr::swap): 24 (WTF::swap): 25 (WTF::operator==): 26 (WTF::operator!=): 27 (WTF::getPtr): 28 (WTF::freeOwnedGPtr): 29 1 30 2009-11-17 Oliver Hunt <oliver@apple.com> 2 31 -
trunk/JavaScriptCore/wtf/GOwnPtr.cpp
r48383 r51086 19 19 #include "config.h" 20 20 #include "GOwnPtr.h" 21 22 #include <glib.h> 21 23 22 24 namespace WTF { -
trunk/JavaScriptCore/wtf/GOwnPtr.h
r48383 r51086 24 24 25 25 #include <algorithm> 26 #include <glib.h>27 26 #include <wtf/Assertions.h> 28 27 #include <wtf/Noncopyable.h> 29 28 29 // Forward delcarations at this point avoid the need to include GLib includes 30 // in WTF headers. 31 typedef struct _GError GError; 32 typedef struct _GList GList; 33 typedef struct _GCond GCond; 34 typedef struct _GMutex GMutex; 35 typedef struct _GPatternSpec GPatternSpec; 36 typedef struct _GDir GDir; 37 typedef struct _GHashTable GHashTable; 38 extern "C" void g_free(void*); 39 30 40 namespace WTF { 31 template <typename T> inline void freeOwnedGPtr(T* ptr) { g_free(reinterpret_cast<void*>(ptr)); }32 template<> void freeOwnedGPtr<GError>(GError*);33 template<> void freeOwnedGPtr<GList>(GList*);34 template<> void freeOwnedGPtr<GCond>(GCond*);35 template<> void freeOwnedGPtr<GMutex>(GMutex*);36 template<> void freeOwnedGPtr<GPatternSpec>(GPatternSpec*);37 template<> void freeOwnedGPtr<GDir>(GDir*);38 template<> void freeOwnedGPtr<GHashTable>(GHashTable*);39 41 40 template <typename T> class GOwnPtr : public Noncopyable { 41 public: 42 explicit GOwnPtr(T* ptr = 0) : m_ptr(ptr) { } 43 ~GOwnPtr() { freeOwnedGPtr(m_ptr); } 42 template <typename T> inline void freeOwnedGPtr(T* ptr); 43 template<> void freeOwnedGPtr<GError>(GError*); 44 template<> void freeOwnedGPtr<GList>(GList*); 45 template<> void freeOwnedGPtr<GCond>(GCond*); 46 template<> void freeOwnedGPtr<GMutex>(GMutex*); 47 template<> void freeOwnedGPtr<GPatternSpec>(GPatternSpec*); 48 template<> void freeOwnedGPtr<GDir>(GDir*); 49 template<> void freeOwnedGPtr<GHashTable>(GHashTable*); 44 50 45 T* get() const { return m_ptr; } 46 T* release() { T* ptr = m_ptr; m_ptr = 0; return ptr; } 47 T*& outPtr() { ASSERT(!m_ptr); return m_ptr; } 51 template <typename T> class GOwnPtr : public Noncopyable { 52 public: 53 explicit GOwnPtr(T* ptr = 0) : m_ptr(ptr) { } 54 ~GOwnPtr() { freeOwnedGPtr(m_ptr); } 48 55 49 void set(T* ptr) { ASSERT(!ptr || m_ptr != ptr); freeOwnedGPtr(m_ptr); m_ptr = ptr; } 50 void clear() { freeOwnedGPtr(m_ptr); m_ptr = 0; } 51 52 T& operator*() const { ASSERT(m_ptr); return *m_ptr; } 53 T* operator->() const { ASSERT(m_ptr); return m_ptr; } 54 55 bool operator!() const { return !m_ptr; } 56 57 // This conversion operator allows implicit conversion to bool but not to other integer types. 58 typedef T* GOwnPtr::*UnspecifiedBoolType; 59 operator UnspecifiedBoolType() const { return m_ptr ? &GOwnPtr::m_ptr : 0; } 60 61 void swap(GOwnPtr& o) { std::swap(m_ptr, o.m_ptr); } 62 63 private: 64 T* m_ptr; 65 }; 66 67 template <typename T> inline void swap(GOwnPtr<T>& a, GOwnPtr<T>& b) { a.swap(b); } 68 69 template <typename T, typename U> inline bool operator==(const GOwnPtr<T>& a, U* b) 70 { 71 return a.get() == b; 72 } 73 74 template <typename T, typename U> inline bool operator==(T* a, const GOwnPtr<U>& b) 56 T* get() const { return m_ptr; } 57 T* release() 75 58 { 76 return a == b.get(); 59 T* ptr = m_ptr; 60 m_ptr = 0; 61 return ptr; 77 62 } 78 63 79 template <typename T, typename U> inline bool operator!=(const GOwnPtr<T>& a, U* b)64 T*& outPtr() 80 65 { 81 return a.get() != b; 66 ASSERT(!m_ptr); 67 return m_ptr; 82 68 } 83 69 84 template <typename T, typename U> inline bool operator!=(T* a, const GOwnPtr<U>& b) 85 { 86 return a != b.get(); 70 void set(T* ptr) 71 { 72 ASSERT(!ptr || m_ptr != ptr); 73 freeOwnedGPtr(m_ptr); 74 m_ptr = ptr; 87 75 } 88 89 template <typename T> inline typename GOwnPtr<T>::PtrType getPtr(const GOwnPtr<T>& p)76 77 void clear() 90 78 { 91 return p.get(); 79 freeOwnedGPtr(m_ptr); 80 m_ptr = 0; 92 81 } 82 83 T& operator*() const 84 { 85 ASSERT(m_ptr); 86 return *m_ptr; 87 } 88 89 T* operator->() const 90 { 91 ASSERT(m_ptr); 92 return m_ptr; 93 } 94 95 bool operator!() const { return !m_ptr; } 96 97 // This conversion operator allows implicit conversion to bool but not to other integer types. 98 typedef T* GOwnPtr::*UnspecifiedBoolType; 99 operator UnspecifiedBoolType() const { return m_ptr ? &GOwnPtr::m_ptr : 0; } 100 101 void swap(GOwnPtr& o) { std::swap(m_ptr, o.m_ptr); } 102 103 private: 104 T* m_ptr; 105 }; 106 107 template <typename T> inline void swap(GOwnPtr<T>& a, GOwnPtr<T>& b) 108 { 109 a.swap(b); 110 } 111 112 template <typename T, typename U> inline bool operator==(const GOwnPtr<T>& a, U* b) 113 { 114 return a.get() == b; 115 } 116 117 template <typename T, typename U> inline bool operator==(T* a, const GOwnPtr<U>& b) 118 { 119 return a == b.get(); 120 } 121 122 template <typename T, typename U> inline bool operator!=(const GOwnPtr<T>& a, U* b) 123 { 124 return a.get() != b; 125 } 126 127 template <typename T, typename U> inline bool operator!=(T* a, const GOwnPtr<U>& b) 128 { 129 return a != b.get(); 130 } 131 132 template <typename T> inline typename GOwnPtr<T>::PtrType getPtr(const GOwnPtr<T>& p) 133 { 134 return p.get(); 135 } 136 137 template <typename T> inline void freeOwnedGPtr(T* ptr) 138 { 139 g_free(ptr); 140 } 93 141 94 142 } // namespace WTF
Note: See TracChangeset
for help on using the changeset viewer.