// Copyright (c) 2019 GeometryFactory (France). All rights reserved. // // This file is part of CGAL (www.cgal.org); you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public License as // published by the Free Software Foundation; either version 3 of the License, // or (at your option) any later version. // // Licensees holding a valid commercial license may use this file in // accordance with the commercial license agreement provided with the software. // // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. // // $URL$ // $Id$ // SPDX-License-Identifier: LGPL-3.0+ // // // Author(s) : Sebastien Loriot #ifndef CGAL_BOOST_GRAPH_NAMED_FUNCTION_PARAMS_H #define CGAL_BOOST_GRAPH_NAMED_FUNCTION_PARAMS_H #include #include #include #define CGAL_BGL_NP_TEMPLATE_PARAMETERS T, typename Tag, typename Base #define CGAL_BGL_NP_CLASS CGAL::Named_function_parameters namespace CGAL { namespace internal_np{ struct No_property {}; struct Param_not_found {}; enum all_default_t { all_default }; // 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 template struct Named_params_impl : Base { T v; // copy of the parameter Named_params_impl(T v, const Base& b) : Base(b) , v(v) {} }; // partial specialization for base class of the recursive nesting template struct Named_params_impl { T v; // copy of the parameter Named_params_impl(T v) : v(v) {} }; // Helper class to get the type of a named parameter pack given a query tag template struct Get_param; template< typename T, typename Tag, typename Query_tag> struct Get_param< Named_params_impl, Query_tag > { typedef Param_not_found type; }; template< typename T, typename Tag, typename Base> struct Get_param< Named_params_impl, Tag > { typedef T type; }; template< typename T, typename Tag> struct Get_param< Named_params_impl, Tag > { typedef T type; }; template< typename T, typename Tag, typename Base, typename Query_tag> struct Get_param< Named_params_impl, Query_tag> { typedef typename Get_param::type type; }; // helper to choose the default template struct Lookup_named_param_def { typedef typename internal_np::Get_param::type NP_type; typedef typename boost::mpl::if_< boost::is_same, D, NP_type>::type type; }; // helper function to extract the value from a named parameter pack given a query tag template T get_parameter_impl(const Named_params_impl& np, Tag) { return np.v; } template< typename T, typename Tag, typename Query_tag> Param_not_found get_parameter_impl(const Named_params_impl&, Query_tag) { return Param_not_found(); } template< typename T, typename Tag> T get_parameter_impl(const Named_params_impl& np, Tag) { return np.v; }; template typename Get_param, Query_tag>::type get_parameter_impl(const Named_params_impl& np, Query_tag tag) { CGAL_static_assertion( (!boost::is_same::value) ); return get_parameter_impl(static_cast(np), tag); } } // end of internal_np namespace template struct Named_function_parameters : internal_np::Named_params_impl { typedef internal_np::Named_params_impl base; typedef Named_function_parameters self; Named_function_parameters(T v = T()) : base(v) {} Named_function_parameters(T v, const Base& b) : base(v, b) {} Named_function_parameters all_default() const { typedef Named_function_parameters Params; return Params(*this); } // create the functions for new named parameters and the one imported boost // used to concatenate several parameters #define CGAL_add_named_parameter(X, Y, Z) \ template \ Named_function_parameters \ Z(const K& k) const \ { \ typedef Named_function_parameters Params;\ return Params(k, *this); \ } #include #undef CGAL_add_named_parameter }; namespace parameters { Named_function_parameters inline all_default() { typedef Named_function_parameters Params; return Params(); } template Named_function_parameters inline no_parameters(Named_function_parameters) { typedef Named_function_parameters Params; return Params(); } // define free functions for named parameters #define CGAL_add_named_parameter(X, Y, Z) \ template \ Named_function_parameters \ Z(K const& p) \ { \ typedef Named_function_parameters Params;\ return Params(p); \ } #include #undef CGAL_add_named_parameter // function to extract a parameter template typename internal_np::Get_param, Query_tag>::type get_parameter(const Named_function_parameters& np, Query_tag tag) { return internal_np::get_parameter_impl(static_cast&>(np), tag); } template D choose_parameter(const internal_np::Param_not_found&, const D& d) { return d; } template const T& choose_parameter(const T& t, const D&) { return t; } bool inline is_default_parameter(const internal_np::Param_not_found&) { return true; } template bool is_default_parameter(const T&) { return false; } } // end of parameters namespace } //namespace CGAL #endif // CGAL_BOOST_GRAPH_NAMED_FUNCTION_PARAMS_HPP