]> git.saurik.com Git - wxWidgets.git/commitdiff
reuse wxObjectRefData for various ref-counted classes (closes #10886)
authorVadim Zeitlin <vadim@wxwidgets.org>
Fri, 12 Jun 2009 17:14:28 +0000 (17:14 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Fri, 12 Jun 2009 17:14:28 +0000 (17:14 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@61025 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/generic/grid.h
include/wx/object.h
include/wx/propgrid/property.h
include/wx/propgrid/propgridpagestate.h
include/wx/variant.h
src/common/variant.cpp
src/generic/grid.cpp
src/propgrid/property.cpp
src/propgrid/propgrid.cpp

index 11397b37de979a4f155f86c8f214ec864b2a0431..49e9248266a411f21fbaa29b38575ce808980b43 100644 (file)
@@ -110,16 +110,10 @@ class wxGridDirectionOperations;
 //     class is not documented and is not public at all
 // ----------------------------------------------------------------------------
 
-class WXDLLIMPEXP_ADV wxGridCellWorker : public wxClientDataContainer
+class WXDLLIMPEXP_ADV wxGridCellWorker : public wxClientDataContainer, public wxObjectRefData
 {
 public:
-    wxGridCellWorker() { m_nRef = 1; }
-
-    // this class is ref counted: it is created with ref count of 1, so
-    // calling DecRef() once will delete it. Calling IncRef() allows to lock
-    // it until the matching DecRef() is called
-    void IncRef() { m_nRef++; }
-    void DecRef() { if ( --m_nRef == 0 ) delete this; }
+    wxGridCellWorker() { }
 
     // interpret renderer parameters: arbitrary string whose interpretatin is
     // left to the derived classes
@@ -131,8 +125,6 @@ protected:
     virtual ~wxGridCellWorker();
 
 private:
-    size_t m_nRef;
-
     // suppress the stupid gcc warning about the class having private dtor and
     // no friends
     friend class wxGridCellWorkerDummyFriend;
@@ -297,7 +289,7 @@ protected:
 // class may be returned by wxGridTable::GetAttr().
 // ----------------------------------------------------------------------------
 
-class WXDLLIMPEXP_ADV wxGridCellAttr : public wxClientDataContainer
+class WXDLLIMPEXP_ADV wxGridCellAttr : public wxClientDataContainer, public wxObjectRefData
 {
 public:
     enum wxAttrKind
@@ -336,12 +328,6 @@ public:
     wxGridCellAttr *Clone() const;
     void MergeWith(wxGridCellAttr *mergefrom);
 
-    // this class is ref counted: it is created with ref count of 1, so
-    // calling DecRef() once will delete it. Calling IncRef() allows to lock
-    // it until the matching DecRef() is called
-    void IncRef() { m_nRef++; }
-    void DecRef() { if ( --m_nRef == 0 ) delete this; }
-
     // setters
     void SetTextColour(const wxColour& colText) { m_colText = colText; }
     void SetBackgroundColour(const wxColour& colBack) { m_colBack = colBack; }
@@ -419,9 +405,6 @@ private:
     void Init(wxGridCellAttr *attrDefault = NULL);
 
 
-    // the ref count - when it goes to 0, we die
-    size_t   m_nRef;
-
     wxColour m_colText,
              m_colBack;
     wxFont   m_font;
index 9da3222c8efd572c2260af4f8a390ae76aa80f46..8afcf85bf8cca1dc679d4591cbd4d07c17ce0021 100644 (file)
@@ -407,7 +407,7 @@ class WXDLLIMPEXP_BASE wxObjectRefData
     friend class WXDLLIMPEXP_FWD_BASE wxObject;
 
 public:
-    wxObjectRefData() : m_count(1) { }
+    wxObjectRefData(int refCount = 1) : m_count(refCount) { }
 
     int GetRefCount() const { return m_count; }
 
index 106d983896437aadb8ab9422128eff9ed466ec67..6e0e66683c383da9c6f3fdc6465eadd54160df9e 100644 (file)
@@ -64,12 +64,12 @@ struct wxPGPaintData
 
     Base class for wxPropertyGrid cell renderers.
 */
-class WXDLLIMPEXP_PROPGRID wxPGCellRenderer
+class WXDLLIMPEXP_PROPGRID wxPGCellRenderer : public wxObjectRefData
 {
 public:
 
-    wxPGCellRenderer( unsigned int refCount = 1 )
-        : m_refCount(refCount) { }
+    wxPGCellRenderer( int refCount = 1 )
+        : wxObjectRefData(refCount) { }
     virtual ~wxPGCellRenderer() { }
 
     // Render flags
@@ -145,22 +145,6 @@ public:
                      const wxRect& rect,
                      const wxPGCell& cell,
                      int flags ) const;
-
-    void IncRef()
-    {
-        m_refCount++;
-    }
-
-    void DecRef()
-    {
-        m_refCount--;
-        if ( !m_refCount )
-            delete this;
-    }
-protected:
-
-private:
-    unsigned int    m_refCount;
 };
 
 
@@ -697,7 +681,7 @@ protected:
 
 typedef void* wxPGChoicesId;
 
-class WXDLLIMPEXP_PROPGRID wxPGChoicesData
+class WXDLLIMPEXP_PROPGRID wxPGChoicesData : public wxObjectRefData
 {
     friend class wxPGChoices;
 public:
@@ -728,20 +712,9 @@ public:
         return m_items[i];
     }
 
-    void DecRef()
-    {
-        m_refCount--;
-        wxASSERT( m_refCount >= 0 );
-        if ( m_refCount == 0 )
-            delete this;
-    }
-
 private:
     wxVector<wxPGChoiceEntry>   m_items;
 
-    // So that multiple properties can use the same set
-    int             m_refCount;
-
     virtual ~wxPGChoicesData();
 };
 
@@ -785,7 +758,7 @@ public:
         if ( a.m_data != wxPGChoicesEmptyData )
         {
             m_data = a.m_data;
-            m_data->m_refCount++;
+            m_data->IncRef();
         }
     }
 
@@ -825,7 +798,7 @@ public:
     {
         wxASSERT(data);
         m_data = data;
-        data->m_refCount++;
+        data->IncRef();
     }
 
     /** Destructor. */
@@ -998,8 +971,8 @@ public:
     // Returns data, increases refcount.
     wxPGChoicesData* GetData()
     {
-        wxASSERT( m_data->m_refCount != 0xFFFFFFF );
-        m_data->m_refCount++;
+        wxASSERT( m_data->GetRefCount() != -1 );
+        m_data->IncRef();
         return m_data;
     }
 
index 5e58483f1f3ea3e513c8663c8258c003374dec28..c6d8cde900fbfef97ae9448d5448a4aad8e4c5f2 100644 (file)
@@ -314,28 +314,16 @@ protected:
 
 /** Base class to derive new viterators.
 */
-class WXDLLIMPEXP_PROPGRID wxPGVIteratorBase
+class WXDLLIMPEXP_PROPGRID wxPGVIteratorBase : public wxObjectRefData
 {
     friend class wxPGVIterator;
 public:
-    wxPGVIteratorBase() { m_refCount = 1; }
+    wxPGVIteratorBase() { }
     virtual void Next() = 0;
-    void IncRef()
-    {
-        m_refCount++;
-    }
-    void DecRef()
-    {
-        m_refCount--;
-        if ( m_refCount <= 0 )
-            delete this;
-    }
 protected:
     virtual ~wxPGVIteratorBase() { }
 
     wxPropertyGridIterator  m_it;
-private:
-    int     m_refCount;
 };
 
 /** @class wxPGVIterator
index 73e675eaeff1b9dddb3279854dc9ac247b01e0ca..d082a4f42b32e954eac3932fa617a26548fc566f 100644 (file)
  * overloading wxVariant with unnecessary functionality.
  */
 
-class WXDLLIMPEXP_BASE wxVariantData
+class WXDLLIMPEXP_BASE wxVariantData : public wxObjectRefData
 {
     friend class wxVariant;
 public:
-    wxVariantData() : m_count(1) { }
+    wxVariantData() { }
 
     // Override these to provide common functionality
     virtual bool Eq(wxVariantData& data) const = 0;
@@ -81,23 +81,11 @@ public:
     // a copy of the data.
     virtual wxVariantData* Clone() const { return NULL; }
 
-    void IncRef() { m_count++; }
-    void DecRef()
-    {
-        if ( --m_count == 0 )
-            delete this;
-    }
-
-    int GetRefCount() const { return m_count; }
-
 protected:
     // Protected dtor should make some incompatible code
     // break more louder. That is, they should do data->DecRef()
     // instead of delete data.
     virtual ~wxVariantData() { }
-
-private:
-    int     m_count;
 };
 
 /*
index 661a6190e51e4649657f97507198d3869629fcb1..bed7a03f60e34eb65a1896b469a99217191f6bc3 100644 (file)
@@ -163,7 +163,7 @@ void wxVariant::Ref(const wxVariant& clone)
     if ( clone.m_data )
     {
         m_data = clone.m_data;
-        m_data->m_count++;
+        m_data->IncRef();
     }
 }
 
@@ -172,7 +172,7 @@ void wxVariant::UnRef()
 {
     if ( m_data )
     {
-        wxASSERT_MSG( m_data->m_count > 0, _T("invalid ref data count") );
+        wxASSERT_MSG( m_data->GetRefCount() > 0, _T("invalid ref data count") );
 
         m_data->DecRef();
         m_data = NULL;
index 7b99052966399db1c43bf307e30dac955321d8ea..cc03db9a3f4c56f84c2e2fc031e4bbd4add21f0f 100644 (file)
@@ -197,8 +197,6 @@ wxGridCellWorker::~wxGridCellWorker()
 
 void wxGridCellAttr::Init(wxGridCellAttr *attrDefault)
 {
-    m_nRef = 1;
-
     m_isReadOnly = Unset;
 
     m_renderer = NULL;
index 8af53f28ab861d1bf94ef042f5bf141943879add..7f2f5a66ed7785b76ef4e74dd5b437c84af29d66 100644 (file)
@@ -2682,7 +2682,7 @@ void wxPGChoices::RemoveAt(size_t nIndex, size_t count)
 {
     AllocExclusive();
 
-    wxASSERT( m_data->m_refCount != 0xFFFFFFF );
+    wxASSERT( m_data->GetRefCount() != -1 );
     m_data->m_items.erase(m_data->m_items.begin()+nIndex,
                           m_data->m_items.begin()+nIndex+count);
 }
@@ -2798,7 +2798,7 @@ void wxPGChoices::AllocExclusive()
 {
     EnsureData();
 
-    if ( m_data->m_refCount != 1 )
+    if ( m_data->GetRefCount() != 1 )
     {
         wxPGChoicesData* data = new wxPGChoicesData();
         data->CopyDataFrom(m_data);
@@ -2816,7 +2816,7 @@ void wxPGChoices::AssignData( wxPGChoicesData* data )
     if ( data != wxPGChoicesEmptyData )
     {
         m_data = data;
-        data->m_refCount++;
+        data->IncRef();
     }
 }
 
index 83462b36a5f4f2fbea3ea53fa2b981c555ac3739..964afd9c9059587aa020c7236e0c1723404f1371 100644 (file)
@@ -5231,7 +5231,6 @@ wxPGChoiceEntry::wxPGChoiceEntry()
 
 wxPGChoicesData::wxPGChoicesData()
 {
-    m_refCount = 1;
 }
 
 wxPGChoicesData::~wxPGChoicesData()