Milena (Olena)
User documentation 2.0a Id
|
00001 // Copyright (C) 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_UTIL_INTERNAL_GRAPH_NBH_ITER_BASE_HH 00027 # define MLN_UTIL_INTERNAL_GRAPH_NBH_ITER_BASE_HH 00028 00029 # include <mln/core/concept/proxy.hh> 00030 00034 00035 namespace mln 00036 { 00037 00038 // Forward declaration. 00039 template <typename S> class p_indexed_psite; 00040 00041 namespace internal 00042 { 00043 00044 template <typename G, typename C, typename Elt, typename E> 00045 class nbh_iterator_base 00046 : public Proxy< E >, 00047 public internal::proxy_impl< const Elt&, E > 00048 { 00049 public: 00050 00054 bool is_valid() const; 00056 void invalidate(); 00057 00059 void start(); 00060 00062 void next(); 00063 00066 unsigned index() const; 00067 00069 typename Elt::id_t id() const; 00070 00072 operator typename Elt::id_t() const; 00073 00076 operator typename Elt::id_value_t() const; 00077 00079 const C& center() const; 00080 00082 template <typename S> 00083 void center_at(const p_indexed_psite<S>& c); 00084 00085 template <typename C2> 00086 void center_at(const C2& c); 00087 00089 void change_target(const G& g); 00090 00092 const Elt& element() const; 00093 00095 const Elt& elt_hook_() const; 00096 00098 00102 const Elt& subj_(); 00104 00105 protected: 00108 nbh_iterator_base(); 00109 template <typename C2> 00110 nbh_iterator_base(const C2& c); 00112 00113 const C* c_; // Center 00114 Elt elt_; 00115 unsigned i_; 00116 }; 00117 00118 # ifndef MLN_INCLUDE_ONLY 00119 00120 template <typename G, typename C, typename Elt, typename E> 00121 inline 00122 nbh_iterator_base<G,C,Elt,E>::nbh_iterator_base() 00123 { 00124 } 00125 00126 template <typename G, typename C, typename Elt, typename E> 00127 template <typename C2> 00128 inline 00129 nbh_iterator_base<G,C,Elt,E>::nbh_iterator_base(const C2& c) 00130 : elt_(c.graph()), i_(0) 00131 { 00132 //FIXME: Check if typeof(c.graph()) == G 00133 center_at(c); 00134 } 00135 00136 template <typename G, typename C, typename Elt, typename E> 00137 inline 00138 bool 00139 nbh_iterator_base<G,C,Elt,E>::is_valid() const 00140 { 00141 return exact(this)->is_valid_(); 00142 } 00143 00144 template <typename G, typename C, typename Elt, typename E> 00145 inline 00146 void 00147 nbh_iterator_base<G,C,Elt,E>::invalidate() 00148 { 00149 i_ = mln_max(unsigned); 00150 } 00151 00152 template <typename G, typename C, typename Elt, typename E> 00153 inline 00154 void 00155 nbh_iterator_base<G,C,Elt,E>::start() 00156 { 00157 i_ = exact(this)->start_id_(); 00158 if (is_valid()) 00159 exact(this)->update_(); 00160 } 00161 00162 template <typename G, typename C, typename Elt, typename E> 00163 inline 00164 void 00165 nbh_iterator_base<G,C,Elt,E>::next() 00166 { 00167 mln_precondition(is_valid()); 00168 mln_precondition(c_->is_valid()); 00169 00170 i_ = exact(this)->next_id_(); 00171 if (is_valid()) 00172 exact(this)->update_(); 00173 } 00174 00175 template <typename G, typename C, typename Elt, typename E> 00176 inline 00177 unsigned 00178 nbh_iterator_base<G,C,Elt,E>::index() const 00179 { 00180 return i_; 00181 } 00182 00183 template <typename G, typename C, typename Elt, typename E> 00184 inline 00185 typename Elt::id_t 00186 nbh_iterator_base<G,C,Elt,E>::id() const 00187 { 00188 return elt_.id(); 00189 } 00190 00191 template <typename G, typename C, typename Elt, typename E> 00192 inline 00193 nbh_iterator_base<G,C,Elt,E>::operator typename Elt::id_t() const 00194 { 00195 return elt_.id(); 00196 } 00197 00198 template <typename G, typename C, typename Elt, typename E> 00199 inline 00200 nbh_iterator_base<G,C,Elt,E>::operator typename Elt::id_value_t() const 00201 { 00202 return elt_.id(); 00203 } 00204 00205 template <typename G, typename C, typename Elt, typename E> 00206 inline 00207 const C& 00208 nbh_iterator_base<G,C,Elt,E>::center() const 00209 { 00210 mln_precondition(c_ != 0); 00211 return *c_; 00212 } 00213 00214 template <typename G, typename C, typename Elt, typename E> 00215 inline 00216 const Elt& 00217 nbh_iterator_base<G,C,Elt,E>::subj_() 00218 { 00219 return elt_; 00220 } 00221 00222 template <typename G, typename C, typename Elt, typename E> 00223 template <typename S> 00224 inline 00225 void 00226 nbh_iterator_base<G,C,Elt,E>::center_at(const p_indexed_psite<S>& c) 00227 { 00228 //FIXME: p_indexed_psite does not have a conversion operator towards a 00229 // p_edges/vertices_psite or a vertex/edge. 00230 c_ = & static_cast< const C& >(c.unproxy_()); 00231 00232 //FIXME: c_->graph() may not be the right graph! 00233 // The target may not be initialized before this call... 00234 // See core/neighb.hh in center_at(), i.center_at(). 00235 elt_.change_graph(c_->graph()); 00236 00237 invalidate(); 00238 } 00239 00240 template <typename G, typename C, typename Elt, typename E> 00241 template <typename C2> 00242 inline 00243 void 00244 nbh_iterator_base<G,C,Elt,E>::center_at(const C2& c) 00245 { 00246 mlc_converts_to(C2, const C&)::check(); 00247 c_ = & static_cast< const C& >(exact(c)); 00248 00249 //FIXME: c_->graph() may not be the right graph! 00250 // The target may not be initialized before this call... 00251 // See core/neighb.hh in center_at(), i.center_at(). 00252 elt_.change_graph(c_->graph()); 00253 00254 invalidate(); 00255 } 00256 00257 template <typename G, typename C, typename Elt, typename E> 00258 inline 00259 void 00260 nbh_iterator_base<G,C,Elt,E>::change_target(const G& g) 00261 { 00262 elt_.change_graph(g); 00263 } 00264 00265 template <typename G, typename C, typename Elt, typename E> 00266 inline 00267 const Elt& 00268 nbh_iterator_base<G,C,Elt,E>::element() const 00269 { 00270 return elt_; 00271 } 00272 00273 template <typename G, typename C, typename Elt, typename E> 00274 inline 00275 const Elt& 00276 nbh_iterator_base<G,C,Elt,E>::elt_hook_() const 00277 { 00278 return elt_; 00279 } 00280 00281 # endif // !MLN_INCLUDE_ONLY 00282 00283 } // End of namespace mln::internal 00284 00285 } // End of namespace mln 00286 00287 00288 #endif // ! MLN_UTIL_INTERNAL_GRAPH_NBH_ITER_BASE_HH