include/wipal/pcap/frame_iterator.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 PCAP_FRAME_ITERATOR_HH_
00023 # define PCAP_FRAME_ITERATOR_HH_
00024 
00025 # include <istream>
00026 
00027 # include <wipal/pcap/frame_descriptor.hh>
00028 # include <wipal/pcap/descriptor.hh>
00029 # include <wipal/tool/valued_iterator.hh>
00030 
00031 
00032 /*---------------------.
00033 | Forward declarations |
00034 `---------------------*/
00035 
00036 namespace pcapxx
00037 {
00038 
00039   template <class>
00040   struct descriptor;
00041 
00043   namespace internals
00044   {
00045 
00046     template <class>
00047     struct frame_iterator;
00048 
00049   } // End of namespace pcapxx::internals.
00050 
00051 } // End of namespace pcapxx.
00052 
00053 
00054 /*--------------.
00055 | Virtual types |
00056 `--------------*/
00057 
00058 namespace tool
00059 {
00060 
00062   template <class B>
00063   struct types< pcapxx::internals::frame_iterator<B> >
00064   {
00065     typedef pcapxx::frame_descriptor    value_type;
00066     typedef pcapxx::descriptor<bottom>  iterable_type;
00067   };
00068 
00069 } // End of namespace tool.
00070 
00071 /*-------------.
00072 | Declarations |
00073 `-------------*/
00074 
00075 namespace pcapxx
00076 {
00077   namespace internals
00078   {
00079 
00081     template <class Bottom = tool::bottom>
00082     struct frame_iterator:
00083       tt_inherit(public tool::valued_iterator, frame_iterator<Bottom>)
00084     {
00086 
00087       typedef tt_get_exact(Bottom, frame_iterator<Bottom>)      exact_type;
00088       typedef tool::valued_iterator<exact_type>                 super_type;
00089       typedef tt_type(iterable_type, exact_type)                iterable_type;
00090       typedef tt_type(value_type, exact_type)                   value_type;
00092 
00094       frame_iterator(const iterable_type& desc, bool end);
00095 
00097       frame_iterator(const iterable_type&       desc,
00098                      const std::streampos&      pos,
00099                      unsigned                   count);
00100 
00102       frame_iterator(const frame_iterator&);
00103 
00105       frame_iterator&   operator = (const frame_iterator&);
00106 
00108 
00109       bool              equal(const frame_iterator& rhs) const;
00110       void              increment();
00112 
00113     private:
00114 
00116       std::istream&     stream();
00117 
00118       /*-----------.
00119       | Attributes |
00120       `-----------*/
00121 
00123       const iterable_type*              desc_;
00124 
00133 
00134       /*
00135        * Profiling showed std::ifstream's constructor takes much time,
00136        * even when not requesting to open a file (which is a frequent
00137        * case).  Thus we use a pointer instead to avoid that overhead.
00138        * Of course, this implies the required allocation will slow
00139        * down cases where we must open a file and initialize this
00140        * attribute.
00141        */
00142       std::auto_ptr<std::istream>       input_;
00143 
00144       std::streampos                    pos_;   
00145       unsigned                          count_; 
00146 
00148     };
00149 
00150   } // End of namespace pcapxx::internals.
00151 
00152 } // End of namespace pcapxx.
00153 
00154 # include "frame_iterator.hxx"
00155 
00156 #endif // ! PCAP_FRAME_ITERATOR_HH_

Generated on Tue Jan 15 19:32:31 2008 for wipal by  doxygen 1.5.4