1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690
|
// Copyright (c) 1997
// Utrecht University (The Netherlands),
// ETH Zurich (Switzerland),
// INRIA Sophia-Antipolis (France),
// Max-Planck-Institute Saarbruecken (Germany),
// and Tel-Aviv University (Israel). All rights reserved.
//
// This file is part of CGAL (www.cgal.org); you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation; either version 3 of the License,
// or (at your option) any later version.
//
// Licensees holding a valid commercial license may use this file in
// accordance with the commercial license agreement provided with the software.
//
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//
// $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/next/Circulator/include/CGAL/circulator_impl.h $
// $Id: circulator_impl.h 67093 2012-01-13 11:22:39Z lrineau $
//
//
// Author(s) : Lutz Kettner <kettner@inf.ethz.ch>
#ifndef CGAL_CIRCULATOR_IMPL_H
#define CGAL_CIRCULATOR_IMPL_H 1
#include <CGAL/circulator.h>
namespace CGAL {
template < class S>
class Forward_circulator_over_struct
: public Forward_circulator_ptrbase<S,std::ptrdiff_t,std::size_t>{
public:
// DEFINITION
//
// Given a structure `S' that have a data member `S* next' that realizes a
// ring like data structure the adaptor
// `Forward_circulator_over_struct< S>' provides a forward circulator
// for it. If the structure `S' has additionally a second data member of
// type `S* prev' that realizes the reverse direction the adaptor
// `Bidirectional_circulator_over_struct< S>' provides a bidirectional
// circulator for it. In addition, adaptors for const circulators are
// provided with the names `Forward_const_circulator_over_struct< S>'
// and `Bidirectional_const_circulator_over_struct< S>'. A circulator
// becomes invalid whenever the object it refers to gets deleted from the
// data structure.
typedef Forward_circulator_over_struct<S> Self;
typedef Forward_circulator_ptrbase<S,std::ptrdiff_t,std::size_t> Base1;
typedef typename Base1::reference reference;
typedef typename Base1::pointer pointer;
// CREATION
//
// New creation variable is: `circ'
Forward_circulator_over_struct() {}
// a circulator `circ' with singular value.
Forward_circulator_over_struct( S* ptr)
: Forward_circulator_ptrbase<S,std::ptrdiff_t,std::size_t>( ptr) {}
// a circulator `circ' initialized to point to the element `*ptr'.
// OPERATIONS
bool operator==( Nullptr_t p) const {
CGAL_assertion( p == NULL);
return this->_ptr == NULL;
}
bool operator!=( Nullptr_t p) const { return !(*this == p); }
bool operator==( const Self& c) const { return this->_ptr == c._ptr; }
bool operator!=( const Self& c) const { return !(*this == c); }
reference operator*() const { return *(S*)this->_ptr;}
pointer operator->() const { return (S*)this->_ptr;}
Self& operator++() {
this->_ptr = ((S*)this->_ptr)->next;
return *this;
}
Self operator++(int) {
Self tmp = *this;
++*this;
return tmp;
}
};
template < class S>
class Forward_const_circulator_over_struct
: public Forward_circulator_ptrbase<S,std::ptrdiff_t,std::size_t>{
public:
typedef Forward_const_circulator_over_struct<S> Self;
typedef const S& reference;
typedef const S* pointer;
// CREATION
Forward_const_circulator_over_struct() {}
// a circulator `circ' with singular value.
Forward_const_circulator_over_struct( const S* ptr)
: Forward_circulator_ptrbase<S,std::ptrdiff_t,
std::size_t>((void*)ptr) {}
// a circulator `circ' initialized to point to the element `*ptr'.
// OPERATIONS
bool operator==( Nullptr_t p) const {
CGAL_assertion( p == NULL);
return this->_ptr == NULL;
}
bool operator!=( Nullptr_t p) const { return !(*this == p); }
bool operator==( const Self& c) const { return this->_ptr == c._ptr; }
bool operator!=( const Self& c) const { return !(*this == c); }
reference operator*() const { return *(const S*)this->_ptr;}
pointer operator->() const { return (const S*)this->_ptr;}
Self& operator++() {
this->_ptr = ((S*)this->_ptr)->next;
return *this;
}
Self operator++(int) {
Self tmp = *this;
++*this;
return tmp;
}
};
template < class S>
class Bidirectional_circulator_over_struct
: public Bidirectional_circulator_ptrbase<S,std::ptrdiff_t,std::size_t>{
public:
typedef Bidirectional_circulator_over_struct<S> Self;
typedef Bidirectional_circulator_ptrbase<S,std::ptrdiff_t,
std::size_t> Base1;
typedef typename Base1::reference reference;
typedef typename Base1::pointer pointer;
// CREATION
//
// New creation variable is: `circ'
Bidirectional_circulator_over_struct() {}
// a circulator `circ' with singular value.
Bidirectional_circulator_over_struct( S* ptr)
: Bidirectional_circulator_ptrbase<S,std::ptrdiff_t,
std::size_t>( ptr) {}
// a circulator `circ' initialized to point to the element `*ptr'.
// OPERATIONS
bool operator==( Nullptr_t p) const {
CGAL_assertion( p == NULL);
return this->_ptr == NULL;
}
bool operator!=( Nullptr_t p) const { return !(*this == p); }
bool operator==( const Self& c) const { return this->_ptr == c._ptr; }
bool operator!=( const Self& c) const { return !(*this == c); }
reference operator*() const { return *(S*)this->_ptr;}
pointer operator->() const { return (S*)this->_ptr;}
Self& operator++() {
this->_ptr = ((S*)this->_ptr)->next;
return *this;
}
Self operator++(int) {
Self tmp = *this;
++*this;
return tmp;
}
Self& operator--() {
this->_ptr = ((S*)this->_ptr)->prev;
return *this;
}
Self operator--(int) {
Self tmp = *this;
--*this;
return tmp;
}
};
template < class S>
class Bidirectional_const_circulator_over_struct
: public Bidirectional_circulator_ptrbase<S,std::ptrdiff_t,std::size_t>{
public:
typedef Bidirectional_const_circulator_over_struct<S> Self;
typedef const S& reference;
typedef const S* pointer;
// CREATION
Bidirectional_const_circulator_over_struct() {}
// a circulator `circ' with singular value.
Bidirectional_const_circulator_over_struct( const S* ptr)
: Bidirectional_circulator_ptrbase<S,std::ptrdiff_t,std::size_t>(
(void*)ptr) {}
// a circulator `circ' initialized to point to the element `*ptr'.
// OPERATIONS
bool operator==( Nullptr_t p) const {
CGAL_assertion( p == NULL);
return this->_ptr == NULL;
}
bool operator!=( Nullptr_t p) const { return !(*this == p); }
bool operator==( const Self& c) const { return this->_ptr == c._ptr; }
bool operator!=( const Self& c) const { return !(*this == c); }
reference operator*() const { return *(const S*)this->_ptr;}
pointer operator->() const { return (const S*)this->_ptr;}
Self& operator++() {
this->_ptr = ((S*)this->_ptr)->next;
return *this;
}
Self operator++(int) {
Self tmp = *this;
++*this;
return tmp;
}
Self& operator--() {
this->_ptr = ((S*)this->_ptr)->prev;
return *this;
}
Self operator--(int) {
Self tmp = *this;
--*this;
return tmp;
}
};
template < class C>
class Forward_circulator_over_class
: public Forward_circulator_ptrbase<C,std::ptrdiff_t,std::size_t>{
public:
typedef Forward_circulator_over_class<C> Self;
// DEFINITION
//
// Given a class `C' that has a member function `C* next()' that realizes
// a ring like data structure the adaptor
// `Forward_circulator_over_class<C>' provides a forward circulator
// for it. If the class `C' has additionally a second member function `C*
// prev()' that realizes the reverse direction the adaptor
// `Bidirectional_circulator_over_class<C>' provides a bidirectional
// circulator for it. In addition, adaptors for const circulators are
// provided with the names `Forward_const_circulator_over_class<C>'
// and `Bidirectional_const_circulator_over_class<C>'. A circulator
// becomes invalid whenever the object it refers to gets deleted from the
// data structure.
Forward_circulator_over_class() {}
// a circulator `circ' with a singular value.
Forward_circulator_over_class( C* ptr)
: Forward_circulator_ptrbase<C,std::ptrdiff_t,std::size_t>( ptr) {}
// a circulator `circ' initialized to point to the element `*ptr'.
//
// OPERATIONS
bool operator==( Nullptr_t p) const {
CGAL_assertion( p == NULL);
return this->_ptr == NULL;
}
bool operator!=( Nullptr_t p) const { return !(*this == p); }
bool operator==( const Self& c) const { return this->_ptr == c._ptr; }
bool operator!=( const Self& c) const { return !(*this == c); }
C& operator*() const { return *(C*)this->_ptr;}
C* operator->() const { return (C*)this->_ptr;}
Self& operator++() {
this->_ptr = ((C*)this->_ptr)->next();
return *this;
}
Self operator++(int) {
Self tmp = *this;
++*this;
return tmp;
}
};
template < class C>
class Forward_const_circulator_over_class
: public Forward_circulator_ptrbase<C,std::ptrdiff_t,std::size_t>{
public:
typedef Forward_const_circulator_over_class<C> Self;
Forward_const_circulator_over_class() {}
// a circulator `circ' with singular value.
Forward_const_circulator_over_class( const C* ptr)
: Forward_circulator_ptrbase<C,std::ptrdiff_t,std::size_t>
((void*)ptr) {}
// a circulator `circ' initialized to point to the element `*ptr'.
//
// OPERATIONS
bool operator==( Nullptr_t p) const {
CGAL_assertion( p == NULL);
return this->_ptr == NULL;
}
bool operator!=( Nullptr_t p) const { return !(*this == p); }
bool operator==( const Self& c) const { return this->_ptr == c._ptr; }
bool operator!=( const Self& c) const { return !(*this == c); }
const C& operator*() const { return *(C*)this->_ptr;}
const C* operator->() const { return (C*)this->_ptr;}
Self& operator++() {
this->_ptr = (void*)(((C*)this->_ptr)->next());
return *this;
}
Self operator++(int) {
Self tmp = *this;
++*this;
return tmp;
}
};
template < class C>
class Bidirectional_circulator_over_class
: public Bidirectional_circulator_ptrbase<C,std::ptrdiff_t,std::size_t>{
public:
typedef Bidirectional_circulator_over_class<C> Self;
Bidirectional_circulator_over_class() {}
// a circulator `circ' with singular value.
Bidirectional_circulator_over_class( C* ptr)
: Bidirectional_circulator_ptrbase<C,std::ptrdiff_t,std::size_t>
(ptr) {}
// a circulator `circ' initialized to point to the element `*ptr'.
//
// OPERATIONS
bool operator==( Nullptr_t p) const {
CGAL_assertion( p == NULL);
return this->_ptr == NULL;
}
bool operator!=( Nullptr_t p) const { return !(*this == p); }
bool operator==( const Self& c) const { return this->_ptr == c._ptr; }
bool operator!=( const Self& c) const { return !(*this == c); }
C& operator*() const { return *(C*)this->_ptr;}
C* operator->() const { return (C*)this->_ptr;}
Self& operator++() {
this->_ptr = ((C*)this->_ptr)->next();
return *this;
}
Self operator++(int) {
Self tmp = *this;
++*this;
return tmp;
}
Self& operator--() {
this->_ptr = ((C*)this->_ptr)->prev();
return *this;
}
Self operator--(int) {
Self tmp = *this;
--*this;
return tmp;
}
};
template < class C>
class Bidirectional_const_circulator_over_class
: public Bidirectional_circulator_ptrbase<C,std::ptrdiff_t,std::size_t>{
public:
typedef Bidirectional_const_circulator_over_class<C> Self;
//
// CREATION
Bidirectional_const_circulator_over_class() {}
// a circulator `circ' with singular value.
Bidirectional_const_circulator_over_class( const C* ptr)
: Bidirectional_circulator_ptrbase<C,std::ptrdiff_t,std::size_t>(
(void*)ptr) {}
// a circulator `circ' initialized to point to the element `*ptr'.
//
// OPERATIONS
bool operator==( Nullptr_t p) const {
CGAL_assertion( p == NULL);
return this->_ptr == NULL;
}
bool operator!=( Nullptr_t p) const { return !(*this == p); }
bool operator==( const Self& c) const { return this->_ptr == c._ptr; }
bool operator!=( const Self& c) const { return !(*this == c); }
const C& operator*() const { return *(C*)this->_ptr;}
const C* operator->() const { return (C*)this->_ptr;}
Self& operator++() {
this->_ptr = (void*)(((C*)this->_ptr)->next());
return *this;
}
Self operator++(int) {
Self tmp = *this;
++*this;
return tmp;
}
Self& operator--() {
this->_ptr = (void*)(((C*)this->_ptr)->prev());
return *this;
}
Self operator--(int) {
Self tmp = *this;
--*this;
return tmp;
}
};
template < class A, class T, class U, class I>
class Circulator_over_array
: public Random_access_circulator_ptrbase<T,I,U>{
U _size;
U _i;
public:
// DEFINITION
//
// Given a data structure `A' that provides random access with an index of
// type `U' to its sequence of stored elements of type `T' with the member
// function `operator[]' the adaptor `Circulator_over_array< A, T, U,
// I>' provides a random access circulator for `A'. The corresponding
// const circulator is `Const_circulator_over_array< A, T, U, I>'. All
// circulators for an array `a' become invalid whenever `a' changes its
// size (due to deletions or insertions).
//
// `A' is a random access data structure and `T' its value type. `U' is
// the unsigned integral type carrying the size of the array and the
// actual index within the container. `I' is the signed integral type used
// as distance type and as index type in the random access circulator.
// TYPES
typedef A Array;
typedef Circulator_over_array<A,T,U,I> Self;
// CREATION
Circulator_over_array() : _size(0), _i(0) {}
// a circulator `circ' with singular value.
Circulator_over_array( A& array, U size, U start = 0)
: Random_access_circulator_ptrbase<T,I,U>( &array),
_size( size), _i(start) {}
// a circulator `circ' initialized to refer to the element
// `(array.*access)(start)'. The circulator `circ' contains a
// singular value if `start >= size'. Precondition: The
// expressions `(array.*access)(i)' are valid in the range
// 0 <= i < `size' .
// OPERATIONS
bool operator==( Nullptr_t p) const {
CGAL_assertion( p == NULL);
return _i >= _size;
}
bool operator!=( Nullptr_t p) const { return !(*this == p); }
bool operator==( const Self& c) const {
CGAL_assertion( this->_ptr == c._ptr); // belong to the same array?
CGAL_assertion( _size == c._size); // same size when instantiated ?
return _i == c._i;
}
bool operator!=( const Self& c) const { return !(*this == c); }
T& operator*() const {
CGAL_assertion( this->_ptr != NULL);
CGAL_assertion( _i < _size);
return ((A*)this->_ptr)->operator[](_i);
}
T* operator->() const {
CGAL_assertion( this->_ptr != NULL);
CGAL_assertion( _i < _size);
return &(((A*)this->_ptr)->operator[](_i));
}
Self& operator++() {
CGAL_assertion( this->_ptr != NULL);
CGAL_assertion( _i < _size);
++ _i;
if ( _i >= _size)
_i = 0;
return *this;
}
Self operator++(int) {
Self tmp = *this;
++*this;
return tmp;
}
Self& operator--() {
CGAL_assertion( this->_ptr != NULL);
CGAL_assertion( _i < _size);
if ( _i <= 0)
_i = _size - 1;
else
-- _i;
return *this;
}
Self operator--(int) {
Self tmp = *this;
--*this;
return tmp;
}
Self& operator+=( I n);
Self operator+( I n) const {
Self tmp = *this;
return tmp += n;
}
Self& operator-=( I n) { return operator+=( -n); }
Self operator-( I n) const {
Self tmp = *this;
return tmp += -n;
}
I operator-( const Self& c) const {
CGAL_assertion( this->_ptr == c._ptr); // belong to the same array?
CGAL_assertion( _size == c._size); // same size when instantiated ?
return _i - c._i;
}
T& operator[](I n) const {
Self tmp = *this;
tmp += n;
return tmp.operator*();
}
Self min_circulator() {
return Self( *((A*)this->_ptr), _size);
}
// no relational ordering
};
template < class Dist, class A, class T, class U, class I>
inline
Circulator_over_array< A, T, U, I>
operator+( Dist n, const Circulator_over_array< A, T, U, I>& circ) {
Circulator_over_array< A, T, U, I> tmp = circ;
return tmp += I(n);
}
template < class A, class T, class U, class I>
Circulator_over_array< A, T, U, I>&
Circulator_over_array< A, T, U, I>::
operator+=( I n) {
CGAL_assertion( this->_ptr != NULL);
CGAL_assertion( _i < _size);
_i = non_negative_mod( (I)(_i) + n, _size);
CGAL_assertion( _i < _size);
return *this;
}
template < class A, class T, class U, class I>
class Const_circulator_over_array
: public Random_access_circulator_ptrbase<T,I,U> {
U _size;
U _i;
public:
// TYPES
typedef A Array;
typedef Const_circulator_over_array<A,T,U,I> Self;
// New creation variable is: `circ'
//
// CREATION
Const_circulator_over_array() : _size(0), _i(0) {}
// a const circulator `circ' with singular value.
Const_circulator_over_array( const A& array, U size, U start = 0)
: Random_access_circulator_ptrbase<T,I,U>(
(void*)(&array)), _size( size), _i(start) {}
// a const circulator `circ' initialized to refer to the element
// `(array.*access)(start)'. The circulator `circ' contains a
// singular value if `start >= size'. Precondition: The
// expressions `(array.*access)(i)' are valid in the range
// 0 <= i < `size' .
//
// OPERATIONS
bool operator==( Nullptr_t p) const {
CGAL_assertion( p == NULL);
return _i >= _size;
}
bool operator!=( Nullptr_t p) const { return !(*this == p); }
bool operator==( const Self& c) const {
CGAL_assertion( this->_ptr == c._ptr); // belong to the same array?
CGAL_assertion( _size == c._size); // same size when instantiated ?
return _i == c._i;
}
bool operator!=( const Self& c) const { return !(*this == c); }
const T& operator*() const {
CGAL_assertion( this->_ptr != NULL);
CGAL_assertion( _i < _size);
return ((const A*)this->_ptr)->operator[](_i);
}
const T* operator->() const {
CGAL_assertion( this->_ptr != NULL);
CGAL_assertion( _i < _size);
return &(((const A*)this->_ptr)->operator[](_i));
}
Self& operator++() {
CGAL_assertion( this->_ptr != NULL);
CGAL_assertion( _i < _size);
++ _i;
if ( _i >= _size)
_i = 0;
return *this;
}
Self operator++(int) {
Self tmp = *this;
++*this;
return tmp;
}
Self& operator--() {
CGAL_assertion( this->_ptr != NULL);
CGAL_assertion( _i < _size);
if ( _i <= 0)
_i = _size - 1;
else
-- _i;
return *this;
}
Self operator--(int) {
Self tmp = *this;
--*this;
return tmp;
}
Self& operator+=( I n);
Self operator+( I n) const {
Self tmp = *this;
return tmp += n;
}
Self& operator-=( I n) {
return operator+=( -n);
}
Self operator-( I n) const {
Self tmp = *this;
return tmp += -n;
}
I
operator-( const Self& c) const {
CGAL_assertion( this->_ptr == c._ptr); // belong to the same array?
CGAL_assertion( _size == c._size); // same size when instantiated ?
return _i - c._i;
}
const T& operator[](I n) const {
Self tmp = *this;
tmp += n;
return tmp.operator*();
}
Self min_circulator() {
return Self( *((const A*)this->_ptr), _size);
}
// no relational ordering
};
template < class Dist, class A, class T, class U, class I>
inline
Const_circulator_over_array< A, T, U, I>
operator+( Dist n, const Const_circulator_over_array<A,T,U,I>& circ) {
Const_circulator_over_array< A, T, U, I> tmp = circ;
return tmp += I(n);
}
template < class A, class T, class U, class I>
Const_circulator_over_array< A, T, U, I>&
Const_circulator_over_array< A, T, U, I>::
operator+=( I n) {
CGAL_assertion( this->_ptr != NULL);
CGAL_assertion( _i < _size);
_i = non_negative_mod( (I)(_i) + n, _size);
CGAL_assertion( _i < _size);
return *this;
}
} //namespace CGAL
#endif // CGAL_CIRCULATOR_IMPL_H //
// EOF //
|