include/trace-tools/tool/window.hxx

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_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),
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     return v_;
00070   }
00071 
00072   template <class I, unsigned Ws, unsigned S, class B>
00073   const typename window<I, Ws, S, B>::value_type*
00074   window<I, Ws, S, B>::get_ptr() const
00075   {
00076     return &v_;
00077   }
00078 
00079   template <class I, unsigned Ws, unsigned S, class B>
00080   const typename I::value_type&
00081   window<I, Ws, S, B>::operator [] (unsigned i) const
00082   {
00083     return v_[i];
00084   }
00085 
00086   template <class I, unsigned Ws, unsigned S, class B>
00087   window_maker<I, Ws, S, B>::window_maker(const I& first, const I& last):
00088     first_ (first),
00089     last_ (last)
00090   {
00091   }
00092 
00093 } // End of namespace tool.
00094 
00095 #endif // ! TOOL_WINDOW_HXX_

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