From 40e8f71efa5c45f1ab0826e6bf92ddf676a57f88 Mon Sep 17 00:00:00 2001 From: Dmitry Marakasov Date: Mon, 19 Jan 2015 00:47:25 +0300 Subject: [PATCH] Make setters return reference to self: Point and Rect --- SDL2pp/Point.cc | 6 ++++-- SDL2pp/Point.hh | 8 ++++++-- SDL2pp/Rect.cc | 17 +++++++++++------ SDL2pp/Rect.hh | 24 ++++++++++++++++++------ 4 files changed, 39 insertions(+), 16 deletions(-) diff --git a/SDL2pp/Point.cc b/SDL2pp/Point.cc index 0e91b76..6f66298 100644 --- a/SDL2pp/Point.cc +++ b/SDL2pp/Point.cc @@ -50,16 +50,18 @@ int Point::GetX() const { return x; } -void Point::SetX(int nx) { +Point& Point::SetX(int nx) { x = nx; + return *this; } int Point::GetY() const { return y; } -void Point::SetY(int ny) { +Point& Point::SetY(int ny) { y = ny; + return *this; } Point Point::operator+(const Point& other) const { diff --git a/SDL2pp/Point.hh b/SDL2pp/Point.hh index 883c521..bf883be 100644 --- a/SDL2pp/Point.hh +++ b/SDL2pp/Point.hh @@ -129,8 +129,10 @@ public: /// /// \param[in] nx New X coordinate value /// + /// \returns Reference to self + /// //////////////////////////////////////////////////////////// - void SetX(int nx); + Point& SetX(int nx); //////////////////////////////////////////////////////////// /// \brief Get Y coordinate of the point @@ -145,8 +147,10 @@ public: /// /// \param[in] ny New Y coordinate value /// + /// \returns Reference to self + /// //////////////////////////////////////////////////////////// - void SetY(int ny); + Point& SetY(int ny); //////////////////////////////////////////////////////////// /// \brief Get point's memberwise addition with another point diff --git a/SDL2pp/Rect.cc b/SDL2pp/Rect.cc index 70529a8..89962f8 100644 --- a/SDL2pp/Rect.cc +++ b/SDL2pp/Rect.cc @@ -84,31 +84,34 @@ int Rect::GetX() const { return x; } -void Rect::SetX(int nx) { +Rect& Rect::SetX(int nx) { x = nx; + return *this; } int Rect::GetY() const { return y; } -void Rect::SetY(int ny) { +Rect& Rect::SetY(int ny) { y = ny; + return *this; } int Rect::GetW() const { return w; } -void Rect::SetW(int nw) { +Rect& Rect::SetW(int nw) { w = nw; + return *this; } int Rect::GetH() const { return h; } -void Rect::SetH(int nh) { +Rect& Rect::SetH(int nh) { h = nh; } @@ -116,16 +119,18 @@ int Rect::GetX2() const { return x + w - 1; } -void Rect::SetX2(int x2) { +Rect& Rect::SetX2(int x2) { w = x2 - x + 1; + return *this; } int Rect::GetY2() const { return y + h - 1; } -void Rect::SetY2(int y2) { +Rect& Rect::SetY2(int y2) { h = y2 - y + 1; + return *this; } bool Rect::Contains(int px, int py) const { diff --git a/SDL2pp/Rect.hh b/SDL2pp/Rect.hh index aaf272f..6cd7b71 100644 --- a/SDL2pp/Rect.hh +++ b/SDL2pp/Rect.hh @@ -186,8 +186,10 @@ public: /// /// \param[in] nx New X coordinate value /// + /// \returns Reference to self + /// //////////////////////////////////////////////////////////// - void SetX(int nx); + Rect& SetX(int nx); //////////////////////////////////////////////////////////// /// \brief Get Y coordinate of the rect corner @@ -202,8 +204,10 @@ public: /// /// \param[in] ny New Y coordinate value /// + /// \returns Reference to self + /// //////////////////////////////////////////////////////////// - void SetY(int ny); + Rect& SetY(int ny); //////////////////////////////////////////////////////////// /// \brief Get width of the rect @@ -218,8 +222,10 @@ public: /// /// \param[in] nw New width of the rect /// + /// \returns Reference to self + /// //////////////////////////////////////////////////////////// - void SetW(int nw); + Rect& SetW(int nw); //////////////////////////////////////////////////////////// /// \brief Get height of the rect @@ -234,8 +240,10 @@ public: /// /// \param[in] nh New height of the rect /// + /// \returns Reference to self + /// //////////////////////////////////////////////////////////// - void SetH(int nh); + Rect& SetH(int nh); //////////////////////////////////////////////////////////// /// \brief Get X coordinate of the rect second corner @@ -250,8 +258,10 @@ public: /// /// \param[in] x2 New X coordinate value /// + /// \returns Reference to self + /// //////////////////////////////////////////////////////////// - void SetX2(int x2); + Rect& SetX2(int x2); //////////////////////////////////////////////////////////// /// \brief Get Y coordinate of the rect second corner @@ -270,8 +280,10 @@ public: /// /// This modifies rectangle height internally /// + /// \returns Reference to self + /// //////////////////////////////////////////////////////////// - void SetY2(int y2); + Rect& SetY2(int y2); //////////////////////////////////////////////////////////// /// \brief Check whether the rect contains given point