mirror of
https://github.com/libSDL2pp/libSDL2pp.git
synced 2025-08-03 19:05:59 -04:00
Properly handle self-assignment
This commit is contained in:
parent
1e4e1cb560
commit
66f4d5b57a
@ -43,7 +43,9 @@ Point Point::Null() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Point::Point(const Point& other) {
|
Point::Point(const Point& other) {
|
||||||
if (other.point_.get()) {
|
if (!other.point_) {
|
||||||
|
point_.reset(nullptr);
|
||||||
|
} else if (point_ != other.point_) {
|
||||||
point_.reset(new SDL_Point);
|
point_.reset(new SDL_Point);
|
||||||
point_->x = other.point_->x;
|
point_->x = other.point_->x;
|
||||||
point_->y = other.point_->y;
|
point_->y = other.point_->y;
|
||||||
@ -53,7 +55,9 @@ Point::Point(const Point& other) {
|
|||||||
Point::Point(Point&&) noexcept = default;
|
Point::Point(Point&&) noexcept = default;
|
||||||
|
|
||||||
Point& Point::operator=(const Point& other) {
|
Point& Point::operator=(const Point& other) {
|
||||||
if (other.point_.get()) {
|
if (!other.point_) {
|
||||||
|
point_.reset(nullptr);
|
||||||
|
} else if (point_ != other.point_) {
|
||||||
point_.reset(new SDL_Point);
|
point_.reset(new SDL_Point);
|
||||||
point_->x = other.point_->x;
|
point_->x = other.point_->x;
|
||||||
point_->y = other.point_->y;
|
point_->y = other.point_->y;
|
||||||
|
@ -45,7 +45,9 @@ Rect Rect::Null() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Rect::Rect(const Rect& other) {
|
Rect::Rect(const Rect& other) {
|
||||||
if (other.rect_.get()) {
|
if (!other.rect_) {
|
||||||
|
rect_.reset(nullptr);
|
||||||
|
} else if (rect_ != other.rect_) {
|
||||||
rect_.reset(new SDL_Rect);
|
rect_.reset(new SDL_Rect);
|
||||||
rect_->x = other.rect_->x;
|
rect_->x = other.rect_->x;
|
||||||
rect_->y = other.rect_->y;
|
rect_->y = other.rect_->y;
|
||||||
@ -57,7 +59,9 @@ Rect::Rect(const Rect& other) {
|
|||||||
Rect::Rect(Rect&&) noexcept = default;
|
Rect::Rect(Rect&&) noexcept = default;
|
||||||
|
|
||||||
Rect& Rect::operator=(const Rect& other) {
|
Rect& Rect::operator=(const Rect& other) {
|
||||||
if (other.rect_.get()) {
|
if (!other.rect_) {
|
||||||
|
rect_.reset(nullptr);
|
||||||
|
} else if (rect_ != other.rect_) {
|
||||||
rect_.reset(new SDL_Rect);
|
rect_.reset(new SDL_Rect);
|
||||||
rect_->x = other.rect_->x;
|
rect_->x = other.rect_->x;
|
||||||
rect_->y = other.rect_->y;
|
rect_->y = other.rect_->y;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user