Add getters and checks for nullness

This commit is contained in:
Dmitry Marakasov 2013-09-18 03:04:47 +04:00
parent 3011a62589
commit aa615060e4
4 changed files with 66 additions and 0 deletions

View File

@ -19,6 +19,8 @@
3. This notice may not be removed or altered from any source distribution.
*/
#include <cassert>
#include <SDL2/SDL_rect.h>
#include <SDL2pp/Point.hh>
@ -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;
}
}

View File

@ -54,6 +54,11 @@ public:
SDL_Point* Get();
const SDL_Point* Get() const;
bool IsNull() const;
int GetX() const;
int GetY() const;
};
}

View File

@ -19,6 +19,8 @@
3. This notice may not be removed or altered from any source distribution.
*/
#include <cassert>
#include <SDL2/SDL_rect.h>
#include <SDL2pp/Rect.hh>
@ -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;
}
}

View File

@ -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;
};
}