[Lemon-commits] Peter Kovacs: Stream operators for Point and Bou...
Lemon HG
hg at lemon.cs.elte.hu
Fri Aug 29 15:35:36 CEST 2008
details: http://lemon.cs.elte.hu/hg/lemon/rev/d0aae16df1bb
changeset: 250:d0aae16df1bb
user: Peter Kovacs <kpeter [at] inf.elte.hu>
date: Wed Aug 27 10:50:04 2008 +0200
description:
Stream operators for Point and BoundingBox classes (ticket #126)
- Add operator<< and operator>> for BoundingBox.
- operator<< of Point gives space-less output.
diffstat:
1 file changed, 42 insertions(+), 1 deletion(-)
lemon/dim2.h | 43 ++++++++++++++++++++++++++++++++++++++++++-
diffs (60 lines):
diff -r f0b89f242745 -r d0aae16df1bb lemon/dim2.h
--- a/lemon/dim2.h Mon Aug 18 20:33:11 2008 +0200
+++ b/lemon/dim2.h Wed Aug 27 10:50:04 2008 +0200
@@ -221,7 +221,7 @@
template<typename T>
inline std::ostream& operator<<(std::ostream &os, const Point<T>& z)
{
- os << "(" << z.x << ", " << z.y << ")";
+ os << "(" << z.x << "," << z.y << ")";
return os;
}
@@ -533,6 +533,47 @@
};//class Boundingbox
+ ///Read a bounding box from a stream
+
+ ///Read a bounding box from a stream.
+ ///\relates BoundingBox
+ template<typename T>
+ inline std::istream& operator>>(std::istream &is, BoundingBox<T>& b) {
+ char c;
+ Point<T> p;
+ if (is >> c) {
+ if (c != '(') is.putback(c);
+ } else {
+ is.clear();
+ }
+ if (!(is >> p)) return is;
+ b.bottomLeft(p);
+ if (is >> c) {
+ if (c != ',') is.putback(c);
+ } else {
+ is.clear();
+ }
+ if (!(is >> p)) return is;
+ b.topRight(p);
+ if (is >> c) {
+ if (c != ')') is.putback(c);
+ } else {
+ is.clear();
+ }
+ return is;
+ }
+
+ ///Write a bounding box to a stream
+
+ ///Write a bounding box to a stream.
+ ///\relates BoundingBox
+ template<typename T>
+ inline std::ostream& operator<<(std::ostream &os, const BoundingBox<T>& b)
+ {
+ os << "(" << b.bottomLeft() << "," << b.topRight() << ")";
+ return os;
+ }
+
///Map of x-coordinates of a \ref Point "Point"-map
///\ingroup maps
More information about the Lemon-commits
mailing list