Make CustomCommand safe copyable and moveable

This commit is contained in:
halx99 2020-08-19 11:42:32 +08:00
parent aa5fc9dc0f
commit 93b39601f9
2 changed files with 47 additions and 1 deletions

View File

@ -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);

View File

@ -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:
/**