1 // Copyright (c) 2003
2 // Utrecht University (The Netherlands),
3 // ETH Zurich (Switzerland),
4 // INRIA Sophia-Antipolis (France),
5 // Max-Planck-Institute Saarbruecken (Germany),
6 // and Tel-Aviv University (Israel).  All rights reserved.
7 //
8 // This file is part of CGAL (www.cgal.org)
9 //
10 // $URL: https://github.com/CGAL/cgal/blob/v5.3/STL_Extension/include/CGAL/Circulator_project.h $
11 // $Id: Circulator_project.h 0779373 2020-03-26T13:31:46+01:00 Sébastien Loriot
12 // SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial
13 //
14 //
15 // Author(s)     : Michael Hoffmann <hoffmann@inf.ethz.ch>
16 //                 Lutz Kettner <kettner@mpi-sb.mpg.de>
17 //                 Sylvain Pion
18 
19 #ifndef CGAL_CIRCULATOR_PROJECT_H
20 #define CGAL_CIRCULATOR_PROJECT_H 1
21 
22 #include <CGAL/circulator.h>
23 
24 namespace CGAL {
25 
26 template < class C,
27            class Fct,
28            class Ref = typename C::reference,
29            class Ptr = typename C::pointer>
30 class Circulator_project {
31 protected:
32   C        nt;    // The internal circulator.
33 public:
34   typedef C  Circulator;
35   typedef Circulator_project<C,Fct,Ref,Ptr> Self;
36 
37   typedef typename  C::iterator_category   iterator_category;
38   typedef typename  Fct::result_type       value_type;
39   typedef typename  C::difference_type     difference_type;
40   typedef typename  C::size_type           size_type;
41   typedef           Ref                    reference;
42   typedef           Ptr                    pointer;
43 
44   // CREATION
45   // --------
46 
Circulator_project()47   Circulator_project() {}
Circulator_project(Circulator j)48   Circulator_project( Circulator j) : nt(j) {}
49 
50   // OPERATIONS Forward Category
51   // ---------------------------
52 
current_circulator()53   Circulator  current_circulator() const { return nt;}
ptr()54   Ptr ptr() const {
55     Fct fct;
56     return &(fct(*nt));
57   }
58 
59   bool operator==( std::nullptr_t CGAL_assertion_code(p) ) const {
60     CGAL_assertion( p == 0);
61     return ( nt == 0);
62   }
63   bool  operator!=( std::nullptr_t p) const { return !(*this == p); }
64   bool  operator==( const Self& i) const { return ( nt == i.nt); }
65   bool  operator!=( const Self& i) const { return !(*this == i); }
66   Ref   operator*()  const { return *ptr(); }
67   Ptr   operator->() const { return ptr(); }
68   Self& operator++() {
69     ++nt;
70     return *this;
71   }
72   Self  operator++(int) {
73     Self tmp = *this;
74     ++*this;
75     return tmp;
76   }
77 
78   // OPERATIONS Bidirectional Category
79   // ---------------------------------
80 
81   Self& operator--() {
82     --nt;
83     return *this;
84   }
85   Self  operator--(int) {
86     Self tmp = *this;
87     --*this;
88     return tmp;
89   }
90 
91   // OPERATIONS Random Access Category
92   // ---------------------------------
93 
min_circulator()94   Self  min_circulator() const {
95     return Self( nt.min_circulator());
96   }
97   Self& operator+=( difference_type n) {
98     nt += n;
99     return *this;
100   }
101   Self  operator+( difference_type n) const {
102     Self tmp = *this;
103     return tmp += n;
104   }
105   Self& operator-=( difference_type n) {
106     return operator+=( -n);
107   }
108   Self  operator-( difference_type n) const {
109     Self tmp = *this;
110     return tmp += -n;
111   }
112   difference_type  operator-( const Self& i) const {
113     return nt - i.nt;
114   }
115   Ref  operator[]( difference_type n) const {
116     Self tmp = *this;
117     tmp += n;
118     return tmp.operator*();
119   }
120 };
121 
122 template < class Dist, class Fct, class C, class Ref, class Ptr>
123 inline
124 Circulator_project<C,Fct,Ref,Ptr>
125 operator+( Dist n, Circulator_project<C,Fct,Ref,Ptr> i) { return i += n; }
126 
127 } //namespace CGAL
128 #endif // CGAL_CIRCULATOR_PROJECT_H //
129 // EOF //
130