reuse wxObjectRefData for various ref-counted classes (closes #10886)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@61025 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -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;
|
||||
|
@@ -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; }
|
||||
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
|
@@ -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
|
||||
|
@@ -55,11 +55,11 @@
|
||||
* 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;
|
||||
};
|
||||
|
||||
/*
|
||||
|
@@ -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;
|
||||
|
@@ -197,8 +197,6 @@ wxGridCellWorker::~wxGridCellWorker()
|
||||
|
||||
void wxGridCellAttr::Init(wxGridCellAttr *attrDefault)
|
||||
{
|
||||
m_nRef = 1;
|
||||
|
||||
m_isReadOnly = Unset;
|
||||
|
||||
m_renderer = NULL;
|
||||
|
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -5231,7 +5231,6 @@ wxPGChoiceEntry::wxPGChoiceEntry()
|
||||
|
||||
wxPGChoicesData::wxPGChoicesData()
|
||||
{
|
||||
m_refCount = 1;
|
||||
}
|
||||
|
||||
wxPGChoicesData::~wxPGChoicesData()
|
||||
|
Reference in New Issue
Block a user