Stream operators for Point and BoundingBox classes (ticket #126)
authorPeter Kovacs <kpeter@inf.elte.hu>
Wed, 27 Aug 2008 10:50:04 +0200
changeset 250d0aae16df1bb
parent 249 f0b89f242745
child 253 dbe309b5e855
Stream operators for Point and BoundingBox classes (ticket #126)
- Add operator<< and operator>> for BoundingBox.
- operator<< of Point gives space-less output.
lemon/dim2.h
     1.1 --- a/lemon/dim2.h	Mon Aug 18 20:33:11 2008 +0200
     1.2 +++ b/lemon/dim2.h	Wed Aug 27 10:50:04 2008 +0200
     1.3 @@ -221,7 +221,7 @@
     1.4    template<typename T>
     1.5    inline std::ostream& operator<<(std::ostream &os, const Point<T>& z)
     1.6    {
     1.7 -    os << "(" << z.x << ", " << z.y << ")";
     1.8 +    os << "(" << z.x << "," << z.y << ")";
     1.9      return os;
    1.10    }
    1.11  
    1.12 @@ -533,6 +533,47 @@
    1.13      };//class Boundingbox
    1.14  
    1.15  
    1.16 +  ///Read a bounding box from a stream
    1.17 +
    1.18 +  ///Read a bounding box from a stream.
    1.19 +  ///\relates BoundingBox
    1.20 +  template<typename T>
    1.21 +  inline std::istream& operator>>(std::istream &is, BoundingBox<T>& b) {
    1.22 +    char c;
    1.23 +    Point<T> p;
    1.24 +    if (is >> c) {
    1.25 +      if (c != '(') is.putback(c);
    1.26 +    } else {
    1.27 +      is.clear();
    1.28 +    }
    1.29 +    if (!(is >> p)) return is;
    1.30 +    b.bottomLeft(p);
    1.31 +    if (is >> c) {
    1.32 +      if (c != ',') is.putback(c);
    1.33 +    } else {
    1.34 +      is.clear();
    1.35 +    }
    1.36 +    if (!(is >> p)) return is;
    1.37 +    b.topRight(p);
    1.38 +    if (is >> c) {
    1.39 +      if (c != ')') is.putback(c);
    1.40 +    } else {
    1.41 +      is.clear();
    1.42 +    }
    1.43 +    return is;
    1.44 +  }
    1.45 +
    1.46 +  ///Write a bounding box to a stream
    1.47 +
    1.48 +  ///Write a bounding box to a stream.
    1.49 +  ///\relates BoundingBox
    1.50 +  template<typename T>
    1.51 +  inline std::ostream& operator<<(std::ostream &os, const BoundingBox<T>& b)
    1.52 +  {
    1.53 +    os << "(" << b.bottomLeft() << "," << b.topRight() << ")";
    1.54 +    return os;
    1.55 +  }
    1.56 +
    1.57    ///Map of x-coordinates of a \ref Point "Point"-map
    1.58  
    1.59    ///\ingroup maps