- if (wcs) {
-#if ( defined(__BORLANDC__) && (__BORLANDC__ > 0x530) ) \
- || ( defined(__MWERKS__) && defined(__WXMSW__) )
- size_t siz = (std::wcslen(wcs)+1)*sizeof(wchar_t);
+ return *this;
+ }
+
+ bool extend(size_t len)
+ {
+ wxASSERT_MSG( m_data->m_owned, _T("cannot extend non-owned buffer") );
+ wxASSERT_MSG( m_data->m_ref == 1, _T("can't extend shared buffer") );
+
+ CharType *str =
+ (CharType *)realloc(data(), (len + 1) * sizeof(CharType));
+ if ( !str )
+ return false;
+
+ if ( m_data == &NullData )
+ {
+ m_data = new Data(str);
+ }
+ else
+ {
+ m_data->m_str = str;
+ m_data->m_owned = true;
+ }
+
+ return true;
+ }
+
+ CharType *data() { return m_data->m_str; }
+ const CharType *data() const { return m_data->m_str; }
+ operator const CharType *() const { return data(); }
+ CharType operator[](size_t n) const { return data()[n]; }
+
+private:
+ // reference-counted data
+ struct Data
+ {
+ enum Kind
+ {
+ Owned,
+ NonOwned
+ };
+
+ Data(CharType *str, Kind kind = Owned)
+ : m_str(str), m_ref(1), m_owned(kind == Owned) {}
+
+ ~Data()
+ {
+ if ( m_owned )
+ free(m_str);
+ }
+
+ CharType *m_str;
+
+ // "short" to have sizeof(Data)=8 on 32bit archs
+ unsigned short m_ref;
+
+ bool m_owned;
+ };
+
+ // placeholder for NULL string, to simplify this code
+ // NB: this is defined in string.cpp, not (non-existent) buffer.cpp
+#ifdef __MINGW32__
+ // MinGW requires explicit WXDLLIMPEXP_DATA_BASE to avoid compilation
+ // errors
+ static WXDLLIMPEXP_DATA_BASE(Data) NullData;