00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 #ifndef MLN_CORE_CONCEPT_ITERATOR_HH
00027 # define MLN_CORE_CONCEPT_ITERATOR_HH
00028 
00033 # include <mln/core/concept/object.hh>
00034 
00038 # define for_all(x) for(x.start(); x.is_valid(); x.next())
00039 
00040 
00044 # define for_all_2(x1, x2)                      \
00045   for(x1.start(), x2.start();                   \
00046       x1.is_valid();                            \
00047       x1.next(), x2.next())
00048 
00049 
00053 # define for_all_3(x1, x2, x3)                  \
00054   for(x1.start(), x2.start(), x3.start();       \
00055       x1.is_valid();                            \
00056       x1.next(), x2.next(), x3.next())
00057 
00058 
00062 # define for_all_remaining(x) \
00063   if (! x.is_valid()) {} else while (x.next(), x.is_valid())
00064 
00065 
00066 
00067 namespace mln
00068 {
00074   template <typename E>
00075   struct Iterator : public Object<E>
00076   {
00077     
00078 
00079 
00080 
00081 
00082 
00083 
00092     void next(); 
00093 
00094   protected:
00095     Iterator();
00096   };
00097 
00098 
00099 # ifndef MLN_INCLUDE_ONLY
00100 
00101   template <typename E>
00102   void Iterator<E>::next() 
00103   {
00104     assert(exact(this)->is_valid());
00105     exact(this)->next_();
00106   }
00107 
00108   template <typename E>
00109   inline
00110   Iterator<E>::Iterator()
00111   {
00112     bool (E::*m1)() const = & E::is_valid;
00113     m1 = 0;
00114     void (E::*m2)() = & E::invalidate;
00115     m2 = 0;
00116     void (E::*m3)() = & E::start;
00117     m3 = 0;
00118     void (E::*m4)() = & E::next_;
00119     m4 = 0;
00120   }
00121 
00122 # endif // ! MLN_INCLUDE_ONLY
00123 
00124 
00125 } 
00126 
00127 
00128 #endif // ! MLN_CORE_CONCEPT_ITERATOR_HH