include/wipal/tool/window.hh

00001 /*
00002  * WiPal - A library and a set of tools to manipulate wireless traces.
00003  * Copyright (C) 2007  Universite Pierre et Marie Curie - Paris 6
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00018  * MA  02110-1301  USA
00019  *
00020  * Author: Thomas Claveirole <thomas.claveirole@lip6.fr>
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 
00124   protected:
00125     bool                at_end_;
00126     InputIterator       next_;  
00127     InputIterator       last_;  
00128     value_type          v_;     
00129   };
00130 
00140   template <class InputIterator,
00141             unsigned WSize,
00142             unsigned Step = 1,
00143             class Bottom = bottom>
00144   struct window_maker:
00145     wp_inherit(public iterable,
00146                window_maker<InputIterator, WSize, Step, Bottom>)
00147   {
00149     window_maker(const InputIterator& first, const InputIterator& last);
00150 
00151   private:
00152     InputIterator       first_;
00153     InputIterator       last_;
00154 
00155     friend class window<InputIterator, WSize, Step>;
00156   };
00157 
00158 } // End of namespace tool.
00159 
00160 # include "window.hxx"
00161 
00162 #endif // ! TOOL_WINDOW_HH_

Generated on Wed Jan 16 16:15:14 2008 for wipal by  doxygen 1.5.4