1 // Copyright (c) 2010-2011 CNRS and LIRIS' Establishments (France).
2 // All rights reserved.
3 //
4 // This file is part of CGAL (www.cgal.org)
5 //
6 // $URL: https://github.com/CGAL/cgal/blob/v5.3/Combinatorial_map/include/CGAL/Dart.h $
7 // $Id: Dart.h d6306be 2020-10-22T10:30:38+02:00 Guillaume Damiand
8 // SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial
9 //
10 // Author(s)     : Guillaume Damiand <guillaume.damiand@liris.cnrs.fr>
11 //
12 #ifndef CGAL_DART_H
13 #define CGAL_DART_H 1
14 
15 #include <CGAL/assertions.h>
16 #include <CGAL/tags.h>
17 #include <CGAL/tuple.h>
18 #include <bitset>
19 #include <CGAL/Cell_attribute.h>
20 
21 namespace CGAL {
22 
23   template <class, class, class, class>
24   class Compact_container;
25 
26   template <class, class>
27   class Concurrent_compact_container;
28 
29   template<unsigned int, class, class, class>
30   class Combinatorial_map_storage_1;
31 
32   template<unsigned int, class, class, class>
33   class Generalized_map_storage_1;
34 
35   template<unsigned int, unsigned int, class, class, class, class>
36   class CMap_linear_cell_complex_storage_1;
37 
38   template<unsigned int, unsigned int, class, class, class, class>
39   class GMap_linear_cell_complex_storage_1;
40 
41   namespace internal {
42 
43   template<class, class>
44   struct Init_id;
45 
46   } // end namespace internal
47 
48   /** @file Dart.h
49    * Definition of nD dart.
50    */
51 
52   /** Definition of nD dart without information.
53    * The_dart class describes an nD dart (basic element of a combinatorial or generalized map).
54    * A dart is composed with handle towards its neighbors,
55    * a bitset containing Boolean marks, and handle towards enabled attributes.
56    * n is the dimension of the space (2 for 2D, 3 for 3D...)
57    * Refs the ref class
58    */
59   template <unsigned int d, typename Refs, class WithId>
60   struct Dart_without_info: public Add_id<WithId>
61   {
62   public:
63     template<unsigned int, class, class, class>
64     friend class Combinatorial_map_storage_1;
65 
66     template<unsigned int, class, class, class>
67     friend class Generalized_map_storage_1;
68 
69     template<unsigned int, unsigned int, class, class, class, class>
70     friend class CMap_linear_cell_complex_storage_1;
71 
72     template<unsigned int, unsigned int, class, class, class, class>
73     friend class GMap_linear_cell_complex_storage_1;
74 
75     template <class, class, class, class>
76     friend class Compact_container;
77 
78     template <class, class>
79     friend class Concurrent_compact_container;
80 
81     template<class, class>
82     friend struct internal::Init_id;
83 
84     typedef Dart_without_info<d,Refs, WithId> Self;
85     typedef typename Refs::Dart_handle        Dart_handle;
86     typedef typename Refs::size_type          size_type;
87     typedef typename Refs::Dart_const_handle  Dart_const_handle;
88     typedef typename Refs::Helper             Helper;
89     typedef WithId                            Has_id;
90 
91     /// Typedef for attributes
92     template<int i>
93     struct Attribute_handle: public Refs::template Attribute_handle<i>
94     {};
95     template<int i>
96     struct Attribute_const_handle:
97       public Refs::template Attribute_const_handle<i>
98     {};
99 
100     /// The number of used marks.
101     static const size_type NB_MARKS = Refs::NB_MARKS;
102 
103     /// The dimension of the combinatorial map.
104     static const unsigned int dimension = d;
105 
for_compact_containerDart_without_info106     void * for_compact_container() const
107     { return mf[0].for_compact_container(); }
for_compact_containerDart_without_info108     void for_compact_container(void *p)
109     { mf[0].for_compact_container(p); }
110 
get_fDart_without_info111     Dart_handle get_f(unsigned int i) const
112     {
113       assert(i<=dimension);
114       return mf[i];
115     }
116 
117   protected:
118     /** Default constructor: no real initialisation,
119      *  because this is done in the combinatorial map class.
120      */
Dart_without_infoDart_without_info121     Dart_without_info()
122     {}
123 
124     /** Copy constructor:
125      * @param adart a dart.
126      */
Dart_without_infoDart_without_info127     Dart_without_info(const Dart_without_info& adart) : mmarks(adart.mmarks),
128     mattribute_handles(adart.mattribute_handles)
129     {
130       for (unsigned int i = 0; i <= dimension; ++i)
131         mf[i] = adart.mf[i];
132     }
133 
134     /** Return the mark value of a given mark number.
135      * @param amark the mark number.
136      * @return the value for this number.
137      */
get_markDart_without_info138     bool get_mark(size_type amark) const
139     {
140       CGAL_assertion(amark>=0 && amark<NB_MARKS);
141       return mmarks[amark];
142     }
143 
144     /** Set the mark of a given mark number to a given value.
145      * @param amark the mark number.
146      * @param AValue the value.
147      */
set_markDart_without_info148     void set_mark(size_type amark, bool avalue) const
149     {
150       CGAL_assertion(amark>=0 && amark<NB_MARKS);
151       mmarks.set(amark, avalue);
152     }
153     /** Flip the mark of a given mark number.
154      * @param amark the mark number.
155      */
flip_markDart_without_info156     void flip_mark(size_type amark) const
157     {
158       CGAL_assertion(amark>=0 && amark<NB_MARKS);
159       mmarks.flip(amark);
160     }
161 
162     /** Return all the marks of this dart.
163      * @return the marks.
164      */
get_marksDart_without_info165      std::bitset<NB_MARKS> get_marks() const
166     { return mmarks; }
167 
168     /** Set simultaneously all the marks of this dart to a given value.
169      * @param amarks the value of the marks.
170      */
set_marksDart_without_info171      void set_marks(const std::bitset<NB_MARKS>& amarks) const
172     { mmarks = amarks; }
173 
174     /// @return a handle on the i-attribute
175     template<int i>
attributeDart_without_info176     typename Attribute_handle<i>::type attribute()
177     {
178       CGAL_static_assertion_msg(Helper::template Dimension_index<i>::value>=0,
179                      "attribute<i> called but i-attributes are disabled.");
180       return std::get<Helper::template Dimension_index<i>::value>
181         (mattribute_handles);
182     }
183     template<int i>
attributeDart_without_info184     typename Attribute_const_handle<i>::type attribute() const
185     {
186       CGAL_static_assertion_msg(Helper::template Dimension_index<i>::value>=0,
187                      "attribute<i> called but i-attributes are disabled.");
188       return std::get<Helper::template Dimension_index<i>::value>
189         (mattribute_handles);
190     }
191 
192   protected:
193     /// Neighboors for each dimension +1 (from 0 to dimension).
194     Dart_handle mf[dimension+1];
195 
196     /// Values of Boolean marks.
197     mutable std::bitset<NB_MARKS> mmarks;
198 
199     /// Attributes enabled
200     typename Helper::Attribute_handles mattribute_handles;
201   };
202 
203 #if defined(CGAL_CMAP_DART_DEPRECATED) && !defined(CGAL_NO_DEPRECATED_CODE)
204 
205 #define CGAL_BETAINV(i) (i>1?i:(i==1?0:1))
206 
207   /** Definition of nD dart for combinatorial map. Add functions beta and attributes which
208    * are now deprecated.
209    */
210   template <unsigned int d, typename Refs, class WithID=Tag_false>
211   struct CGAL_DEPRECATED Dart : public Dart_without_info<d, Refs, WithID>
212   {
213     template<unsigned int, class, class, class>
214     friend class Combinatorial_map_storage_1;
215 
216     template<unsigned int, unsigned int, class, class, class, class>
217     friend class CMap_linear_cell_complex_storage_1;
218 
219     template <class, class, class, class>
220     friend class Compact_container;
221 
222     template <class, class>
223     friend class Concurrent_compact_container;
224 
225     typedef Dart_without_info<d, Refs, WithID> Base;
226 
227     using Base::dimension;
228     using Base::mf;
229     using Base::mattribute_handles;
230 
231     typedef typename Base::Dart_handle Dart_handle;
232     typedef typename Base::Dart_const_handle Dart_const_handle;
233     typedef typename Base::Helper Helper;
234 
235     /// Typedef for attributes
236     template<int i>
237     struct Attribute_handle: public Refs::template Attribute_handle<i>
238     {};
239     template<int i>
240     struct Attribute_const_handle:
241       public Refs::template Attribute_const_handle<i>
242     {};
243 
244   public:
245     /** Return the beta of this dart for a given dimension.
246      * @param i the dimension.
247      * @return beta(\em i).
248      */
249     template<unsigned int i>
betaDart250     Dart_handle beta()
251     {
252       CGAL_assertion(i <= dimension);
253       return mf[i];
254     }
betaDart255     Dart_handle beta(unsigned int i)
256     {
257       CGAL_assertion(i <= dimension);
258       return mf[i];
259     }
260     template<unsigned int i>
betaDart261     Dart_const_handle beta() const
262     {
263       CGAL_assertion(i <= dimension);
264       return mf[i];
265     }
betaDart266     Dart_const_handle beta(unsigned int i) const
267     {
268       CGAL_assertion(i <= dimension);
269       return mf[i];
270     }
271 
272     /** Return the beta inverse of this dart for a given dimension.
273      * @param i the dimension.
274      * @return beta^{-1}(\em i).
275      */
276     template<unsigned int i>
beta_invDart277     Dart_handle beta_inv()
278     { return beta<CGAL_BETAINV(i)>(); }
beta_invDart279     Dart_handle beta_inv(unsigned int i)
280     { return beta(CGAL_BETAINV(i)); }
281     template<unsigned int i>
beta_invDart282     Dart_const_handle beta_inv() const
283     { return beta<CGAL_BETAINV(i)>(); }
beta_invDart284     Dart_const_handle beta_inv(unsigned int i) const
285     { return beta(CGAL_BETAINV(i)); }
286 
287     /// @return a handle on the i-attribute
288     template<int i>
attributeDart289     typename Attribute_handle<i>::type attribute()
290     {
291       CGAL_static_assertion_msg(Helper::template Dimension_index<i>::value>=0,
292                      "attribute<i> called but i-attributes are disabled.");
293       return std::get<Helper::template Dimension_index<i>::value>
294         (mattribute_handles);
295     }
296     template<int i>
attributeDart297     typename Attribute_const_handle<i>::type attribute() const
298     {
299       CGAL_static_assertion_msg(Helper::template Dimension_index<i>::value>=0,
300                      "attribute<i> called but i-attributes are disabled.");
301       return std::get<Helper::template Dimension_index<i>::value>
302         (mattribute_handles);
303     }
304   };
305 #else // CGAL_CMAP_DART_DEPRECATED
306   // Dart definition with an info;
307   //  (there is a specialization below when Info_==void)
308   template <unsigned int d, typename Refs, typename Info_=void,
309             class WithID=Tag_false>
310   struct Dart : public Dart_without_info<d, Refs, WithID>
311   {
312   public:
313     template<unsigned int, class, class, class>
314     friend class Combinatorial_map_storage_1;
315 
316     template<unsigned int, class, class, class>
317     friend class Generalized_map_storage_1;
318 
319     template<unsigned int, unsigned int, class, class, class, class>
320     friend class CMap_linear_cell_complex_storage_1;
321 
322     template<unsigned int, unsigned int, class, class, class, class>
323     friend class GMap_linear_cell_complex_storage_1;
324 
325     template <class, class, class, class>
326     friend class Compact_container;
327 
328     template <class, class>
329     friend class Concurrent_compact_container;
330 
331     typedef Dart<d, Refs, Info_, WithID> Self;
332     typedef Info_                        Info;
333 
334   protected:
335     /** Default constructor: no real initialisation,
336      *  because this is done in the combinatorial or generalized map class.
337      */
DartDart338     Dart()
339     {}
340 
DartDart341     Dart(const Info_& info) : minfo(info)
342     {}
343 
infoDart344     Info_& info()
345     { return minfo; }
infoDart346     const Info_& info() const
347     { return minfo; }
348 
349   protected:
350     Info minfo;
351   };
352 
353   // Specialization of Dart class when info==void
354   template <unsigned int d, typename Refs, class WithID>
355   struct Dart<d, Refs, void, WithID> : public Dart_without_info<d, Refs, WithID>
356   {
357   public:
358     typedef CGAL::Void Info;
359   };
360 
361 #endif // CGAL_CMAP_DART_DEPRECATED
362 
363 } // namespace CGAL
364 
365 #endif // CGAL_DART_H //
366 // EOF //
367