mirror of
https://github.com/libSDL2pp/libSDL2pp.git
synced 2025-08-03 10:55:57 -04:00
Implement stream output operators for Point and Rect
This commit is contained in:
parent
fa7ba94957
commit
fdcbcddc1d
@ -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;
|
||||
}
|
||||
|
@ -22,6 +22,8 @@
|
||||
#ifndef SDL2PP_POINT_HH
|
||||
#define SDL2PP_POINT_HH
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <SDL2/SDL_rect.h>
|
||||
|
||||
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
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user