mirror of https://github.com/axmolengine/axmol.git
Make CustomCommand safe copyable and moveable
This commit is contained in:
parent
aa5fc9dc0f
commit
93b39601f9
|
@ -41,6 +41,44 @@ CustomCommand::~CustomCommand()
|
|||
CC_SAFE_RELEASE(_indexBuffer);
|
||||
}
|
||||
|
||||
CustomCommand::CustomCommand(const CustomCommand& rhs)
|
||||
{
|
||||
this->copyAssign(rhs);
|
||||
}
|
||||
|
||||
CustomCommand::CustomCommand(CustomCommand&& rhs)
|
||||
{
|
||||
this->moveAssign(std::move(rhs));
|
||||
}
|
||||
|
||||
CustomCommand& CustomCommand::operator=(const CustomCommand& rhs)
|
||||
{
|
||||
this->copyAssign(rhs);
|
||||
return *this;
|
||||
}
|
||||
CustomCommand& CustomCommand::operator=(CustomCommand&& rhs)
|
||||
{
|
||||
this->moveAssign(std::move(rhs));
|
||||
return *this;
|
||||
}
|
||||
|
||||
void CustomCommand::copyAssign(const CustomCommand& rhs)
|
||||
{
|
||||
if (this != &rhs) {
|
||||
memcpy(this, &rhs, sizeof(rhs));
|
||||
CC_SAFE_RETAIN(_vertexBuffer);
|
||||
CC_SAFE_RETAIN(_indexBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
void CustomCommand::moveAssign(CustomCommand&& rhs)
|
||||
{
|
||||
if (this != &rhs) {
|
||||
memcpy(this, &rhs, sizeof(rhs));
|
||||
rhs._vertexBuffer = rhs._indexBuffer = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void CustomCommand::init(float depth, const cocos2d::Mat4 &modelViewTransform, unsigned int flags)
|
||||
{
|
||||
RenderCommand::init(depth, modelViewTransform, flags);
|
||||
|
|
|
@ -68,9 +68,17 @@ public:
|
|||
|
||||
/**Constructor.*/
|
||||
CustomCommand();
|
||||
CustomCommand(const CustomCommand& rhs);
|
||||
CustomCommand(CustomCommand&& rhs);
|
||||
/**Destructor.*/
|
||||
~CustomCommand();
|
||||
|
||||
CustomCommand& operator=(const CustomCommand& rhs);
|
||||
CustomCommand& operator=(CustomCommand&& rhs);
|
||||
|
||||
protected:
|
||||
void copyAssign(const CustomCommand& rhs);
|
||||
void moveAssign(CustomCommand&& rhs);
|
||||
|
||||
public:
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue