diff --git a/SDL2pp/Point.cc b/SDL2pp/Point.cc index 312f92b..c41cf7e 100644 --- a/SDL2pp/Point.cc +++ b/SDL2pp/Point.cc @@ -149,3 +149,8 @@ Point& Point::Wrap(const Rect& rect) { } } + +std::ostream& operator<<(std::ostream& stream, const SDL2pp::Point& point) { + stream << "[x:" << point.x << ",y:" << point.y << "]"; + return stream; +} diff --git a/SDL2pp/Point.hh b/SDL2pp/Point.hh index 2149342..026dbc3 100644 --- a/SDL2pp/Point.hh +++ b/SDL2pp/Point.hh @@ -22,6 +22,8 @@ #ifndef SDL2PP_POINT_HH #define SDL2PP_POINT_HH +#include + #include namespace SDL2pp { @@ -277,4 +279,15 @@ public: } +//////////////////////////////////////////////////////////// +/// \brief Stream output operator overload for SDL2pp::Point +/// +/// \param[in] stream Stream to output to +/// \param[in] point Point to output +/// +/// \returns stream +/// +//////////////////////////////////////////////////////////// +std::ostream& operator<<(std::ostream& stream, const SDL2pp::Point& point); + #endif diff --git a/SDL2pp/Rect.cc b/SDL2pp/Rect.cc index 252dfad..21e570a 100644 --- a/SDL2pp/Rect.cc +++ b/SDL2pp/Rect.cc @@ -228,3 +228,8 @@ Rect& Rect::operator-=(const Point& offset) { } } + +std::ostream& operator<<(std::ostream& stream, const SDL2pp::Rect& rect) { + stream << "[x:" << rect.x << ",y:" << rect.y << ",w:" << rect.w << ",h:" << rect.h << "]"; + return stream; +} diff --git a/SDL2pp/Rect.hh b/SDL2pp/Rect.hh index b262488..074ac08 100644 --- a/SDL2pp/Rect.hh +++ b/SDL2pp/Rect.hh @@ -458,4 +458,15 @@ public: } +//////////////////////////////////////////////////////////// +/// \brief Stream output operator overload for SDL2pp::Rect +/// +/// \param[in] stream Stream to output to +/// \param[in] rect Rect to output +/// +/// \returns stream +/// +//////////////////////////////////////////////////////////// +std::ostream& operator<<(std::ostream& stream, const SDL2pp::Rect& rect); + #endif diff --git a/tests/test_pointrect.cc b/tests/test_pointrect.cc index 1d9fd6a..808457b 100644 --- a/tests/test_pointrect.cc +++ b/tests/test_pointrect.cc @@ -333,4 +333,10 @@ BEGIN_TEST() EXPECT_TRUE(Point(-19, -19).GetWrapped(rect) == Point(11, 21)); EXPECT_TRUE(Point(-21, -21).GetWrapped(rect) == Point(39, 59)); } + + { + // streams + EXPECT_EQUAL((std::stringstream() << Point(1, 2)).str(), "[x:1,y:2]"); + EXPECT_EQUAL((std::stringstream() << Rect(1, 2, 3, 4)).str(), "[x:1,y:2,w:3,h:4]"); + } END_TEST()