include/trace-tools/tool/window.hh

00001 /*
00002  * trace-tools - 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 <trace-tools/tool/iterator.hh>
00028 # include <trace-tools/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     tt_inherit(public iterator, window<InputIterator, WSize, Step>)
00093   {
00095     typedef tt_get_exact(Bottom, window<InputIterator, WSize, Step, Bottom>)
00096                                                                 exact_type;
00097 
00099     typedef tt_type(value_type, exact_type)                     value_type;
00100 
00102     template <class Iterable>
00103     window(Iterable&, bool);
00104 
00106     bool                equal(const window&) const;
00107 
00109     void                increment();
00110 
00112     const value_type&   get() const;
00113 
00115     const value_type*   get_ptr() const;
00116 
00118     const typename InputIterator::value_type&
00119     operator [] (unsigned i) const;
00120 
00121   protected:
00122     bool                at_end_;
00123     InputIterator       next_;  
00124     InputIterator       last_;  
00125     value_type          v_;     
00126   };
00127 
00137   template <class InputIterator,
00138             unsigned WSize,
00139             unsigned Step = 1,
00140             class Bottom = bottom>
00141   struct window_maker:
00142     tt_inherit(public iterable,
00143                window_maker<InputIterator, WSize, Step, Bottom>)
00144   {
00146     window_maker(const InputIterator& first, const InputIterator& last);
00147 
00148   private:
00149     InputIterator       first_;
00150     InputIterator       last_;
00151 
00152     friend class window<InputIterator, WSize, Step>;
00153   };
00154 
00155 } // End of namespace tool.
00156 
00157 # include "window.hxx"
00158 
00159 #endif // ! TOOL_WINDOW_HH_

Generated on Wed Sep 12 16:02:47 2007 for trace-tools by  doxygen 1.5.3