1 // Copyright (c) 2013 Tel-Aviv University (Israel).
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/Arrangement_on_surface_2/include/CGAL/Arr_point_location_result.h $
7 // $Id: Arr_point_location_result.h 0626eb0 2020-06-11T12:32:33+03:00 Efi Fogel
8 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial
9 //
10 // Author(s) : Efi Fogel   <efif@post.tau.ac.il>
11 
12 #ifndef CGAL_ARR_POINT_LOCATION_RESULT_H
13 #define CGAL_ARR_POINT_LOCATION_RESULT_H
14 
15 #include <CGAL/license/Arrangement_on_surface_2.h>
16 
17 #include <CGAL/disable_warnings.h>
18 
19 // The macro CGAL_ARR_POINT_LOCATION_VERSION controls which version of the
20 // point location is used. Currently two values are supported:
21 // 1. Point location with CGAL::Object
22 // 2. Point location with boost::optional<boost::variant<...> >
23 // The default value is 2.
24 
25 #if !defined(CGAL_ARR_POINT_LOCATION_VERSION)
26 #define CGAL_ARR_POINT_LOCATION_VERSION 2
27 #endif
28 
29 #include <CGAL/Object.h>
30 
31 #include <boost/optional.hpp>
32 #include <boost/variant.hpp>
33 
34 #ifdef CGAL_CFG_BOOST_VARIANT_SWAP_BUG
35 #if CGAL_ARR_POINT_LOCATION_VERSION > 1
36 #include <CGAL/Arrangement_2/Arrangement_2_iterators.h>
37 // workaround for this bug:
38 // https://svn.boost.org/trac/boost/ticket/2839
39 namespace boost{ namespace detail { namespace variant {
40 
41 template <class CI, class F, class MI, class V, class D, class C>
move_swap(::CGAL::I_Filtered_const_iterator<CI,F,MI,V,D,C> & lhs,::CGAL::I_Filtered_const_iterator<CI,F,MI,V,D,C> & rhs)42 inline void move_swap(
43   ::CGAL::I_Filtered_const_iterator<CI, F, MI, V, D, C>& lhs,
44   ::CGAL::I_Filtered_const_iterator<CI, F, MI,  V, D, C>& rhs)
45 {
46     ::CGAL::I_Filtered_const_iterator<CI, F, MI, V, D, C> tmp( boost::detail::variant::move(lhs) );
47     lhs = boost::detail::variant::move(rhs);
48     rhs = boost::detail::variant::move(tmp);
49 }
50 } } }
51 #endif
52 #endif
53 
54 namespace CGAL {
55 
56 template <typename Arrangement_>
57 struct Arr_point_location_result {
58   typedef Arrangement_                                   Arrangement_2;
59 
60   typedef typename Arrangement_2::Vertex_const_handle    Vertex_const_handle;
61   typedef typename Arrangement_2::Halfedge_const_handle  Halfedge_const_handle;
62   typedef typename Arrangement_2::Face_const_handle      Face_const_handle;
63 
64 #if CGAL_ARR_POINT_LOCATION_VERSION < 2
65   typedef CGAL::Object                                   Type;
66 #else
67   typedef typename boost::variant<Vertex_const_handle,
68                                   Halfedge_const_handle,
69                                   Face_const_handle>     Type;
70 #endif
71   typedef Type                                           type;
72 
73   // This function returns either make_object() or a result_type constructor
74   // to generate return values. The Object version takes a dummy template
75   // argument, which is needed for the return of the other option, e.g.,
76   // boost::optional<boost::variant> >.
77   // In theory a one parameter variant could be returned, but this _could_
78   // lead to conversion overhead, and so we rather go for the real type.
79   // Overloads for empty returns are also provided.
80 #if CGAL_ARR_POINT_LOCATION_VERSION < 2
81   template <typename T>
82   static
make_resultArr_point_location_result83   inline Type make_result(T t) { return CGAL::make_object(t); }
84 
85   static
empty_optional_resultArr_point_location_result86   inline CGAL::Object empty_optional_result() { return CGAL::Object(); }
87 
88   template <typename T>
89   static
assignArr_point_location_result90   inline const T* assign(const Type* obj) { return CGAL::object_cast<T>(obj); }
91 #else
92   template <typename T>
93   static
make_resultArr_point_location_result94   inline Type make_result(T t) { return Type(t); }
95 
96   static
empty_optional_resultArr_point_location_result97   inline boost::optional<Type> empty_optional_result()
98   { return boost::optional<Type>(); }
99 
100   template <typename T>
101   static
assignArr_point_location_result102   inline const T* assign(const Type* obj) { return boost::get<T>(obj); }
103 #endif // CGAL_ARR_POINT_LOCATION_VERSION < 2
104 
105   //this one is only to remove warnings in functions
106   static
default_resultArr_point_location_result107   inline Type default_result(){
108     CGAL_error_msg("This functions should have never been called!");
109     return Type();
110   }
111 };
112 
113 } //namespace CGAL
114 
115 #include <CGAL/enable_warnings.h>
116 
117 #endif
118