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