diff --git a/include/boost/python/args.hpp b/include/boost/python/args.hpp new file mode 100644 index 00000000..b584506b --- /dev/null +++ b/include/boost/python/args.hpp @@ -0,0 +1,19 @@ +// 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 ARGS_DWA2002323_HPP +# define ARGS_DWA2002323_HPP +# include + +namespace boost { namespace python { + +// A type list for specifying arguments +template < BOOST_MPL_LIST_DEFAULT_PARAMETERS(typename A, ::boost::mpl::null_argument) > +struct args : ::boost::mpl::type_list< BOOST_MPL_LIST_PARAMETERS(A) >::type +{}; + +}} // namespace boost::python + +#endif // ARGS_DWA2002323_HPP diff --git a/include/boost/python/bases.hpp b/include/boost/python/bases.hpp new file mode 100644 index 00000000..468c6744 --- /dev/null +++ b/include/boost/python/bases.hpp @@ -0,0 +1,58 @@ +// 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 BASES_DWA2002321_HPP +# define BASES_DWA2002321_HPP +# include +# include +# include +# include + +namespace boost { namespace python { + // A type list for specifying bases + template < BOOST_MPL_LIST_DEFAULT_PARAMETERS(typename B, ::boost::mpl::null_argument) > + struct bases : ::boost::mpl::type_list< BOOST_MPL_LIST_PARAMETERS(B) >::type + {}; + + namespace detail + { +# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION + template struct specifies_bases + { + BOOST_STATIC_CONSTANT(bool, value = false); + }; + template < BOOST_MPL_LIST_PARAMETERS(class B) > + struct specifies_bases< bases< BOOST_MPL_LIST_PARAMETERS(B) > > + { + BOOST_STATIC_CONSTANT(bool, value = true); + }; +# else + template < BOOST_MPL_LIST_PARAMETERS(class B) > + static char is_bases_helper(bases< BOOST_MPL_LIST_PARAMETERS(B) > const&); + + static char (& is_bases_helper(...) )[256]; + + template struct specifies_bases + { + private: + static typename add_reference::type make(); + BOOST_STATIC_CONSTANT(bool, non_ref = !is_reference::value); + public: + BOOST_STATIC_CONSTANT(bool, value = non_ref & (sizeof(is_bases_helper(make())) == 1)); + }; +# endif + template > + struct select_bases + : mpl::select_type< + specifies_bases::value + , T + , Prev + > + { + }; + } +}} // namespace boost::python + +#endif // BASES_DWA2002321_HPP diff --git a/include/boost/python/detail/if_else.hpp b/include/boost/python/detail/if_else.hpp new file mode 100644 index 00000000..6668617c --- /dev/null +++ b/include/boost/python/detail/if_else.hpp @@ -0,0 +1,117 @@ +// 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 IF_ELSE_DWA2002322_HPP +# define IF_ELSE_DWA2002322_HPP +# include + +namespace boost { namespace python { namespace detail { + +template struct elif_selected; + +template +struct if_selected +{ + template + struct elif : elif_selected + { + }; + + template + struct else_ + { + typedef T type; + }; +}; + +# if defined(BOOST_MSVC) && (BOOST_MSVC == 1300) +namespace msvc70_aux { + +template< bool > struct inherit_from +{ + template< typename T > struct result + { + typedef T type; + }; +}; + +template<> struct inherit_from +{ + template< typename T > struct result + { + struct type {}; + }; +}; + +template< typename T > +struct never_true +{ + BOOST_STATIC_CONSTANT(bool, value = false); +}; + +} // namespace msvc70_aux + +#endif // # if defined(BOOST_MSVC) && (BOOST_MSVC == 1300) + +template +struct elif_selected +{ +# if !(defined(BOOST_MSVC) && BOOST_MSVC <= 1300 || defined(__MWERKS__) && __MWERKS__ <= 0x2407) + template class then; +# elif defined(BOOST_MSVC) && (BOOST_MSVC == 1300) + template + struct then : msvc70_aux::inherit_from< msvc70_aux::never_true::value > + ::template result< if_selected >::type + { + }; +# else + template + struct then : if_selected + { + }; +# endif +}; + +# if !(defined(BOOST_MSVC) && BOOST_MSVC <= 1300 || defined(__MWERKS__) && __MWERKS__ <= 0x2407) +template +template +class elif_selected::then : public if_selected +{ +}; +# endif + +template struct if_ +{ + template + struct then : if_selected + { + }; +}; + +struct if_unselected +{ + template struct elif : if_ + { + }; + + template + struct else_ + { + typedef U type; + }; +}; + +template <> +struct if_ +{ + template + struct then : if_unselected + { + }; +}; + +}}} // namespace boost::python::detail + +#endif // IF_ELSE_DWA2002322_HPP diff --git a/include/boost/python/detail/pointee.hpp b/include/boost/python/detail/pointee.hpp new file mode 100644 index 00000000..2af1535f --- /dev/null +++ b/include/boost/python/detail/pointee.hpp @@ -0,0 +1,36 @@ +// 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 POINTEE_DWA2002323_HPP +# define POINTEE_DWA2002323_HPP + +# include + +namespace boost { namespace python { namespace detail { + +template +struct pointee_impl +{ + template struct apply : remove_pointer {}; +}; + +template <> +struct pointee_impl +{ + template struct apply + { + typedef typename T::element_type type; + }; +}; + +template +struct pointee + : pointee_impl::value>::template apply +{ +}; + +}}} // namespace boost::python::detail + +#endif // POINTEE_DWA2002323_HPP diff --git a/include/boost/python/has_back_reference.hpp b/include/boost/python/has_back_reference.hpp new file mode 100644 index 00000000..95a3ae9a --- /dev/null +++ b/include/boost/python/has_back_reference.hpp @@ -0,0 +1,22 @@ +// 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 HAS_BACK_REFERENCE_DWA2002323_HPP +# define HAS_BACK_REFERENCE_DWA2002323_HPP + +namespace boost { namespace python { + +// traits class which users can specialize to indicate that a class +// contains a back-reference to its owning PyObject* +template +struct has_back_reference +{ + BOOST_STATIC_CONSTANT(bool, value = false); +}; + + +}} // namespace boost::python + +#endif // HAS_BACK_REFERENCE_DWA2002323_HPP diff --git a/test/bases.cpp b/test/bases.cpp new file mode 100644 index 00000000..e4f91990 --- /dev/null +++ b/test/bases.cpp @@ -0,0 +1,63 @@ +// 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. +#include +#include +#include + +struct A; +struct B; + +template +struct choose_bases + : boost::python::detail::select_bases< + X + , typename boost::python::detail::select_bases< + Y + , typename boost::python::detail::select_bases::type + >::type> +{ + +}; + +int main() +{ + BOOST_STATIC_ASSERT((boost::python::detail::specifies_bases< + boost::python::bases >::value)); + + BOOST_STATIC_ASSERT((!boost::python::detail::specifies_bases< + boost::python::bases& >::value)); + + BOOST_STATIC_ASSERT((!boost::python::detail::specifies_bases< + void* >::value)); + + BOOST_STATIC_ASSERT((!boost::python::detail::specifies_bases< + int >::value)); + + BOOST_STATIC_ASSERT((!boost::python::detail::specifies_bases< + int[5] >::value)); + + typedef boost::python::detail::select_bases< + int + , boost::python::detail::select_bases::type > collected1; + + BOOST_STATIC_ASSERT((boost::is_same >::value)); + BOOST_STATIC_ASSERT((boost::is_same::type,boost::python::bases<> >::value)); + + typedef boost::python::detail::select_bases< + int + , boost::python::detail::select_bases< + boost::python::bases + , boost::python::detail::select_bases< + A + >::type + >::type + > collected2; + + BOOST_STATIC_ASSERT((boost::is_same >::value)); + BOOST_STATIC_ASSERT((boost::is_same,long>::type,boost::python::bases >::value)); + + return 0; +} diff --git a/test/if_else.cpp b/test/if_else.cpp new file mode 100644 index 00000000..d8bd34ca --- /dev/null +++ b/test/if_else.cpp @@ -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. +#include +#include +#include + + typedef char c1; + typedef char c2[2]; + typedef char c3[3]; + typedef char c4[4]; + +template +struct choose +{ +#if 1 + typedef typename boost::python::detail::if_< + (sizeof(c1) == size) + >::template then< + c1 + >::template elif< + (sizeof(c2) == size) + >::template then< + c2 + >::template elif< + (sizeof(c3) == size) + >::template then< + c3 + >::template elif< + (sizeof(c4) == size) + >::template then< + c4 + >::template else_::type type; +#else + typedef typename boost::python::detail::if_< + (sizeof(c1) == size) + , c1 + >::template elif< + (sizeof(c2) == size) + , c2 + >::template elif< + (sizeof(c3) == size) + , c3 + >::template elif< + (sizeof(c4) == size) + , c4 + >::template else_::type type; +#endif +}; + +int main() +{ + BOOST_STATIC_ASSERT((boost::is_same::type,c1>::value)); + BOOST_STATIC_ASSERT((boost::is_same::type,c2>::value)); + BOOST_STATIC_ASSERT((boost::is_same::type,c3>::value)); + BOOST_STATIC_ASSERT((boost::is_same::type,c4>::value)); + BOOST_STATIC_ASSERT((boost::is_same::type,void*>::value)); + return 0; +} diff --git a/test/pointee.cpp b/test/pointee.cpp new file mode 100644 index 00000000..7935e897 --- /dev/null +++ b/test/pointee.cpp @@ -0,0 +1,35 @@ +// 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. +#include +#include +#include +#include +#include + +struct A; + +int main() +{ + BOOST_STATIC_ASSERT( + (boost::is_same< + boost::python::detail::pointee >::type + , char** + >::value)); + + BOOST_STATIC_ASSERT( + (boost::is_same< + boost::python::detail::pointee >::type + , A>::value)); + +#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION + BOOST_STATIC_ASSERT( + (boost::is_same< + boost::python::detail::pointee::type + , char + >::value)); +#endif + return 0; +}