[vlc-devel] commit: skins2: operator '=' return a reference. ( Rémi Duraffort )
git version control
git at videolan.org
Thu Mar 12 13:36:05 CET 2009
vlc | branch: master | Rémi Duraffort <ivoire at videolan.org> | Wed Mar 11 20:11:40 2009 +0100| [29591e86dce52698967ddf3bad5c37322ca4faad] | committer: Rémi Duraffort
skins2: operator '=' return a reference.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=29591e86dce52698967ddf3bad5c37322ca4faad
---
modules/gui/skins2/utils/ustring.cpp | 16 +++++++++++++---
modules/gui/skins2/utils/ustring.hpp | 4 ++--
2 files changed, 15 insertions(+), 5 deletions(-)
diff --git a/modules/gui/skins2/utils/ustring.cpp b/modules/gui/skins2/utils/ustring.cpp
index 483269f..76fb03c 100644
--- a/modules/gui/skins2/utils/ustring.cpp
+++ b/modules/gui/skins2/utils/ustring.cpp
@@ -199,8 +199,11 @@ bool UString::operator >=( const UString &rOther ) const
}
-void UString::operator =( const UString &rOther )
+UString& UString::operator =( const UString &rOther )
{
+ if( this == &rOther )
+ return *this;
+
m_length = rOther.m_length;
delete[] m_pString;
m_pString = new uint32_t[size() + 1];
@@ -208,15 +211,20 @@ void UString::operator =( const UString &rOther )
{
m_pString[i] = rOther.m_pString[i];
}
+
+ return *this;
}
-void UString::operator +=( const UString &rOther )
+UString& UString::operator +=( const UString &rOther )
{
+ if( this == &rOther )
+ return *this;
+
int tempLength = this->length() + rOther.length();
uint32_t *pTempString = new uint32_t[tempLength + 1];
// Copy the first string
- memcpy( pTempString, this->m_pString, 4 * this->size() );
+ memcpy( pTempString, this->m_pString, sizeof(uint32_t) * this->size() );
// Append the second string
// memcpy( pTempString + 4 * size(), rOther.m_pString,
// 4 * rOther.size() );
@@ -230,6 +238,8 @@ void UString::operator +=( const UString &rOther )
delete[] m_pString;
m_pString = pTempString;
m_length = tempLength;
+
+ return *this;
}
diff --git a/modules/gui/skins2/utils/ustring.hpp b/modules/gui/skins2/utils/ustring.hpp
index 598dc70..36ad952 100644
--- a/modules/gui/skins2/utils/ustring.hpp
+++ b/modules/gui/skins2/utils/ustring.hpp
@@ -58,9 +58,9 @@ class UString: public SkinObject
bool operator >( const UString &rOther ) const;
bool operator >=( const UString &rOther ) const;
/// Assignment
- void operator =( const UString &rOther );
+ UString& operator =( const UString &rOther );
/// Concatenation with assignment
- void operator +=( const UString &rOther );
+ UString& operator +=( const UString &rOther );
/// Concatenation
const UString operator +( const UString &rOther ) const;
const UString operator +( const char *pString ) const;
More information about the vlc-devel
mailing list