From cc162d170bcaf7d5b3f47ffde346b1849f905662 Mon Sep 17 00:00:00 2001 From: Thorbjørn Lindeijer Date: Sun, 13 Mar 2011 00:52:27 +0100 Subject: For streaming things to cout better implement stream operator More convenient since it doesn't require calling any methods, and a bit faster. Also added stream operator for Rectangle. --- src/utils/point.h | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'src/utils') diff --git a/src/utils/point.h b/src/utils/point.h index 8436b8c..4402aa0 100644 --- a/src/utils/point.h +++ b/src/utils/point.h @@ -22,8 +22,7 @@ #define POINT_H #include -#include -#include +#include /** * A point in positive space. Usually represents pixel coordinates on a map. @@ -60,13 +59,6 @@ class Point { return (x != other.x || y != other.y); } - - std::string str() const - { - std::ostringstream ssPoint; - ssPoint << "(" << x << ", " << y << ")"; - return ssPoint.str(); - } }; /** @@ -96,4 +88,17 @@ class Rectangle } }; +inline std::ostream &operator <<(std::ostream &os, const Point &point) +{ + os << '(' << point.x << ", " << point.y << ')'; + return os; +} + +inline std::ostream &operator <<(std::ostream &os, const Rectangle &rect) +{ + os << '(' << rect.x << ',' << rect.y + << ' ' << rect.w << 'x' << rect.h << ')'; + return os; +} + #endif // POINT_H -- cgit