include/wipal/tool/list_of_iterables.hxx

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_HXX_
00023 # define TOOL_LIST_OF_ITERABLES_HXX_
00024 
00025 # include <boost/foreach.hpp>
00026 
00027 # include "list_of_iterables.hh"
00028 
00029 namespace tool
00030 {
00031 
00032   template <class T, class B1, class B2>
00033   list_of_iterables_iterator<T, B1, B2>::
00034   list_of_iterables_iterator(const iterable_type& list, bool end): super_type ()
00035   {
00036     if (not end)
00037       BOOST_FOREACH(const T& i, list.list_)
00038         {
00039           const inner_iterator_type     b = i.begin();
00040           const inner_iterator_type     e = i.end();
00041 
00042           if (b != e)
00043             {
00044               begins_.push(b);
00045               ends_.push(e);
00046             }
00047         }
00048   }
00049 
00050   template <class T, class B1, class B2>
00051   bool
00052   list_of_iterables_iterator<T, B1, B2>::equal(const exact_type& rhs) const
00053   {
00054     const bool r = begins_ == rhs.begins_;
00055 
00056     assert(not r or ends_ == rhs.ends_);
00057     return r;
00058   }
00059 
00060   template <class T, class B1, class B2>
00061   void
00062   list_of_iterables_iterator<T, B1, B2>::increment()
00063   {
00064     // Preconditions.
00065     assert(not begins_.empty() and not ends_.empty());
00066     assert(begins_.front() != ends_.front());
00067 
00068     if (++begins_.front() == ends_.front())
00069       {
00070         begins_.pop();
00071         ends_.pop();
00072       }
00073 
00074     // Postconditions.
00075     assert(begins_.empty() or (not ends_.empty() and
00076                                begins_.front() != ends_.front()));
00077   }
00078 
00079   template <class T, class B1, class B2>
00080   const typename list_of_iterables_iterator<T, B1, B2>::value_type&
00081   list_of_iterables_iterator<T, B1, B2>::get() const
00082   {
00083     assert(not begins_.empty());
00084     assert(begins_.front() != ends_.front());
00085 
00086     return *begins_.front();
00087   }
00088 
00089   template <class T, class B1, class B2>
00090   const typename list_of_iterables_iterator<T, B1, B2>::value_type*
00091   list_of_iterables_iterator<T, B1, B2>::get_ptr() const
00092   {
00093     assert(not begins_.empty());
00094     assert(begins_.front() != ends_.front());
00095 
00096     return &*begins_.front();
00097   }
00098 
00099   template <class T, class B>
00100   list_of_iterables<T, B>::list_of_iterables(): super_type ()
00101   {
00102   }
00103 
00104   template <class T, class B>
00105   template <class L>
00106   list_of_iterables<T, B>::list_of_iterables(const L& list): super_type ()
00107   {
00108     BOOST_FOREACH(const T& i, list)
00109       list_.push_back(i);
00110   }
00111 
00112   template <class T, class B>
00113   bool
00114   list_of_iterables<T, B>::empty() const
00115   {
00116     return list_.empty() or this->begin() == this->end();
00117   }
00118 
00119   template <class T, class B>
00120   size_t
00121   list_of_iterables<T, B>::size() const
00122   {
00123     return list_.size();
00124   }
00125 
00126   template <class T, class B>
00127   typename list_of_iterables<T, B>::exact_type&
00128   list_of_iterables<T, B>::push_back(const T& i)
00129   {
00130     list_.push_back(i);
00131 
00132     return this->exact();
00133   }
00134 
00135   template <class T, class B>
00136   const T&
00137   list_of_iterables<T, B>::iterable(unsigned i) const
00138   {
00139     assert(i < list_.size());
00140 
00141     return list_[i];
00142   }
00143 
00144   template <class T, class B>
00145   T&
00146   list_of_iterables<T, B>::iterable(unsigned i)
00147   {
00148     assert(i < list_.size());
00149 
00150     return list_[i];
00151   }
00152 
00153 } // End of namespace tool.
00154 
00155 #endif // ! TOOL_ITERABLE_HXX_

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