From 2103e691dba0991e9bd9bcbd3aad6418fe30b1b4 Mon Sep 17 00:00:00 2001 From: Dave Abrahams Date: Thu, 8 Aug 2002 15:45:58 +0000 Subject: [PATCH] initial commit [SVN r14738] --- include/boost/python/detail/def_helper.hpp | 61 ++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 include/boost/python/detail/def_helper.hpp diff --git a/include/boost/python/detail/def_helper.hpp b/include/boost/python/detail/def_helper.hpp new file mode 100644 index 00000000..1222f71b --- /dev/null +++ b/include/boost/python/detail/def_helper.hpp @@ -0,0 +1,61 @@ +// Copyright David Abrahams 2002. Permission to copy, use, +// modify, sell and distribute this software is granted provided this +// copyright notice appears in all copies. This software is provided +// "as is" without express or implied warranty, and with no claim as +// to its suitability for any purpose. +#ifndef DEF_HELPER_DWA200287_HPP +# define DEF_HELPER_DWA200287_HPP + +# include +# include +# include + +namespace boost { namespace python { namespace detail { + +// +// def_helper -- +// +// A helper for def() functions which determines how to interpret +// an argument of type T which could be either CallPolicies or a +// string literal representing a docstring. +// +// Generates two static functions: +// +// get_policy(x), where x is of type T, returns a policies +// object: either a reference to x or default_call_policies() +// if x is a string literal. +// +// get_doc(x, s), where s convertible to char const*, returns x +// if x is a string literal, s otherwise. + +template +struct def_helper_impl +{ + template + static P const& get_policy(P const& x) { return x; } + + template + static char const* get_doc(P const&, char const* doc) { return doc; } +}; + +template <> +struct def_helper_impl +{ + static python::default_call_policies get_policy(char const*) { return default_call_policies(); } + static char const* get_doc(char const* doc, char const*) { return doc; } +}; + +template +struct def_helper + : def_helper_impl< + type_traits::ice_or< + is_string_literal::value + , is_same::value + , is_same::value +>::value +> +{}; + +}}} // namespace boost::python::detail + +#endif // DEF_HELPER_DWA200287_HPP