added wxObject::AllocExclusive() and associated methods
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@13937 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -382,18 +382,33 @@ public:
|
|||||||
virtual void Dump(wxSTD ostream& str);
|
virtual void Dump(wxSTD ostream& str);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// make a 'clone' of the object
|
// ref counted data handling methods
|
||||||
|
|
||||||
|
// get/set
|
||||||
|
wxObjectRefData *GetRefData() const { return m_refData; }
|
||||||
|
void SetRefData(wxObjectRefData *data) { m_refData = data; }
|
||||||
|
|
||||||
|
// make a 'clone' of the object
|
||||||
void Ref(const wxObject& clone);
|
void Ref(const wxObject& clone);
|
||||||
|
|
||||||
// destroy a reference
|
// destroy a reference
|
||||||
|
|
||||||
void UnRef();
|
void UnRef();
|
||||||
|
|
||||||
inline wxObjectRefData *GetRefData() const { return m_refData; }
|
|
||||||
inline void SetRefData(wxObjectRefData *data) { m_refData = data; }
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
// ensure that our data is not shared with anybody else: if we have no
|
||||||
|
// data, it is created using CreateRefData() below, if we have shared data
|
||||||
|
// it is copied using CloneRefData(), otherwise nothing is done
|
||||||
|
void AllocExclusive();
|
||||||
|
|
||||||
|
// both methods must be implemented if Unshare() is used, not pure virtual
|
||||||
|
// only because of the backwards compatibility reasons
|
||||||
|
|
||||||
|
// create a new m_refData
|
||||||
|
virtual wxObjectRefData *CreateRefData() const;
|
||||||
|
|
||||||
|
// create a new m_refData initialized with the given one
|
||||||
|
virtual wxObjectRefData *CloneRefData(wxObjectRefData *data) const;
|
||||||
|
|
||||||
wxObjectRefData *m_refData;
|
wxObjectRefData *m_refData;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -249,10 +249,44 @@ void wxObject::UnRef()
|
|||||||
|
|
||||||
if ( !--m_refData->m_count )
|
if ( !--m_refData->m_count )
|
||||||
delete m_refData;
|
delete m_refData;
|
||||||
m_refData = 0;
|
m_refData = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wxObject::AllocExclusive()
|
||||||
|
{
|
||||||
|
if ( !m_refData )
|
||||||
|
{
|
||||||
|
m_refData = CreateRefData();
|
||||||
|
}
|
||||||
|
else if ( m_refData->GetRefCount() > 1 )
|
||||||
|
{
|
||||||
|
// note that ref is not going to be destroyed in this case
|
||||||
|
wxObjectRefData* ref = m_refData;
|
||||||
|
UnRef();
|
||||||
|
|
||||||
|
// ... so we can still access it
|
||||||
|
m_refData = CloneRefData(ref);
|
||||||
|
}
|
||||||
|
//else: ref count is 1, we are exclusive owners of m_refData anyhow
|
||||||
|
|
||||||
|
wxASSERT_MSG( m_refData && m_refData->GetRefCount() == 1,
|
||||||
|
_T("wxObject::AllocExclusive() failed.") );
|
||||||
|
}
|
||||||
|
|
||||||
|
wxObjectRefData *wxObject::CreateRefData() const
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxObjectRefData *wxObject::CloneRefData(wxObjectRefData * WXUNUSED(data)) const
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// misc
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
#if defined(__DARWIN__) && defined(DYLIB_INIT)
|
#if defined(__DARWIN__) && defined(DYLIB_INIT)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user