1 // Copyright (c) 2012  INRIA Sophia-Antipolis (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/AABB_tree/include/CGAL/internal/AABB_tree/Primitive_helper.h $
7 // $Id: Primitive_helper.h 0779373 2020-03-26T13:31:46+01:00 Sébastien Loriot
8 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial
9 //
10 // Author(s) : Sebastien Loriot
11 
12 #ifndef CGAL_INTERNAL_AABB_TREE_PRIMITIVE_HELPER
13 #define CGAL_INTERNAL_AABB_TREE_PRIMITIVE_HELPER
14 
15 #include <CGAL/license/AABB_tree.h>
16 
17 
18 #include <CGAL/internal/AABB_tree/Has_nested_type_Shared_data.h>
19 #include <boost/mpl/has_xxx.hpp>
20 
21 namespace CGAL{
22 namespace internal{
23 
24 //for backward compatibility: if Datum_reference and Point_reference are not defined in the primitive
25 //(using auto would solve the pb)
26 BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(Has_nested_type_Datum_reference,Datum_reference,false)
27 BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(Has_nested_type_Point_reference,Point_reference,false)
28 
29 template<class Primitive,bool has_nested_type=Has_nested_type_Datum_reference<Primitive>::value>
30 struct Datum_result_type{ typedef typename Primitive::Datum_reference type; };
31 template<class Primitive>
32 struct Datum_result_type<Primitive,false>{ typedef typename Primitive::Datum type; };
33 template<class Primitive,bool has_nested_type=Has_nested_type_Point_reference<Primitive>::value>
34 struct Point_result_type{ typedef typename Primitive::Point_reference type; };
35 template<class Primitive>
36 struct Point_result_type<Primitive,false>{ typedef typename Primitive::Point type; };
37 
38 
39 //helper controlling whether extra data should be stored in the AABB_tree traits class
40 template <class AABBTraits, bool has_shared_data=Has_nested_type_Shared_data<typename AABBTraits::Primitive>::value>
41 struct Primitive_helper;
42 
43 template <class AABBTraits>
44 struct Primitive_helper<AABBTraits,true>{
45   typedef typename Datum_result_type<typename AABBTraits::Primitive>::type Datum_type;
46   static Datum_type get_datum(const typename AABBTraits::Primitive& p,const AABBTraits& traits)
47   {
48     return p.datum(traits.shared_data());
49   }
50   typedef typename Point_result_type<typename AABBTraits::Primitive>::type Reference_point_type;
51   static Reference_point_type get_reference_point(const typename AABBTraits::Primitive& p,const AABBTraits& traits) {
52     return p.reference_point(traits.shared_data());
53   }
54 };
55 
56 template <class AABBTraits>
57 struct Primitive_helper<AABBTraits,false>{
58   typedef typename Datum_result_type<typename AABBTraits::Primitive>::type Datum_type;
59   static Datum_type get_datum(const typename AABBTraits::Primitive& p,const AABBTraits&) {return p.datum();}
60   typedef typename Point_result_type<typename AABBTraits::Primitive>::type Reference_point_type;
61   static Reference_point_type get_reference_point(const typename AABBTraits::Primitive& p,const AABBTraits&) {return p.reference_point();}
62 };
63 
64 } } //namespace CGAL::internal
65 
66 #endif //CGAL_INTERNAL_AABB_TREE_PRIMITIVE_HELPER
67