Changeset 51086 in webkit


Ignore:
Timestamp:
Nov 17, 2009 12:38:41 PM (14 years ago)
Author:
eric@webkit.org
Message:

2009-11-17 Martin Robinson <martin.james.robinson@gmail.com>

Reviewed by Adam Barth.

[GTK] Style cleanup for GOwnPtr
https://bugs.webkit.org/show_bug.cgi?id=31506

Remove forward declaration in GOwnPtr and do some style cleanup.

  • wtf/GOwnPtr.cpp:
  • wtf/GOwnPtr.h: (WTF::GOwnPtr::GOwnPtr): (WTF::GOwnPtr::~GOwnPtr): (WTF::GOwnPtr::get): (WTF::GOwnPtr::release): (WTF::GOwnPtr::outPtr): (WTF::GOwnPtr::set): (WTF::GOwnPtr::clear): (WTF::GOwnPtr::operator*): (WTF::GOwnPtr::operator->): (WTF::GOwnPtr::operator!): (WTF::GOwnPtr::operator UnspecifiedBoolType): (WTF::GOwnPtr::swap): (WTF::swap): (WTF::operator==): (WTF::operator!=): (WTF::getPtr): (WTF::freeOwnedGPtr):
Location:
trunk/JavaScriptCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r51068 r51086  
     12009-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
    1302009-11-17  Oliver Hunt  <oliver@apple.com>
    231
  • trunk/JavaScriptCore/wtf/GOwnPtr.cpp

    r48383 r51086  
    1919#include "config.h"
    2020#include "GOwnPtr.h"
     21
     22#include <glib.h>
    2123
    2224namespace WTF {
  • trunk/JavaScriptCore/wtf/GOwnPtr.h

    r48383 r51086  
    2424
    2525#include <algorithm>
    26 #include <glib.h>
    2726#include <wtf/Assertions.h>
    2827#include <wtf/Noncopyable.h>
    2928
     29// Forward delcarations at this point avoid the need to include GLib includes
     30// in WTF headers.
     31typedef struct _GError GError;
     32typedef struct _GList GList;
     33typedef struct _GCond GCond;
     34typedef struct _GMutex GMutex;
     35typedef struct _GPatternSpec GPatternSpec;
     36typedef struct _GDir GDir;
     37typedef struct _GHashTable GHashTable;
     38extern "C" void g_free(void*);
     39
    3040namespace 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*);
    3941
    40     template <typename T> class GOwnPtr : public Noncopyable {
    41     public:
    42         explicit GOwnPtr(T* ptr = 0) : m_ptr(ptr) { }
    43         ~GOwnPtr() { freeOwnedGPtr(m_ptr); }
     42template <typename T> inline void freeOwnedGPtr(T* ptr);
     43template<> void freeOwnedGPtr<GError>(GError*);
     44template<> void freeOwnedGPtr<GList>(GList*);
     45template<> void freeOwnedGPtr<GCond>(GCond*);
     46template<> void freeOwnedGPtr<GMutex>(GMutex*);
     47template<> void freeOwnedGPtr<GPatternSpec>(GPatternSpec*);
     48template<> void freeOwnedGPtr<GDir>(GDir*);
     49template<> void freeOwnedGPtr<GHashTable>(GHashTable*);
    4450
    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; }
     51template <typename T> class GOwnPtr : public Noncopyable {
     52public:
     53    explicit GOwnPtr(T* ptr = 0) : m_ptr(ptr) { }
     54    ~GOwnPtr() { freeOwnedGPtr(m_ptr); }
    4855
    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()
    7558    {
    76         return a == b.get();
     59        T* ptr = m_ptr;
     60        m_ptr = 0;
     61        return ptr;
    7762    }
    7863
    79     template <typename T, typename U> inline bool operator!=(const GOwnPtr<T>& a, U* b)
     64    T*& outPtr()
    8065    {
    81         return a.get() != b;
     66        ASSERT(!m_ptr);
     67        return m_ptr;
    8268    }
    8369
    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;
    8775    }
    88    
    89     template <typename T> inline typename GOwnPtr<T>::PtrType getPtr(const GOwnPtr<T>& p)
     76
     77    void clear()
    9078    {
    91         return p.get();
     79        freeOwnedGPtr(m_ptr);
     80        m_ptr = 0;
    9281    }
     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
     103private:
     104    T* m_ptr;
     105};
     106
     107template <typename T> inline void swap(GOwnPtr<T>& a, GOwnPtr<T>& b)
     108{
     109    a.swap(b);
     110}
     111
     112template <typename T, typename U> inline bool operator==(const GOwnPtr<T>& a, U* b)
     113{
     114    return a.get() == b;
     115}
     116
     117template <typename T, typename U> inline bool operator==(T* a, const GOwnPtr<U>& b)
     118{
     119    return a == b.get();
     120}
     121
     122template <typename T, typename U> inline bool operator!=(const GOwnPtr<T>& a, U* b)
     123{
     124    return a.get() != b;
     125}
     126
     127template <typename T, typename U> inline bool operator!=(T* a, const GOwnPtr<U>& b)
     128{
     129    return a != b.get();
     130}
     131
     132template <typename T> inline typename GOwnPtr<T>::PtrType getPtr(const GOwnPtr<T>& p)
     133{
     134    return p.get();
     135}
     136
     137template <typename T> inline void freeOwnedGPtr(T* ptr)
     138{
     139    g_free(ptr);
     140}
    93141
    94142} // namespace WTF
Note: See TracChangeset for help on using the changeset viewer.