// ----------------------------------------------------------------------------
template <typename T>
-class WXDLLIMPEXP_BASE wxCharTypeBuffer
+class wxCharTypeBuffer
{
public:
typedef T CharType;
if ( str )
m_data = new Data(wxStrdup(str));
else
- m_data = &NullData;
+ m_data = GetNullData();
}
wxCharTypeBuffer(size_t len)
DecRef();
}
- CharType *release()
+ // NB: this method is only const for backward compatibility. It used to
+ // be needed for auto_ptr-like semantics of the copy ctor, but now
+ // that ref-counting is used, it's not really needed.
+ CharType *release() const
{
- if ( m_data == &NullData )
+ if ( m_data == GetNullData() )
return NULL;
wxASSERT_MSG( m_data->m_owned, _T("can't release non-owned buffer") );
wxASSERT_MSG( m_data->m_ref == 1, _T("can't release shared buffer") );
CharType *p = m_data->m_str;
- m_data->m_str = NULL;
- DecRef();
+
+ wxCharTypeBuffer *self = wx_const_cast(wxCharTypeBuffer*, this);
+ self->m_data->m_str = NULL;
+ self->DecRef();
+
return p;
}
if ( !str )
return false;
- if ( m_data == &NullData )
+ if ( m_data == GetNullData() )
{
m_data = new Data(str);
}
};
// placeholder for NULL string, to simplify this code
- // NB: this is defined in string.cpp, not (non-existent) buffer.cpp
- static Data NullData;
+ static Data *GetNullData()
+ {
+ static Data s_nullData(NULL);
+
+ return &s_nullData;
+ }
void IncRef()
{
- if ( m_data == &NullData ) // exception, not ref-counted
+ if ( m_data == GetNullData() ) // exception, not ref-counted
return;
m_data->m_ref++;
}
void DecRef()
{
- if ( m_data == &NullData ) // exception, not ref-counted
+ if ( m_data == GetNullData() ) // exception, not ref-counted
return;
if ( --m_data->m_ref == 0 )
delete m_data;
- m_data = &NullData;
+ m_data = GetNullData();
}
private:
WXDLLIMPEXP_TEMPLATE_INSTANCE_BASE( wxCharTypeBuffer<char> )
-class WXDLLIMPEXP_BASE wxCharBuffer : public wxCharTypeBuffer<char>
+class wxCharBuffer : public wxCharTypeBuffer<char>
{
public:
typedef wxCharTypeBuffer<char> wxCharTypeBufferBase;
#if wxUSE_WCHAR_T
WXDLLIMPEXP_TEMPLATE_INSTANCE_BASE( wxCharTypeBuffer<wchar_t> )
-class WXDLLIMPEXP_BASE wxWCharBuffer : public wxCharTypeBuffer<wchar_t>
+class wxWCharBuffer : public wxCharTypeBuffer<wchar_t>
{
public:
typedef wxCharTypeBuffer<wchar_t> wxCharTypeBufferBase;
};
-class WXDLLIMPEXP_BASE wxMemoryBuffer
+class wxMemoryBuffer
{
public:
// ctor and dtor