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_HH_
00023 # define TOOL_WINDOW_HH_
00024
00025 # include <deque>
00026
00027 # include <wipal/tool/iterator.hh>
00028 # include <wipal/tool/iterable.hh>
00029
00030 # include "window_fwd.hh"
00031
00032 namespace tool
00033 {
00034
00036 template <class I, unsigned Ws, unsigned S, class B>
00037 struct types< window<I, Ws, S, B> >
00038 {
00039 typedef
00040 std::deque<typename I::value_type>
00041 value_type;
00042 };
00043
00045 template <class I, unsigned Ws, unsigned S, class B>
00046 struct types< window_maker<I, Ws, S, B> >
00047 {
00048 typedef
00049 window<I, Ws, S, bottom>
00050 iterator;
00051 };
00052
00087 template <class InputIterator,
00088 unsigned WSize,
00089 unsigned Step = 1,
00090 class Bottom = bottom>
00091 struct window:
00092 WP_INHERIT(public iterator, window<InputIterator, WSize, Step>)
00093 {
00095
00096 typedef WP_GET_EXACT(Bottom, window<InputIterator, WSize, Step, Bottom>)
00097 exact_type;
00098 typedef WP_TYPE(value_type, exact_type) value_type;
00100
00101 enum
00102 {
00103 max_size = WSize,
00104 step = Step
00105 };
00106
00108 template <class Iterable>
00109 window(Iterable&, bool);
00110
00111
00113
00114 bool equal(const window&) const;
00115 void increment();
00116 const value_type& get() const;
00117 const value_type* get_ptr() const;
00119
00121 const typename InputIterator::value_type&
00122 operator [] (unsigned i) const;
00123
00125 bool last() const;
00126
00127 protected:
00128 bool at_end_;
00129 InputIterator next_;
00130 InputIterator last_;
00131 value_type v_;
00132 };
00133
00143 template <class InputIterator,
00144 unsigned WSize,
00145 unsigned Step = 1,
00146 class Bottom = bottom>
00147 struct window_maker:
00148 WP_INHERIT(public iterable,
00149 window_maker<InputIterator, WSize, Step, Bottom>)
00150 {
00152 window_maker(const InputIterator& first, const InputIterator& last);
00153
00154 private:
00155 InputIterator first_;
00156 InputIterator last_;
00157
00158 friend class window<InputIterator, WSize, Step>;
00159 };
00160
00161 }
00162
00163 # include "window.hxx"
00164
00165 #endif // ! TOOL_WINDOW_HH_