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 wpl
00028 {
00029
00030 namespace tool
00031 {
00032
00033 template <class I, unsigned Ws, unsigned S, class B>
00034 template <class Iterable>
00035 window<I, Ws, S, B>::window(Iterable& i, bool end):
00036 at_end_ (end or i.first_ == i.last_),
00037 next_ (end ? i.last_ : i.first_),
00038 last_ (i.last_),
00039 v_ ()
00040 {
00041 for (unsigned i = 0; next_ != last_ and i < Ws; ++i)
00042 v_.push_back(*next_++);
00043 }
00044
00045 template <class I, unsigned Ws, unsigned S, class B>
00046 bool
00047 window<I, Ws, S, B>::equal(const window& rhs) const
00048 {
00049 return
00050 at_end_ == rhs.at_end_ and next_ == rhs.next_ and last_ == rhs.last_;
00051 }
00052
00053 template <class I, unsigned Ws, unsigned S, class B>
00054 void
00055 window<I, Ws, S, B>::increment()
00056 {
00057 if (next_ == last_)
00058 at_end_ = true;
00059 else
00060 for (unsigned i = 0; i < S; ++i)
00061 {
00062 v_.pop_front();
00063 if (next_ != last_)
00064 v_.push_back(*next_++);
00065 }
00066 }
00067
00068 template <class I, unsigned Ws, unsigned S, class B>
00069 const typename window<I, Ws, S, B>::value_type&
00070 window<I, Ws, S, B>::get() const
00071 {
00072 assert(not at_end_);
00073
00074 return v_;
00075 }
00076
00077 template <class I, unsigned Ws, unsigned S, class B>
00078 const typename window<I, Ws, S, B>::value_type*
00079 window<I, Ws, S, B>::get_ptr() const
00080 {
00081 assert(not at_end_);
00082
00083 return &v_;
00084 }
00085
00086 template <class I, unsigned Ws, unsigned S, class B>
00087 const typename I::value_type&
00088 window<I, Ws, S, B>::operator [] (unsigned i) const
00089 {
00090 assert(not at_end_);
00091 assert(i < v_.size());
00092
00093 return v_[i];
00094 }
00095
00096 template <class I, unsigned Ws, unsigned S, class B>
00097 bool
00098 window<I, Ws, S, B>::last() const
00099 {
00100 return next_ == last_;
00101 }
00102
00103 template <class I, unsigned Ws, unsigned S, class B>
00104 window_maker<I, Ws, S, B>::window_maker(const I& first, const I& last):
00105 first_ (first),
00106 last_ (last)
00107 {
00108 }
00109
00110 }
00111
00112 }
00113
00114 #endif // ! TOOL_WINDOW_HXX_