00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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 {
00038 BOOST_FOREACH(const T& i, list.list_)
00039 {
00040 const inner_iterator_type b = i.begin();
00041 const inner_iterator_type e = i.end();
00042
00043 if (b != e)
00044 {
00045 begins_.push(b);
00046 ends_.push(e);
00047 }
00048 }
00049 }
00050 }
00051
00052 template <class T, class B1, class B2>
00053 bool
00054 list_of_iterables_iterator<T, B1, B2>::equal(const exact_type& rhs) const
00055 {
00056 const bool r = begins_ == rhs.begins_;
00057
00058 assert(not r or ends_ == rhs.ends_);
00059 return r;
00060 }
00061
00062 template <class T, class B1, class B2>
00063 void
00064 list_of_iterables_iterator<T, B1, B2>::increment()
00065 {
00066
00067 assert(not begins_.empty() and not ends_.empty());
00068 assert(begins_.front() != ends_.front());
00069
00070 if (++begins_.front() == ends_.front())
00071 {
00072 begins_.pop();
00073 ends_.pop();
00074 }
00075
00076
00077 assert(begins_.empty() or (not ends_.empty() and
00078 begins_.front() != ends_.front()));
00079 }
00080
00081 template <class T, class B1, class B2>
00082 const typename list_of_iterables_iterator<T, B1, B2>::value_type&
00083 list_of_iterables_iterator<T, B1, B2>::get() const
00084 {
00085 assert(not begins_.empty());
00086 assert(begins_.front() != ends_.front());
00087
00088 return *begins_.front();
00089 }
00090
00091 template <class T, class B1, class B2>
00092 const typename list_of_iterables_iterator<T, B1, B2>::value_type*
00093 list_of_iterables_iterator<T, B1, B2>::get_ptr() const
00094 {
00095 assert(not begins_.empty());
00096 assert(begins_.front() != ends_.front());
00097
00098 return &*begins_.front();
00099 }
00100
00101 template <class T, class B>
00102 list_of_iterables<T, B>::list_of_iterables(): super_type ()
00103 {
00104 }
00105
00106 template <class T, class B>
00107 template <class L>
00108 list_of_iterables<T, B>::list_of_iterables(const L& list): super_type ()
00109 {
00110 BOOST_FOREACH(const T& i, list)
00111 list_.push_back(i);
00112 }
00113
00114 template <class T, class B>
00115 bool
00116 list_of_iterables<T, B>::empty() const
00117 {
00118 return list_.empty() or this->begin() == this->end();
00119 }
00120
00121 template <class T, class B>
00122 size_t
00123 list_of_iterables<T, B>::size() const
00124 {
00125 return list_.size();
00126 }
00127
00128 template <class T, class B>
00129 typename list_of_iterables<T, B>::exact_type&
00130 list_of_iterables<T, B>::push_back(const T& i)
00131 {
00132 list_.push_back(i);
00133
00134 return this->exact();
00135 }
00136
00137 template <class T, class B>
00138 const T&
00139 list_of_iterables<T, B>::get(unsigned i) const
00140 {
00141 assert(i < list_.size());
00142
00143 return list_[i];
00144 }
00145
00146 template <class T, class B>
00147 T&
00148 list_of_iterables<T, B>::get(unsigned i)
00149 {
00150 assert(i < list_.size());
00151
00152 return list_[i];
00153 }
00154
00155 }
00156
00157 #endif // ! TOOL_ITERABLE_HXX_