include/wipal/tool/list_of_iterables.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_LIST_OF_ITERABLES_HH_
00023 # define TOOL_LIST_OF_ITERABLES_HH_
00024 
00025 # include <queue>
00026 # include <vector>
00027 
00028 # include <wipal/tool/iterable.hh>
00029 # include <wipal/tool/iterator.hh>
00030 
00031 namespace tool
00032 {
00033 
00034   /*---------------------.
00035   | Forward declarations |
00036   `---------------------*/
00037 
00038   template <class T, class B>
00039   struct list_of_iterables;
00040 
00041   template <class T, class B1, class B2>
00042   struct list_of_iterables_iterator;
00043 
00044   /*--------------.
00045   | Virtual types |
00046   `--------------*/
00047 
00048   template <class T, class B, class Bottom>
00049   struct types< list_of_iterables_iterator<T, B, Bottom> >
00050   {
00051     typedef typename T::iterator::value_type            value_type;
00052     typedef list_of_iterables<T, B>                     iterable_type;
00053   };
00054 
00055   template <class T, class B>
00056   struct types< list_of_iterables<T, B> >
00057   {
00058     typedef list_of_iterables_iterator<T, B, bottom>    iterator;
00059   };
00060 
00061   /*-------------.
00062   | Declarations |
00063   `-------------*/
00064 
00065   template <class T, class B, class Bottom = bottom>
00066   struct list_of_iterables_iterator:
00067     tt_inherit(public iterator, list_of_iterables_iterator<T, B, Bottom>)
00068   {
00069     typedef tt_get_exact(Bottom, list_of_iterables_iterator<T, B, Bottom>)
00070                                                 exact_type;
00071     typedef iterator<exact_type>                super_type;
00072     typedef tt_type(value_type, exact_type)     value_type;
00073     typedef tt_type(iterable_type, exact_type)  iterable_type;
00074 
00075     list_of_iterables_iterator(const iterable_type&, bool);
00076 
00077     bool                equal(const exact_type&) const;
00078     void                increment();
00079 
00080     const value_type&   get() const;
00081     const value_type*   get_ptr() const;
00082 
00083   private:
00084     typedef typename T::const_iterator  inner_iterator_type;
00085 
00086     std::queue<inner_iterator_type>     begins_;
00087     std::queue<inner_iterator_type>     ends_;
00088   };
00089 
00090   template <class T, class Bottom = tool::bottom>
00091   struct list_of_iterables: tt_inherit(public iterable,
00092                                        list_of_iterables<T, Bottom>)
00093   {
00094     typedef tt_get_exact(Bottom, list_of_iterables<T, Bottom>)  exact_type;
00095     typedef iterable<exact_type>                                super_type;
00096 
00097     list_of_iterables();
00098 
00099     template <class L>
00100     list_of_iterables(const L& list);
00101 
00102     bool        empty() const;
00103     size_t      size() const;
00104 
00105     exact_type& push_back(const T&);
00106 
00107     const T&    iterable(unsigned i) const;
00108     T&          iterable(unsigned i);
00109 
00110   private:
00111     std::vector<T>      list_;
00112 
00113     friend class list_of_iterables_iterator<T, Bottom, bottom>;
00114   };
00115 
00116 } // End of namespace tool.
00117 
00118 # include "list_of_iterables.hxx"
00119 
00120 #endif // ! TOOL_ITERABLE_HH_

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