# HG changeset patch
# User Peter Kovacs <kpeter@inf.elte.hu>
# Date 1219827004 -7200
# Node ID d0aae16df1bb28a8cce519d53b1004399b71d9a7
# Parent f0b89f24274560f96db7740ebb807719f5e5e369
Stream operators for Point and BoundingBox classes (ticket #126)
- Add operator<< and operator>> for BoundingBox.
- operator<< of Point gives space-less output.
diff -r f0b89f242745 -r d0aae16df1bb lemon/dim2.h
|
a
|
b
|
|
| 221 | 221 | template<typename T> |
| 222 | 222 | inline std::ostream& operator<<(std::ostream &os, const Point<T>& z) |
| 223 | 223 | { |
| 224 | | os << "(" << z.x << ", " << z.y << ")"; |
| | 224 | os << "(" << z.x << "," << z.y << ")"; |
| 225 | 225 | return os; |
| 226 | 226 | } |
| 227 | 227 | |
| … |
… |
|
| 533 | 533 | };//class Boundingbox |
| 534 | 534 | |
| 535 | 535 | |
| | 536 | ///Read a bounding box from a stream |
| | 537 | |
| | 538 | ///Read a bounding box from a stream. |
| | 539 | ///\relates BoundingBox |
| | 540 | template<typename T> |
| | 541 | inline std::istream& operator>>(std::istream &is, BoundingBox<T>& b) { |
| | 542 | char c; |
| | 543 | Point<T> p; |
| | 544 | if (is >> c) { |
| | 545 | if (c != '(') is.putback(c); |
| | 546 | } else { |
| | 547 | is.clear(); |
| | 548 | } |
| | 549 | if (!(is >> p)) return is; |
| | 550 | b.bottomLeft(p); |
| | 551 | if (is >> c) { |
| | 552 | if (c != ',') is.putback(c); |
| | 553 | } else { |
| | 554 | is.clear(); |
| | 555 | } |
| | 556 | if (!(is >> p)) return is; |
| | 557 | b.topRight(p); |
| | 558 | if (is >> c) { |
| | 559 | if (c != ')') is.putback(c); |
| | 560 | } else { |
| | 561 | is.clear(); |
| | 562 | } |
| | 563 | return is; |
| | 564 | } |
| | 565 | |
| | 566 | ///Write a bounding box to a stream |
| | 567 | |
| | 568 | ///Write a bounding box to a stream. |
| | 569 | ///\relates BoundingBox |
| | 570 | template<typename T> |
| | 571 | inline std::ostream& operator<<(std::ostream &os, const BoundingBox<T>& b) |
| | 572 | { |
| | 573 | os << "(" << b.bottomLeft() << "," << b.topRight() << ")"; |
| | 574 | return os; |
| | 575 | } |
| | 576 | |
| 536 | 577 | ///Map of x-coordinates of a \ref Point "Point"-map |
| 537 | 578 | |
| 538 | 579 | ///\ingroup maps |