mirror of https://github.com/axmolengine/axmol.git
fixed self assignment error and provide move semantics to pushBack of Vector<T>
This commit is contained in:
parent
8de6cb1981
commit
80adda2ce8
|
@ -316,18 +316,22 @@ public:
|
|||
/** Copy assignment operator */
|
||||
Map<K, V>& operator= ( const Map<K, V>& other )
|
||||
{
|
||||
if (this != &other) {
|
||||
CCLOGINFO("In the copy assignment operator of Map!");
|
||||
clear();
|
||||
_data = other._data;
|
||||
addRefForAllObjects();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
/** Move assignment operator */
|
||||
Map<K, V>& operator= ( Map<K, V>&& other )
|
||||
{
|
||||
if (this != &other) {
|
||||
CCLOGINFO("In the move assignment operator of Map!");
|
||||
_data = std::move(other._data);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
|
@ -58,7 +58,9 @@ __String::~__String()
|
|||
|
||||
__String& __String::operator= (const __String& other)
|
||||
{
|
||||
if (this != &other) {
|
||||
_string = other._string;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
|
@ -178,6 +178,7 @@ Value::~Value()
|
|||
|
||||
Value& Value::operator= (const Value& other)
|
||||
{
|
||||
if (this != &other) {
|
||||
switch (other._type) {
|
||||
case Type::BYTE:
|
||||
_baseData.byteVal = other._baseData.byteVal;
|
||||
|
@ -216,11 +217,13 @@ Value& Value::operator= (const Value& other)
|
|||
break;
|
||||
}
|
||||
_type = other._type;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
Value& Value::operator= (Value&& other)
|
||||
{
|
||||
if (this != &other) {
|
||||
switch (other._type) {
|
||||
case Type::BYTE:
|
||||
_baseData.byteVal = other._baseData.byteVal;
|
||||
|
@ -261,6 +264,7 @@ Value& Value::operator= (Value&& other)
|
|||
other._mapData = nullptr;
|
||||
other._intKeyMapData = nullptr;
|
||||
other._type = Type::NONE;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
|
|
@ -107,18 +107,22 @@ public:
|
|||
/** Copy assignment operator */
|
||||
Vector<T>& operator=(const Vector<T>& other)
|
||||
{
|
||||
if (this != &other) {
|
||||
CCLOGINFO("In the copy assignment operator!");
|
||||
clear();
|
||||
_data = other._data;
|
||||
addRefForAllObjects();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
/** Move assignment operator */
|
||||
Vector<T>& operator=(Vector<T>&& other)
|
||||
{
|
||||
if (this != &other) {
|
||||
CCLOGINFO("In the move assignment operator!");
|
||||
_data = std::move(other._data);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -260,7 +264,14 @@ public:
|
|||
* which causes an automatic reallocation of the allocated storage space
|
||||
* if -and only if- the new vector size surpasses the current vector capacity.
|
||||
*/
|
||||
void pushBack(T object)
|
||||
void pushBack(const T& object)
|
||||
{
|
||||
CCASSERT(object != nullptr, "The object should not be nullptr");
|
||||
_data.push_back( object );
|
||||
object->retain();
|
||||
}
|
||||
|
||||
void pushBack(const T&& object)
|
||||
{
|
||||
CCASSERT(object != nullptr, "The object should not be nullptr");
|
||||
_data.push_back( object );
|
||||
|
|
Loading…
Reference in New Issue