+ Data(CharType *str, size_t len, Kind kind = Owned)
+ : wxPrivate::UntypedBufferData(str, len, kind)
+ {
+ }
+
+ CharType *Get() const { return static_cast<CharType *>(m_str); }
+ void Set(CharType *str, size_t len)
+ {
+ m_str = str;
+ m_length = len;
+ }
+ };
+
+ // placeholder for NULL string, to simplify this code
+ static Data *GetNullData()
+ {
+ return static_cast<Data *>(wxPrivate::untypedNullDataPtr);
+ }
+
+ void IncRef()
+ {
+ if ( m_data == GetNullData() ) // exception, not ref-counted
+ return;
+ m_data->m_ref++;
+ }
+
+ void DecRef()
+ {
+ if ( m_data == GetNullData() ) // exception, not ref-counted
+ return;
+ if ( --m_data->m_ref == 0 )
+ delete m_data;
+ m_data = GetNullData();
+ }
+
+ // sets this object to a be copy of 'other'; if 'src' is non-owned,
+ // a deep copy is made and 'this' will contain new instance of the data
+ void MakeOwnedCopyOf(const wxScopedCharTypeBuffer& src)
+ {
+ this->DecRef();
+
+ if ( src.m_data == this->GetNullData() )
+ {
+ this->m_data = this->GetNullData();
+ }
+ else if ( src.m_data->m_owned )
+ {
+ this->m_data = src.m_data;
+ this->IncRef();
+ }
+ else
+ {
+ // if the scoped buffer had non-owned data, we have to make
+ // a copy here, because src.m_data->m_str is valid only for as long
+ // as 'src' exists
+ this->m_data = new Data
+ (
+ StrCopy(src.data(), src.length()),
+ src.length()
+ );
+ }