00001 // Copyright (C) 2001, 2002, 2003, 2004 EPITA Research and Development Laboratory 00002 // 00003 // This file is part of the Olena Library. This library is free 00004 // software; you can redistribute it and/or modify it under the terms 00005 // of the GNU General Public License version 2 as published by the 00006 // Free Software Foundation. 00007 // 00008 // This library is distributed in the hope that it will be useful, 00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00011 // General Public License for more details. 00012 // 00013 // You should have received a copy of the GNU General Public License 00014 // along with this library; see the file COPYING. If not, write to 00015 // the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00016 // Boston, MA 02110-1301, USA. 00017 // 00018 // As a special exception, you may use this file as part of a free 00019 // software library without restriction. Specifically, if other files 00020 // instantiate templates or use macros or inline functions from this 00021 // file, or you compile this file and link it with other files to 00022 // produce an executable, this file does not by itself cause the 00023 // resulting executable to be covered by the GNU General Public 00024 // License. This exception does not however invalidate any other 00025 // reasons why the executable file might be covered by the GNU General 00026 // Public License. 00027 00028 #ifndef OLENA_CORE_ABSTRACT_ITER_HH 00029 # define OLENA_CORE_ABSTRACT_ITER_HH 00030 00031 # include <oln/core/abstract/point.hh> 00032 # include <oln/core/abstract/dpoint.hh> 00033 # include <mlc/type.hh> 00034 # include <mlc/objs.hh> 00035 # include <oln/core/macros.hh> 00036 00037 namespace oln { 00038 00041 namespace abstract { 00042 template<class Exact> 00043 struct iter; // forward declaration 00044 } // end of abstract 00045 00046 template<class Exact> 00047 struct iter_traits; 00048 00052 template<class Exact> 00053 struct iter_traits<abstract::iter<Exact> > 00054 { 00055 00056 }; 00057 00058 // shortcuts 00059 using mlc::begin; 00060 using mlc::end; 00061 00062 namespace abstract 00063 { 00178 template<class Exact> 00179 struct iter : public mlc_hierarchy::any<Exact> 00180 { 00186 typedef typename iter_traits<Exact>::point_type point_type; 00192 typedef typename iter_traits<Exact>::dpoint_type dpoint_type; 00193 00200 const point_type& 00201 point_ref() const 00202 { 00203 return p_; 00204 } 00205 00213 bool 00214 operator==(const abstract::point<point_type>& p) const 00215 { 00216 return p_ == p.exact(); 00217 } 00218 00226 bool 00227 operator!=(const abstract::point<point_type>& p) const 00228 { 00229 return p_ != p.exact(); 00230 } 00231 00240 point_type 00241 operator+(const abstract::dpoint<dpoint_type>& dp) const 00242 { 00243 precondition(*this != end); 00244 return p_ + dp.exact(); 00245 } 00246 00255 point_type 00256 operator-(const abstract::dpoint<dpoint_type>& dp) const 00257 { 00258 precondition(*this != end); 00259 return p_ - dp.exact(); 00260 } 00261 00268 operator point_type() const 00269 { 00270 return this->exact().to_point(); 00271 } 00272 00279 point_type 00280 cur() const 00281 { 00282 return *this; 00283 } 00284 00285 // deferred methods are: 00286 // 00287 // void _goto_begin(); 00288 // void _goto_end(); 00289 // bool _is_at_end() const; 00290 // void _goto_next(); 00291 00297 mlc::begin_type 00298 operator=(mlc::begin_type b) 00299 { 00300 this->exact().goto_begin_(); 00301 return b; 00302 } 00303 00309 mlc::end_type 00310 operator=(mlc::end_type e) 00311 { 00312 this->exact().goto_end_(); 00313 return e; 00314 } 00315 00322 bool 00323 operator==(mlc::end_type) const 00324 { 00325 return this->exact().is_at_end_(); 00326 } 00327 00332 void 00333 operator++() 00334 { 00335 precondition(*this != end); 00336 this->exact().goto_next_(); 00337 } 00338 00339 // typename mlc::exact<self>::ret operator++(int) 00340 // { 00341 // precondition(*this != end); 00342 // typename mlc::exact<self>::ret tmp = this->exact(); 00343 // this->operator++(); 00344 // return tmp; 00345 // } 00346 00347 // deduced methods: 00348 00355 bool 00356 operator!=(mlc::end_type e) const 00357 { 00358 return ! this->operator==(e); 00359 } 00360 00362 static std::string 00363 name() 00364 { 00365 return std::string("iter<") + 00366 Exact::name() + ">"; 00367 } 00368 00369 protected: 00370 point_type p_; 00371 00377 iter() 00378 {} 00379 }; 00380 00381 } // end of abstract 00382 00383 } // end of oln 00384 00385 00386 #endif // ! OLENA_CORE_ABSTRACT_ITER_HH