diff --git a/headers/os/interface/Region.h b/headers/os/interface/Region.h index b5e729004d..a8ee4a3d63 100644 --- a/headers/os/interface/Region.h +++ b/headers/os/interface/Region.h @@ -29,13 +29,20 @@ public: BRegion(); BRegion(const BRegion& other); BRegion(const BRect rect); +#if defined(__cplusplus) && __cplusplus >= 201103L + BRegion(BRegion&& other); +#endif virtual ~BRegion(); BRegion& operator=(const BRegion& other); +#if defined(__cplusplus) && __cplusplus >= 201103L + BRegion& operator=(BRegion&& other); +#endif bool operator==(const BRegion& other) const; void Set(BRect rect); void Set(clipping_rect clipping); + void MoveFrom(BRegion& other); BRect Frame() const; clipping_rect FrameInt() const; diff --git a/src/kits/interface/Region.cpp b/src/kits/interface/Region.cpp index b05f3c6649..ee731e9357 100644 --- a/src/kits/interface/Region.cpp +++ b/src/kits/interface/Region.cpp @@ -59,6 +59,19 @@ BRegion::BRegion(const BRect rect) } +#if defined(__cplusplus) && __cplusplus >= 201103L +BRegion::BRegion(BRegion&& other) + : + fCount(0), + fDataSize(0), + fBounds((clipping_rect){ 0, 0, 0, 0 }), + fData(NULL) +{ + MoveFrom(other); +} +#endif + + // NOTE: private constructor BRegion::BRegion(const clipping_rect& clipping) : @@ -95,6 +108,17 @@ BRegion::operator=(const BRegion& other) } +#if defined(__cplusplus) && __cplusplus >= 201103L +BRegion& +BRegion::operator=(BRegion&& other) +{ + MoveFrom(other); + + return *this; +} +#endif + + bool BRegion::operator==(const BRegion& other) const { @@ -128,6 +152,30 @@ BRegion::Set(clipping_rect clipping) } +void +BRegion::MoveFrom(BRegion& other) +{ + if (other.CountRects() <= 0) { + MakeEmpty(); + return; + } + if (other.CountRects() == 1) { + Set(other.FrameInt()); + other.MakeEmpty(); + return; + } + fCount = other.fCount; + fDataSize = other.fDataSize; + fBounds = other.fBounds; + fData = other.fData; + + other.fCount = 0; + other.fDataSize = 0; + other.fBounds = (clipping_rect){ 0, 0, 0, 0 }; + other.fData = NULL; +} + + BRect BRegion::Frame() const {