Patch by Brecht Machiels: Add operator==() to BRegion. Thanks a lot!

Also fixed some coding style inconsistency.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29849 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus
2009-04-01 12:39:44 +00:00
parent bfc1a92f88
commit ac754ba0a2
2 changed files with 33 additions and 14 deletions
+2 -1
View File
@@ -31,7 +31,8 @@ class BRegion {
BRegion(const BRect rect); BRegion(const BRect rect);
virtual ~BRegion(); virtual ~BRegion();
BRegion &operator=(const BRegion &from); BRegion& operator=(const BRegion& from);
bool operator==(const BRegion& other) const;
void Set(BRect newBounds); void Set(BRect newBounds);
void Set(clipping_rect newBounds); void Set(clipping_rect newBounds);
+31 -13
View File
@@ -26,10 +26,11 @@ const static int32 kDataBlockSize = 8;
and its fBounds will be invalid. and its fBounds will be invalid.
*/ */
BRegion::BRegion() BRegion::BRegion()
: fCount(0) :
, fDataSize(0) fCount(0),
, fBounds((clipping_rect){ 0, 0, 0, 0 }) fDataSize(0),
, fData(NULL) fBounds((clipping_rect){ 0, 0, 0, 0 }),
fData(NULL)
{ {
_SetSize(kDataBlockSize); _SetSize(kDataBlockSize);
} }
@@ -39,10 +40,11 @@ BRegion::BRegion()
\param region The region to copy. \param region The region to copy.
*/ */
BRegion::BRegion(const BRegion& region) BRegion::BRegion(const BRegion& region)
: fCount(0) :
, fDataSize(0) fCount(0),
, fBounds((clipping_rect){ 0, 0, 0, 0 }) fDataSize(0),
, fData(NULL) fBounds((clipping_rect){ 0, 0, 0, 0 }),
fData(NULL)
{ {
*this = region; *this = region;
} }
@@ -52,10 +54,11 @@ BRegion::BRegion(const BRegion& region)
\param rect The BRect to set the region to. \param rect The BRect to set the region to.
*/ */
BRegion::BRegion(const BRect rect) BRegion::BRegion(const BRect rect)
: fCount(0) :
, fDataSize(1) fCount(0),
, fBounds((clipping_rect){ 0, 0, 0, 0 }) fDataSize(1),
, fData(&fBounds) fBounds((clipping_rect){ 0, 0, 0, 0 }),
fData(&fBounds)
{ {
if (!rect.IsValid()) if (!rect.IsValid())
return; return;
@@ -94,7 +97,7 @@ BRegion::~BRegion()
\param region the BRegion to copy. \param region the BRegion to copy.
\return This function always returns \c *this. \return This function always returns \c *this.
*/ */
BRegion & BRegion&
BRegion::operator=(const BRegion &region) BRegion::operator=(const BRegion &region)
{ {
if (&region == this) if (&region == this)
@@ -112,6 +115,21 @@ BRegion::operator=(const BRegion &region)
return *this; 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. /*! \brief Set the region to contain just the given BRect.
\param newBounds A BRect. \param newBounds A BRect.