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