BWAPI
|
00001 // Copyright (c) 2005 Tel-Aviv University (Israel). 00002 // All rights reserved. 00003 // 00004 // This file is part of CGAL (www.cgal.org); you may redistribute it under 00005 // the terms of the Q Public License version 1.0. 00006 // See the file LICENSE.QPL distributed with CGAL. 00007 // 00008 // Licensees holding a valid commercial license may use this file in 00009 // accordance with the commercial license agreement provided with the software. 00010 // 00011 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00012 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00013 // 00014 // $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.5-branch/Arrangement_on_surface_2/include/CGAL/Arrangement_2/Arrangement_2_iterators.h $ 00015 // $Id: Arrangement_2_iterators.h 35817 2007-01-26 08:26:02Z wein $ 00016 // 00017 // 00018 // Author(s) : Ron Wein <wein@post.tau.ac.il> 00019 00020 #ifndef CGAL_ARRANGEMENT_2_ITERATORS_H 00021 #define CGAL_ARRANGEMENT_2_ITERATORS_H 00022 00027 CGAL_BEGIN_NAMESPACE 00028 00035 template <class Iterator_, class Value_, class Diff_, class Category_> 00036 class I_Dereference_iterator 00037 { 00038 public: 00039 00040 // Type definitions: 00041 typedef Iterator_ Iterator; 00042 typedef I_Dereference_iterator<Iterator_, 00043 Value_, 00044 Diff_, 00045 Category_> Self; 00046 00047 typedef Category_ iterator_category; 00048 typedef Value_ value_type; 00049 typedef value_type& reference; 00050 typedef value_type* pointer; 00051 typedef Diff_ difference_type; 00052 00053 protected: 00054 00055 Iterator iter; // The internal iterator. 00056 00057 public: 00058 00060 00061 I_Dereference_iterator () 00062 {} 00063 00064 I_Dereference_iterator (Iterator it) : 00065 iter(it) 00066 {} 00068 00070 00071 bool operator== (const Self& it) const 00072 { 00073 return (iter == it.iter); 00074 } 00075 00076 bool operator!= (const Self& it) const 00077 { 00078 return (!(iter == it.iter)); 00079 } 00080 00081 Iterator current_iterator () const 00082 { 00083 return (iter); 00084 } 00085 00086 pointer ptr () const 00087 { 00088 return (static_cast<value_type *> (*iter)); 00089 } 00090 00091 reference operator* () const 00092 { 00093 return (*(ptr())); 00094 } 00095 00096 pointer operator-> () const 00097 { 00098 return (ptr()); 00099 } 00101 00103 00104 Self& operator++() 00105 { 00106 ++iter; 00107 return (*this); 00108 } 00109 00110 Self operator++ (int ) 00111 { 00112 Self tmp = *this; 00113 ++iter; 00114 return (tmp); 00115 } 00117 00119 00120 Self& operator-- () 00121 { 00122 --iter; 00123 return (*this); 00124 } 00125 00126 Self operator-- (int ) 00127 { 00128 Self tmp = *this; 00129 --iter; 00130 return (tmp); 00131 } 00133 }; 00134 00141 template <class CIterator_, class MIterator_, 00142 class Value_, class Diff_, class Category_> 00143 class I_Dereference_const_iterator 00144 { 00145 public: 00146 00147 // Type definitions: 00148 typedef CIterator_ Const_iterator; 00149 typedef MIterator_ Mutable_iterator; 00150 typedef I_Dereference_const_iterator<CIterator_, 00151 MIterator_, 00152 Value_, 00153 Diff_, 00154 Category_> Self; 00155 00156 typedef Category_ iterator_category; 00157 typedef Value_ value_type; 00158 typedef const value_type& reference; 00159 typedef const value_type* pointer; 00160 typedef Diff_ difference_type; 00161 00162 protected: 00163 00164 Const_iterator iter; // The internal iterator. 00165 00166 public: 00167 00169 00170 I_Dereference_const_iterator () 00171 {} 00172 00173 I_Dereference_const_iterator (Const_iterator it) : 00174 iter(it) 00175 {} 00176 00177 I_Dereference_const_iterator (Mutable_iterator it) : 00178 iter (Const_iterator (&(*it))) 00179 {} 00180 00182 00184 00185 bool operator== (const Self& it) const 00186 { 00187 return (iter == it.iter); 00188 } 00189 00190 bool operator!= (const Self& it) const 00191 { 00192 return (!(iter == it.iter)); 00193 } 00194 00195 Const_iterator current_iterator () const 00196 { 00197 return (iter); 00198 } 00199 00200 pointer ptr () const 00201 { 00202 return (static_cast<const value_type *> (*iter)); 00203 } 00204 00205 reference operator* () const 00206 { 00207 return (*(ptr())); 00208 } 00209 00210 pointer operator-> () const 00211 { 00212 return (ptr()); 00213 } 00215 00217 00218 Self& operator++() 00219 { 00220 ++iter; 00221 return (*this); 00222 } 00223 00224 Self operator++ (int ) 00225 { 00226 Self tmp = *this; 00227 ++iter; 00228 return (tmp); 00229 } 00231 00233 00234 Self& operator-- () 00235 { 00236 --iter; 00237 return (*this); 00238 } 00239 00240 Self operator-- (int ) 00241 { 00242 Self tmp = *this; 00243 --iter; 00244 return (tmp); 00245 } 00247 }; 00248 00254 template <class Iterator_, class Filter_, 00255 class Value_, class Diff_, class Category_> 00256 class I_Filtered_iterator 00257 { 00258 public: 00259 00260 typedef Iterator_ Iterator; 00261 typedef Filter_ Filter; 00262 typedef I_Filtered_iterator<Iterator_, 00263 Filter_, 00264 Value_, 00265 Diff_, 00266 Category_> Self; 00267 00268 typedef Category_ iterator_category; 00269 typedef Value_ value_type; 00270 typedef value_type& reference; 00271 typedef value_type* pointer; 00272 typedef Diff_ difference_type; 00273 00274 protected: 00275 00276 Iterator nt; // The internal iterator (this member should not 00277 // be renamed in order to comply with the 00278 // HalfedgeDS circulators that refer to it). 00279 Iterator iend; // A past-the-end iterator. 00280 Filter filt; // The filter functor. 00281 00282 public: 00283 00285 I_Filtered_iterator() 00286 {} 00287 00288 I_Filtered_iterator (Iterator it) : 00289 nt (it), 00290 iend (nt) 00291 {} 00292 00293 I_Filtered_iterator (Iterator it, Iterator end) : 00294 nt (it), 00295 iend (end) 00296 { 00297 while (nt != iend && ! filt (*nt)) 00298 ++nt; 00299 } 00300 00301 I_Filtered_iterator (Iterator it, Iterator end, Filter f) : 00302 nt (it), 00303 iend (end), 00304 filt (f) 00305 { 00306 while (nt != iend && ! filt (*nt)) 00307 ++nt; 00308 } 00309 00311 Iterator current_iterator() const 00312 { 00313 return (nt); 00314 } 00315 00316 Iterator past_the_end () const 00317 { 00318 return (iend); 00319 } 00320 00321 Filter filter () const 00322 { 00323 return (filt); 00324 } 00325 00326 pointer ptr() const 00327 { 00328 return static_cast<pointer>(&(*nt)); 00329 } 00330 00332 bool operator== (const Self& it) const 00333 { 00334 return (nt == it.nt); 00335 } 00336 00337 bool operator!= (const Self& it) const 00338 { 00339 return !(*this == it); 00340 } 00341 00343 reference operator*() const 00344 { 00345 return (*(ptr())); 00346 } 00347 00348 pointer operator->() const 00349 { 00350 return ptr(); 00351 } 00352 00354 Self& operator++ () 00355 { 00356 do 00357 { 00358 ++nt; 00359 } while (!(nt == iend) && ! filt (*nt)); 00360 00361 return (*this); 00362 } 00363 00364 Self operator++ (int) 00365 { 00366 Self tmp = *this; 00367 ++(*this); 00368 return tmp; 00369 } 00370 00372 Self& operator-- () 00373 { 00374 do 00375 { 00376 --nt; 00377 } while (!(nt == iend) && ! filt (*nt)); 00378 00379 return (*this); 00380 } 00381 00382 Self operator-- (int) 00383 { 00384 Self tmp = *this; 00385 --(*this); 00386 return tmp; 00387 } 00388 }; 00389 00395 template <class CIterator_, class Filter_, class MIterator_, 00396 class Value_, class Diff_, class Category_> 00397 class I_Filtered_const_iterator 00398 { 00399 public: 00400 00401 typedef CIterator_ Iterator; 00402 typedef Filter_ Filter; 00403 typedef I_Filtered_const_iterator<CIterator_, 00404 Filter_, 00405 MIterator_, 00406 Value_, 00407 Diff_, 00408 Category_> Self; 00409 00410 typedef Category_ iterator_category; 00411 typedef Value_ value_type; 00412 typedef const value_type& reference; 00413 typedef const value_type* pointer; 00414 typedef Diff_ difference_type; 00415 00416 typedef I_Filtered_iterator<MIterator_, Filter_, 00417 Value_, Diff_, 00418 Category_> mutable_iterator; 00419 00420 protected: 00421 00422 Iterator nt; // The internal iterator (this member should not 00423 // be renamed in order to comply with the 00424 // HalfedgeDS circulators that refer to it). 00425 Iterator iend; // A past-the-end iterator. 00426 Filter filt; // The filter functor. 00427 00428 public: 00429 00431 I_Filtered_const_iterator() 00432 {} 00433 00434 I_Filtered_const_iterator (Iterator it) : 00435 nt (it), 00436 iend (it) 00437 {} 00438 00439 I_Filtered_const_iterator (Iterator it, Iterator end) : 00440 nt (it), 00441 iend (end) 00442 { 00443 while (nt != iend && ! filt (*nt)) 00444 ++nt; 00445 } 00446 00447 I_Filtered_const_iterator (Iterator it, Iterator end, Filter f) : 00448 nt (it), 00449 iend (end), 00450 filt (f) 00451 { 00452 while (nt != iend && ! filt (*nt)) 00453 ++nt; 00454 } 00455 00456 I_Filtered_const_iterator (mutable_iterator it) : 00457 nt (it.current_iterator()), 00458 iend (it.past_the_end()), 00459 filt (it.filter()) 00460 { 00461 // while (nt != iend && ! filt (*nt)) 00462 // ++nt; 00463 } 00464 00466 Iterator current_iterator() const 00467 { 00468 return (nt); 00469 } 00470 00471 Iterator past_the_end () const 00472 { 00473 return (iend); 00474 } 00475 00476 Filter filter () const 00477 { 00478 return (filt); 00479 } 00480 00481 pointer ptr() const 00482 { 00483 return static_cast<pointer>(&(*nt)); 00484 } 00485 00487 bool operator== (const Self& it) const 00488 { 00489 return (nt == it.nt); 00490 } 00491 00492 bool operator!= (const Self& it) const 00493 { 00494 return !(*this == it); 00495 } 00496 00498 reference operator*() const 00499 { 00500 return (*(ptr())); 00501 } 00502 00503 pointer operator->() const 00504 { 00505 return ptr(); 00506 } 00507 00509 Self& operator++ () 00510 { 00511 do 00512 { 00513 ++nt; 00514 } while (!(nt == iend) && ! filt (*nt)); 00515 00516 return (*this); 00517 } 00518 00519 Self operator++ (int) 00520 { 00521 Self tmp = *this; 00522 ++(*this); 00523 return tmp; 00524 } 00525 00527 Self& operator-- () 00528 { 00529 do 00530 { 00531 --nt; 00532 } while (!(nt == iend) && ! filt (*nt)); 00533 00534 return (*this); 00535 } 00536 00537 Self operator-- (int) 00538 { 00539 Self tmp = *this; 00540 --(*this); 00541 return tmp; 00542 } 00543 }; 00544 00545 CGAL_END_NAMESPACE 00546 00547 #endif