From 6d7d2ea5fe823f830ff135c14bc8c41f93d8b47a Mon Sep 17 00:00:00 2001 From: Dave Abrahams Date: Tue, 25 Feb 2003 03:31:36 +0000 Subject: [PATCH] initial checkin [SVN r17626] --- .../python/converter/shared_ptr_to_python.hpp | 26 ++++++++ include/boost/python/detail/is_auto_ptr.hpp | 31 +++++++++ include/boost/python/detail/is_xxx.hpp | 59 +++++++++++++++++ .../python/detail/value_is_shared_ptr.hpp | 18 ++++++ include/boost/python/detail/value_is_xxx.hpp | 63 +++++++++++++++++++ 5 files changed, 197 insertions(+) create mode 100644 include/boost/python/converter/shared_ptr_to_python.hpp create mode 100644 include/boost/python/detail/is_auto_ptr.hpp create mode 100644 include/boost/python/detail/is_xxx.hpp create mode 100644 include/boost/python/detail/value_is_shared_ptr.hpp create mode 100644 include/boost/python/detail/value_is_xxx.hpp diff --git a/include/boost/python/converter/shared_ptr_to_python.hpp b/include/boost/python/converter/shared_ptr_to_python.hpp new file mode 100644 index 00000000..0002fa91 --- /dev/null +++ b/include/boost/python/converter/shared_ptr_to_python.hpp @@ -0,0 +1,26 @@ +// Copyright David Abrahams 2003. 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 SHARED_PTR_TO_PYTHON_DWA2003224_HPP +# define SHARED_PTR_TO_PYTHON_DWA2003224_HPP + +# include +# include +# include + +namespace boost { namespace python { namespace converter { + +template +PyObject* shared_ptr_to_python(shared_ptr const& x) +{ + if (shared_ptr_deleter* d = boost::get_deleter(x)) + return incref(d->owner.get()); + else + return converter::registered const&>::converters.to_python(&x); +} + +}}} // namespace boost::python::converter + +#endif // SHARED_PTR_TO_PYTHON_DWA2003224_HPP diff --git a/include/boost/python/detail/is_auto_ptr.hpp b/include/boost/python/detail/is_auto_ptr.hpp new file mode 100644 index 00000000..9602a8d4 --- /dev/null +++ b/include/boost/python/detail/is_auto_ptr.hpp @@ -0,0 +1,31 @@ +// Copyright David Abrahams 2003. 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 IS_AUTO_PTR_DWA2003224_HPP +# define IS_AUTO_PTR_DWA2003224_HPP + +# ifndef BOOST_NO_AUTO_PTR +# include +# include +# endif + +namespace boost { namespace python { namespace detail { + +# if !defined(BOOST_NO_AUTO_PTR) + +BOOST_PYTHON_IS_XXX_DEF(auto_ptr, std::auto_ptr, 1) + +# else + +template +struct is_auto_ptr : mpl::false_c +{ +}; + +# endif + +}}} // namespace boost::python::detail + +#endif // IS_AUTO_PTR_DWA2003224_HPP diff --git a/include/boost/python/detail/is_xxx.hpp b/include/boost/python/detail/is_xxx.hpp new file mode 100644 index 00000000..6510adc8 --- /dev/null +++ b/include/boost/python/detail/is_xxx.hpp @@ -0,0 +1,59 @@ +// Copyright David Abrahams 2003. 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 IS_XXX_DWA2003224_HPP +# define IS_XXX_DWA2003224_HPP + +# include +# include +# include + +# if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) +# include + +# define BOOST_PYTHON_IS_XXX_DEF(name, qualified_name, nargs) \ +template \ +struct is_##name \ +{ \ + typedef char yes; \ + typedef char (&no)[2]; \ + \ + static X_ dummy; \ + \ + template < BOOST_PP_ENUM_PARAMS_Z(1, nargs, class U) > \ + static yes test( \ + qualified_name< BOOST_PP_ENUM_PARAMS_Z(1, nargs, U) >&, int \ + ); \ + \ + template \ + static no test(U&, ...); \ + \ + BOOST_STATIC_CONSTANT( \ + bool, value \ + = !is_reference::value \ + & (sizeof(test(dummy, 0)) == sizeof(yes))); \ + \ + typedef mpl::bool_c type; \ +}; + +# else + +# define BOOST_PYTHON_IS_XXX_DEF(name, qualified_name, nargs) \ +template \ +struct is_##name : mpl::false_c \ +{ \ +}; \ + \ +template < BOOST_PP_ENUM_PARAMS_Z(1, nargs, class T) > \ +struct is_##name< \ + qualified_name< BOOST_PP_ENUM_PARAMS_Z(1, nargs, T) > \ +> \ + : mpl::true_c \ +{ \ +}; + +# endif + +#endif // IS_XXX_DWA2003224_HPP diff --git a/include/boost/python/detail/value_is_shared_ptr.hpp b/include/boost/python/detail/value_is_shared_ptr.hpp new file mode 100644 index 00000000..5d2c8abe --- /dev/null +++ b/include/boost/python/detail/value_is_shared_ptr.hpp @@ -0,0 +1,18 @@ +// Copyright David Abrahams 2003. 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 VALUE_IS_SHARED_PTR_DWA2003224_HPP +# define VALUE_IS_SHARED_PTR_DWA2003224_HPP + +# include +# include + +namespace boost { namespace python { namespace detail { + +BOOST_PYTHON_VALUE_IS_XXX_DEF(shared_ptr, shared_ptr, 1) + +}}} // namespace boost::python::detail + +#endif // VALUE_IS_SHARED_PTR_DWA2003224_HPP diff --git a/include/boost/python/detail/value_is_xxx.hpp b/include/boost/python/detail/value_is_xxx.hpp new file mode 100644 index 00000000..5621ad55 --- /dev/null +++ b/include/boost/python/detail/value_is_xxx.hpp @@ -0,0 +1,63 @@ +// Copyright David Abrahams 2003. 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 VALUE_IS_XXX_DWA2003224_HPP +# define VALUE_IS_XXX_DWA2003224_HPP + +# include +# include +# include + +# if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) +# include +# include + +# define BOOST_PYTHON_VALUE_IS_XXX_DEF(name, qualified_name, nargs) \ +template \ +struct value_is_##name \ +{ \ + typedef char yes; \ + typedef char (&no)[2]; \ + \ + static typename add_reference::type dummy; \ + \ + template < BOOST_PP_ENUM_PARAMS_Z(1, nargs, class U) > \ + static yes test( \ + qualified_name< BOOST_PP_ENUM_PARAMS_Z(1, nargs, U) > const&, int \ + ); \ + \ + template \ + static no test(U&, ...); \ + \ + BOOST_STATIC_CONSTANT( \ + bool, value \ + = (sizeof(test(dummy, 0)) == sizeof(yes))); \ + \ + typedef mpl::bool_c type; \ +}; + +# else + +# include +# include +# include + +# define BOOST_PYTHON_VALUE_IS_XXX_DEF(name, qualified_name, nargs) \ +template \ +struct value_is_##name \ +{ \ + BOOST_PYTHON_IS_XXX_DEF(name,qualified_name,nargs) \ + BOOST_STATIC_CONSTANT(bool, value = is_##name< \ + typename remove_cv< \ + typename remove_reference::type \ + >::type \ + >::value); \ + typedef mpl::bool_c type; \ + \ +}; + +# endif + +#endif // VALUE_IS_XXX_DWA2003224_HPP