BWAPI
SPAR/AIModule/BWTA/vendors/CGAL/CGAL/IO/Istream_iterator.h
Go to the documentation of this file.
00001 // Copyright (c) 1997  Utrecht University (The Netherlands),
00002 // ETH Zurich (Switzerland), Freie Universitaet Berlin (Germany),
00003 // INRIA Sophia-Antipolis (France), Martin-Luther-University Halle-Wittenberg
00004 // (Germany), Max-Planck-Institute Saarbruecken (Germany), RISC Linz (Austria),
00005 // and Tel-Aviv University (Israel).  All rights reserved.
00006 //
00007 // This file is part of CGAL (www.cgal.org); you can redistribute it and/or
00008 // modify it under the terms of the GNU Lesser General Public License as
00009 // published by the Free Software Foundation; version 2.1 of the License.
00010 // See the file LICENSE.LGPL distributed with CGAL.
00011 //
00012 // Licensees holding a valid commercial license may use this file in
00013 // accordance with the commercial license agreement provided with the software.
00014 //
00015 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00016 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00017 //
00018 // $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.5-branch/Stream_support/include/CGAL/IO/Istream_iterator.h $
00019 // $Id: Istream_iterator.h 28567 2006-02-16 14:30:13Z lsaboret $
00020 // 
00021 //
00022 // Author(s)     : Lutz Kettner  <kettner@inf.ethz.ch>
00023 
00024 #ifndef CGAL_IO_ISTREAM_ITERATOR_H
00025 #define CGAL_IO_ISTREAM_ITERATOR_H
00026 
00027 #include <CGAL/circulator.h>
00028 
00029 CGAL_BEGIN_NAMESPACE
00030 
00031 template <class T, class Stream>
00032 class Istream_iterator {
00033 protected:
00034     Stream* stream;
00035     T value;
00036     void read() {
00037         if ( stream) {
00038             if ( *stream) {
00039                 *stream >> value;
00040                 if ( ! *stream)
00041                     stream = 0;
00042             } else
00043                 stream = 0;
00044         }
00045     }
00046 public:
00047     typedef  T                           value_type;
00048     typedef  const T&                    reference;
00049     typedef  const T&                    const_reference;
00050     typedef  const T*                    pointer;
00051     typedef  const T*                    const_pointer;
00052     typedef  std::size_t                 size_type;
00053     typedef  std::ptrdiff_t              difference_type;
00054     typedef  std::input_iterator_tag     iterator_category;
00055     typedef  Istream_iterator<T,Stream>  Self;
00056 
00057     Istream_iterator() : stream(0) {}
00058     Istream_iterator( Stream& s) : stream(&s) { read(); }
00059     bool      operator==( const Self& i) const {
00060                   return stream == i.stream;
00061     }
00062    bool      operator!=( const Self& i) const {
00063                   return stream != i.stream;
00064     }
00065 
00066     reference operator*()  const { return value; }
00067 #ifdef  CGAL_ARROW_OPERATOR
00068     pointer   operator->() const { return &(operator*()); }
00069 #endif
00070     Self&     operator++()      {
00071                   read();
00072                   return *this;
00073     }
00074     Self      operator++(int)   {
00075                   Self tmp = *this;
00076                   read();
00077                   return tmp;
00078     }
00079 };
00080 
00081 CGAL_END_NAMESPACE
00082 
00083 #endif // CGAL_IO_ISTREAM_ITERATOR_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines