From aa615060e4c16375dd08d108ac5a430dfe9f8310 Mon Sep 17 00:00:00 2001 From: Dmitry Marakasov Date: Wed, 18 Sep 2013 03:04:47 +0400 Subject: [PATCH] Add getters and checks for nullness --- SDL2pp/Point.cc | 16 ++++++++++++++++ SDL2pp/Point.hh | 5 +++++ SDL2pp/Rect.cc | 36 ++++++++++++++++++++++++++++++++++++ SDL2pp/Rect.hh | 9 +++++++++ 4 files changed, 66 insertions(+) diff --git a/SDL2pp/Point.cc b/SDL2pp/Point.cc index 555d2ff..3084af7 100644 --- a/SDL2pp/Point.cc +++ b/SDL2pp/Point.cc @@ -19,6 +19,8 @@ 3. This notice may not be removed or altered from any source distribution. */ +#include + #include #include @@ -65,4 +67,18 @@ const SDL_Point* Point::Get() const { return point_.get(); } +bool Point::IsNull() const { + return point_ == nullptr; +} + +int Point::GetX() const { + assert(!IsNull()); + return point_->x; +} + +int Point::GetY() const { + assert(!IsNull()); + return point_->y; +} + } diff --git a/SDL2pp/Point.hh b/SDL2pp/Point.hh index a739514..8e38e70 100644 --- a/SDL2pp/Point.hh +++ b/SDL2pp/Point.hh @@ -54,6 +54,11 @@ public: SDL_Point* Get(); const SDL_Point* Get() const; + + bool IsNull() const; + + int GetX() const; + int GetY() const; }; } diff --git a/SDL2pp/Rect.cc b/SDL2pp/Rect.cc index dd7f1f0..ce201e2 100644 --- a/SDL2pp/Rect.cc +++ b/SDL2pp/Rect.cc @@ -19,6 +19,8 @@ 3. This notice may not be removed or altered from any source distribution. */ +#include + #include #include @@ -75,4 +77,38 @@ Rect Rect::FromCenter(int cx, int cy, int w, int h) { return Rect(cx - w/2, cy - h/2, cx + w - w/2, cy + h - h/2); } +bool Rect::IsNull() const { + return rect_ == nullptr; +} + +int Rect::GetX() const { + assert(!IsNull()); + return rect_->x; +} + +int Rect::GetY() const { + assert(!IsNull()); + return rect_->y; +} + +int Rect::GetW() const { + assert(!IsNull()); + return rect_->w; +} + +int Rect::GetH() const { + assert(!IsNull()); + return rect_->h; +} + +int Rect::GetX2() const { + assert(!IsNull()); + return rect_->x + rect_->w; +} + +int Rect::GetY2() const { + assert(!IsNull()); + return rect_->y + rect_->h; +} + } diff --git a/SDL2pp/Rect.hh b/SDL2pp/Rect.hh index cec9faf..152eb35 100644 --- a/SDL2pp/Rect.hh +++ b/SDL2pp/Rect.hh @@ -48,6 +48,15 @@ public: SDL_Rect* Get(); const SDL_Rect* Get() const; + + bool IsNull() const; + + int GetX() const; + int GetY() const; + int GetW() const; + int GetH() const; + int GetX2() const; + int GetY2() const; }; }