From 68044a6ede1f16fbf5184afff2364863cf5c73e2 Mon Sep 17 00:00:00 2001 From: Lingjie Zhu Date: Fri, 18 Aug 2017 22:46:00 +0800 Subject: [PATCH] add named function parameters --- .../named_function_params.h | 101 ++++++++++++++++++ .../parameters_interface.h | 8 ++ 2 files changed, 109 insertions(+) create mode 100644 Surface_mesh_approximation/include/CGAL/internal/Surface_mesh_approximation/named_function_params.h create mode 100644 Surface_mesh_approximation/include/CGAL/internal/Surface_mesh_approximation/parameters_interface.h diff --git a/Surface_mesh_approximation/include/CGAL/internal/Surface_mesh_approximation/named_function_params.h b/Surface_mesh_approximation/include/CGAL/internal/Surface_mesh_approximation/named_function_params.h new file mode 100644 index 00000000000..0cd97fc5169 --- /dev/null +++ b/Surface_mesh_approximation/include/CGAL/internal/Surface_mesh_approximation/named_function_params.h @@ -0,0 +1,101 @@ +#ifndef CGAL_VSA_BGL_NAMED_FUNCTION_PARAMS_H +#define CGAL_VSA_BGL_NAMED_FUNCTION_PARAMS_H + +#include + +namespace CGAL{ +namespace internal_np{ + +// define enum types and values for new named parameters +#define CGAL_add_named_parameter(X, Y, Z) \ + enum X { Y }; +#include +#undef CGAL_add_named_parameter + +}//internal_np + + template + struct vsa_bgl_named_params + : CGAL::cgal_bgl_named_params + { + typedef CGAL::cgal_bgl_named_params base; + typedef vsa_bgl_named_params self; + + vsa_bgl_named_params(T v = T()) : base(v) {} + vsa_bgl_named_params(T v, const Base& b) : base(v, b) {} + +// define the functions for new named parameters and the one imported from BGL and boost +// used to concatenate several parameters +#define CGAL_add_named_parameter(X, Y, Z) \ + template \ + vsa_bgl_named_params \ + Z(const K& k) const \ + { \ + typedef vsa_bgl_named_params Params; \ + return Params(k, *this); \ + } +#include +#include +#include +#undef CGAL_add_named_parameter + }; + +namespace VSA{ + +namespace parameters{ + +// define free functions for new named parameters and the one imported from BGL and boost +#define CGAL_add_named_parameter(X, Y, Z) \ + template \ + vsa_bgl_named_params \ + Z(const K& k) \ + { \ + typedef vsa_bgl_named_params Params; \ + return Params(k); \ + } +#include +#include +#include +#undef CGAL_add_named_parameter +} //namespace parameters +} //namespace VSA + +} //namespace CGAL + +// partial specializations hate inheritance and we need to repeat +// those here. this is rather fragile. +namespace boost { +#if BOOST_VERSION < 105100 + template + inline + typename property_value< CGAL::vsa_bgl_named_params, Tag2>::type + get_param(const CGAL::vsa_bgl_named_params& p, Tag2 tag2) + { + enum { match = detail::same_property::value }; + typedef typename + boost::property_value< CGAL::vsa_bgl_named_params, Tag2>::type T2; + T2* t2 = 0; + typedef detail::property_value_dispatch Dispatcher; + return Dispatcher::const_get_value(p, t2, tag2); + } +#endif + + template + struct lookup_named_param_def, Def> { + typedef T type; + static const type& get(const bgl_named_params& p, const Def&) { + return p.m_value; + } + }; + + template + struct lookup_named_param_def, Def> { + typedef typename lookup_named_param_def::type type; + static const type& get(const bgl_named_params& p, const Def& def) { + return lookup_named_param_def::get(p.m_base, def); + } + }; + +} // boost + +#endif //CGAL_VSA_BGL_NAMED_FUNCTION_PARAMS_H diff --git a/Surface_mesh_approximation/include/CGAL/internal/Surface_mesh_approximation/parameters_interface.h b/Surface_mesh_approximation/include/CGAL/internal/Surface_mesh_approximation/parameters_interface.h new file mode 100644 index 00000000000..24f223f021f --- /dev/null +++ b/Surface_mesh_approximation/include/CGAL/internal/Surface_mesh_approximation/parameters_interface.h @@ -0,0 +1,8 @@ +// List of named parameters used in the Polygon Mesh Processing package +// CGAL_add_named_parameter(geom_traits_t, geom_traits, geom_traits) +CGAL_add_named_parameter(number_of_iterations_t, number_of_iterations, number_of_iterations) +CGAL_add_named_parameter(number_of_proxies_t, number_of_proxies, number_of_proxies) +CGAL_add_named_parameter(face_area_t, face_area, face_area_map) +CGAL_add_named_parameter(face_normal_t, face_normal, face_normal_map) +CGAL_add_named_parameter(face_center_t, face_center, face_center_map) +CGAL_add_named_parameter(face_proxy_t, face_proxy, face_proxy_map)