00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef TOOL_WINDOW_HXX_
00023 # define TOOL_WINDOW_HXX_
00024
00025 # include "window.hxx"
00026
00027 namespace tool
00028 {
00029
00030 template <class I, unsigned Ws, unsigned S, class B>
00031 template <class Iterable>
00032 window<I, Ws, S, B>::window(Iterable& i, bool end):
00033 at_end_ (end or i.first_ == i.last_),
00034 next_ (end ? i.last_ : i.first_),
00035 last_ (i.last_),
00036 v_ ()
00037 {
00038 for (unsigned i = 0; next_ != last_ and i < Ws; ++i)
00039 v_.push_back(*next_++);
00040 }
00041
00042 template <class I, unsigned Ws, unsigned S, class B>
00043 bool
00044 window<I, Ws, S, B>::equal(const window& rhs) const
00045 {
00046 return
00047 at_end_ == rhs.at_end_ and next_ == rhs.next_ and last_ == rhs.last_;
00048 }
00049
00050 template <class I, unsigned Ws, unsigned S, class B>
00051 void
00052 window<I, Ws, S, B>::increment()
00053 {
00054 if (next_ == last_)
00055 at_end_ = true;
00056 else
00057 for (unsigned i = 0; i < S; ++i)
00058 {
00059 v_.pop_front();
00060 if (next_ != last_)
00061 v_.push_back(*next_++);
00062 }
00063 }
00064
00065 template <class I, unsigned Ws, unsigned S, class B>
00066 const typename window<I, Ws, S, B>::value_type&
00067 window<I, Ws, S, B>::get() const
00068 {
00069 assert(not at_end_);
00070
00071 return v_;
00072 }
00073
00074 template <class I, unsigned Ws, unsigned S, class B>
00075 const typename window<I, Ws, S, B>::value_type*
00076 window<I, Ws, S, B>::get_ptr() const
00077 {
00078 assert(not at_end_);
00079
00080 return &v_;
00081 }
00082
00083 template <class I, unsigned Ws, unsigned S, class B>
00084 const typename I::value_type&
00085 window<I, Ws, S, B>::operator [] (unsigned i) const
00086 {
00087 assert(not at_end_);
00088 assert(i < v_.size());
00089
00090 return v_[i];
00091 }
00092
00093 template <class I, unsigned Ws, unsigned S, class B>
00094 bool
00095 window<I, Ws, S, B>::last() const
00096 {
00097 return next_ == last_;
00098 }
00099
00100 template <class I, unsigned Ws, unsigned S, class B>
00101 window_maker<I, Ws, S, B>::window_maker(const I& first, const I& last):
00102 first_ (first),
00103 last_ (last)
00104 {
00105 }
00106
00107 }
00108
00109 #endif // ! TOOL_WINDOW_HXX_