diff --git a/headers/os/interface/Region.h b/headers/os/interface/Region.h index 9096260048..633c926eca 100644 --- a/headers/os/interface/Region.h +++ b/headers/os/interface/Region.h @@ -31,7 +31,8 @@ class BRegion { BRegion(const BRect rect); virtual ~BRegion(); - BRegion &operator=(const BRegion &from); + BRegion& operator=(const BRegion& from); + bool operator==(const BRegion& other) const; void Set(BRect newBounds); void Set(clipping_rect newBounds); diff --git a/src/kits/interface/Region.cpp b/src/kits/interface/Region.cpp index 737eb0a1cc..52f3f9f52e 100644 --- a/src/kits/interface/Region.cpp +++ b/src/kits/interface/Region.cpp @@ -26,10 +26,11 @@ const static int32 kDataBlockSize = 8; and its fBounds will be invalid. */ BRegion::BRegion() - : fCount(0) - , fDataSize(0) - , fBounds((clipping_rect){ 0, 0, 0, 0 }) - , fData(NULL) + : + fCount(0), + fDataSize(0), + fBounds((clipping_rect){ 0, 0, 0, 0 }), + fData(NULL) { _SetSize(kDataBlockSize); } @@ -39,10 +40,11 @@ BRegion::BRegion() \param region The region to copy. */ BRegion::BRegion(const BRegion& region) - : fCount(0) - , fDataSize(0) - , fBounds((clipping_rect){ 0, 0, 0, 0 }) - , fData(NULL) + : + fCount(0), + fDataSize(0), + fBounds((clipping_rect){ 0, 0, 0, 0 }), + fData(NULL) { *this = region; } @@ -52,10 +54,11 @@ BRegion::BRegion(const BRegion& region) \param rect The BRect to set the region to. */ BRegion::BRegion(const BRect rect) - : fCount(0) - , fDataSize(1) - , fBounds((clipping_rect){ 0, 0, 0, 0 }) - , fData(&fBounds) + : + fCount(0), + fDataSize(1), + fBounds((clipping_rect){ 0, 0, 0, 0 }), + fData(&fBounds) { if (!rect.IsValid()) return; @@ -94,7 +97,7 @@ BRegion::~BRegion() \param region the BRegion to copy. \return This function always returns \c *this. */ -BRegion & +BRegion& BRegion::operator=(const BRegion ®ion) { if (®ion == this) @@ -112,6 +115,21 @@ BRegion::operator=(const BRegion ®ion) return *this; } +/*! \brief Compares this region to another (by value). + \param other the BRegion to compare to. + \return \ctrue if the two regions are the same, \cfalse otherwise. +*/ +bool +BRegion::operator==(const BRegion& other) const +{ + if (&other == this) + return true; + + if (fCount != other.fCount) + return false; + + return memcmp(fData, other.fData, fCount * sizeof(clipping_rect)) == 0; +} /*! \brief Set the region to contain just the given BRect. \param newBounds A BRect.