Milena (Olena)
User documentation 2.0a Id
|
00001 // Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE) 00002 // 00003 // This file is part of Olena. 00004 // 00005 // Olena is free software: you can redistribute it and/or modify it under 00006 // the terms of the GNU General Public License as published by the Free 00007 // Software Foundation, version 2 of the License. 00008 // 00009 // Olena is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 // General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with Olena. If not, see <http://www.gnu.org/licenses/>. 00016 // 00017 // As a special exception, you may use this file as part of a free 00018 // software project without restriction. Specifically, if other files 00019 // instantiate templates or use macros or inline functions from this 00020 // file, or you compile this file and link it with other files to produce 00021 // an executable, this file does not by itself cause the resulting 00022 // executable to be covered by the GNU General Public License. This 00023 // exception does not however invalidate any other reasons why the 00024 // executable file might be covered by the GNU General Public License. 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 bool is_valid() const; 00079 void invalidate(); 00080 void start(); 00081 void next_(); 00082 */ 00083 00092 void next(); // final 00093 00094 protected: 00095 Iterator(); 00096 }; 00097 00098 00099 # ifndef MLN_INCLUDE_ONLY 00100 00101 template <typename E> 00102 void Iterator<E>::next() // final 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 } // end of namespace mln 00126 00127 00128 #endif // ! MLN_CORE_CONCEPT_ITERATOR_HH