window.hxx

Go to the documentation of this file.
00001 // window.hxx: this file is part of the Vaucanson project.
00002 //
00003 // Vaucanson, a generic library for finite state machines.
00004 //
00005 // Copyright (C) 2001, 2002, 2003, 2004 The Vaucanson Group.
00006 //
00007 // This program is free software; you can redistribute it and/or
00008 // modify it under the terms of the GNU General Public License
00009 // as published by the Free Software Foundation; either version 2
00010 // of the License, or (at your option) any later version.
00011 //
00012 // The complete GNU General Public Licence Notice can be found as the
00013 // `COPYING' file in the root directory.
00014 //
00015 // The Vaucanson Group consists of people listed in the `AUTHORS' file.
00016 //
00017 #ifndef VCSN_MISC_WINDOW_HXX
00018 # define VCSN_MISC_WINDOW_HXX
00019 
00028 # include <vaucanson/misc/window.hh>
00029 # include <vaucanson/misc/contract.hh>
00030 
00031 namespace utility {
00032 
00035   template <class InputIterator, class Letter>
00036   Window<InputIterator, Letter>::Window(const iterator_t& stream,
00037                                         const iterator_t& eof,
00038                                         letter_t eol,
00039                                         length_t length) :
00040     begin_      (stream),
00041     stream_     (stream),
00042     end_        (eof),
00043     eol_        (eol),
00044     length_     (length)
00045   {
00046     precondition(length > 0);
00047 
00048     compute_size();
00049   }
00050 
00051   template <class InputIterator, class Letter>
00052   bool
00053   Window<InputIterator, Letter>::eof() const
00054   {
00055     return stream_ == end_;
00056   }
00057 
00058   template <class InputIterator, class Letter>
00059   bool
00060   Window<InputIterator, Letter>::eol() const
00061   {
00062     return eof() || (*stream_ == eol_);
00063   }
00064 
00065   template <class InputIterator, class Letter>
00066   void
00067   Window<InputIterator, Letter>::shift(unsigned int n)
00068   {
00069     precondition(n <= size_);
00070 
00071     if ((stream_ != end_) && (*stream_ == eol_))
00072       ++stream_;
00073     else
00074       stream_ += n;
00075     compute_size();
00076   }
00077 
00078   template <class InputIterator, class Letter>
00079   void
00080   Window<InputIterator, Letter>::shift()
00081   {
00082     shift(size());
00083   }
00084 
00085   template <class InputIterator, class Letter>
00086   void
00087   Window<InputIterator, Letter>::moveto(length_t offset)
00088   {
00089     stream_ = begin_ + offset;
00090     compute_size();
00091   }
00092 
00093   template <class InputIterator, class Letter>
00094   void
00095   Window<InputIterator, Letter>::moveto(iterator_t position)
00096   {
00097     stream_ = position;
00098     compute_size();
00099   }
00100 
00101   template <class InputIterator, class Letter>
00102   typename Window<InputIterator, Letter>::length_t
00103   Window<InputIterator, Letter>::size() const
00104   {
00105     return size_;
00106   }
00107 
00108   template <class InputIterator, class Letter>
00109   typename Window<InputIterator, Letter>::letter_t
00110   Window<InputIterator, Letter>::operator [] (length_t i) const
00111   {
00112     precondition (i < size_);
00113 
00114     return stream_[i];
00115   }
00116 
00117   template <class InputIterator, class Letter>
00118   std::ostream&
00119   Window<InputIterator, Letter>::print(std::ostream& ostr) const
00120   {
00121     return ostr << window();
00122   }
00123 
00124   template <class InputIterator, class Letter>
00125   typename Window<InputIterator, Letter>::letter_t
00126   Window<InputIterator, Letter>::eol_value() const
00127   {
00128     return eol_;
00129   }
00130 
00131   template <class InputIterator, class Letter>
00132   typename Window<InputIterator, Letter>::iterator_t
00133   Window<InputIterator, Letter>::begin() const
00134   {
00135     return begin_;
00136   }
00137 
00138   template <class InputIterator, class Letter>
00139   typename Window<InputIterator, Letter>::iterator_t
00140   Window<InputIterator, Letter>::stream() const
00141   {
00142     return stream_;
00143   }
00144 
00145   template <class InputIterator, class Letter>
00146   typename Window<InputIterator, Letter>::iterator_t
00147   Window<InputIterator, Letter>::end() const
00148   {
00149     return end_;
00150   }
00151 
00152   template <class InputIterator, class Letter>
00153   size_t
00154   Window<InputIterator, Letter>::offset() const
00155   {
00156     return stream_ - begin_;
00157   }
00158 
00159   template <class InputIterator, class Letter>
00160   typename Window<InputIterator, Letter>::length_t
00161   Window<InputIterator, Letter>::length() const
00162   {
00163     return length_;
00164   }
00165 
00166   template <class InputIterator, class Letter>
00167   typename Window<InputIterator, Letter>::string_t
00168   Window<InputIterator, Letter>::window() const
00169   {
00170     return string_t (stream_, stream_ + size_);
00171   }
00172 
00173   template <class InputIterator, class Letter>
00174   void
00175   Window<InputIterator, Letter>::compute_size()
00176   {
00177     size_ = 0;
00178     while ((size_ < length_) &&
00179            (stream_ + size_ != end_) &&
00180            (stream_[size_] != eol_))
00181       ++size_;
00182   }
00183 
00184   template <class InputIterator, class Letter>
00185   std::ostream&
00186   operator << (std::ostream& ostr, const Window<InputIterator, Letter>& w)
00187   {
00188     return w.print(ostr);
00189   }
00190 
00193 } // utility
00194 
00195 #endif // ! VCSN_MISC_WINDOW_HXX

Generated on Fri Jul 28 12:18:56 2006 for Vaucanson by  doxygen 1.4.6