mirror of
https://github.com/boostorg/python.git
synced 2026-01-24 18:12:43 +00:00
initial checkin
[SVN r13256]
This commit is contained in:
19
include/boost/python/args.hpp
Normal file
19
include/boost/python/args.hpp
Normal file
@@ -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 <boost/mpl/type_list.hpp>
|
||||
|
||||
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
|
||||
58
include/boost/python/bases.hpp
Normal file
58
include/boost/python/bases.hpp
Normal file
@@ -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 <boost/type_traits/object_traits.hpp>
|
||||
# include <boost/mpl/type_list.hpp>
|
||||
# include <boost/mpl/select_type.hpp>
|
||||
# include <boost/mpl/identity/identity.hpp>
|
||||
|
||||
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 <class T> 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 <class T> struct specifies_bases
|
||||
{
|
||||
private:
|
||||
static typename add_reference<T>::type make();
|
||||
BOOST_STATIC_CONSTANT(bool, non_ref = !is_reference<T>::value);
|
||||
public:
|
||||
BOOST_STATIC_CONSTANT(bool, value = non_ref & (sizeof(is_bases_helper(make())) == 1));
|
||||
};
|
||||
# endif
|
||||
template <class T, class Prev = bases<> >
|
||||
struct select_bases
|
||||
: mpl::select_type<
|
||||
specifies_bases<T>::value
|
||||
, T
|
||||
, Prev
|
||||
>
|
||||
{
|
||||
};
|
||||
}
|
||||
}} // namespace boost::python
|
||||
|
||||
#endif // BASES_DWA2002321_HPP
|
||||
117
include/boost/python/detail/if_else.hpp
Normal file
117
include/boost/python/detail/if_else.hpp
Normal file
@@ -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 <boost/config.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace detail {
|
||||
|
||||
template <class T> struct elif_selected;
|
||||
|
||||
template <class T>
|
||||
struct if_selected
|
||||
{
|
||||
template <bool b>
|
||||
struct elif : elif_selected<T>
|
||||
{
|
||||
};
|
||||
|
||||
template <class U>
|
||||
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<true>
|
||||
{
|
||||
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 <class T>
|
||||
struct elif_selected
|
||||
{
|
||||
# if !(defined(BOOST_MSVC) && BOOST_MSVC <= 1300 || defined(__MWERKS__) && __MWERKS__ <= 0x2407)
|
||||
template <class U> class then;
|
||||
# elif defined(BOOST_MSVC) && (BOOST_MSVC == 1300)
|
||||
template <class U>
|
||||
struct then : msvc70_aux::inherit_from< msvc70_aux::never_true<U>::value >
|
||||
::template result< if_selected<T> >::type
|
||||
{
|
||||
};
|
||||
# else
|
||||
template <class U>
|
||||
struct then : if_selected<T>
|
||||
{
|
||||
};
|
||||
# endif
|
||||
};
|
||||
|
||||
# if !(defined(BOOST_MSVC) && BOOST_MSVC <= 1300 || defined(__MWERKS__) && __MWERKS__ <= 0x2407)
|
||||
template <class T>
|
||||
template <class U>
|
||||
class elif_selected<T>::then : public if_selected<T>
|
||||
{
|
||||
};
|
||||
# endif
|
||||
|
||||
template <bool b> struct if_
|
||||
{
|
||||
template <class T>
|
||||
struct then : if_selected<T>
|
||||
{
|
||||
};
|
||||
};
|
||||
|
||||
struct if_unselected
|
||||
{
|
||||
template <bool b> struct elif : if_<b>
|
||||
{
|
||||
};
|
||||
|
||||
template <class U>
|
||||
struct else_
|
||||
{
|
||||
typedef U type;
|
||||
};
|
||||
};
|
||||
|
||||
template <>
|
||||
struct if_<false>
|
||||
{
|
||||
template <class T>
|
||||
struct then : if_unselected
|
||||
{
|
||||
};
|
||||
};
|
||||
|
||||
}}} // namespace boost::python::detail
|
||||
|
||||
#endif // IF_ELSE_DWA2002322_HPP
|
||||
36
include/boost/python/detail/pointee.hpp
Normal file
36
include/boost/python/detail/pointee.hpp
Normal file
@@ -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 <boost/type_traits/object_traits.hpp>
|
||||
|
||||
namespace boost { namespace python { namespace detail {
|
||||
|
||||
template <bool is_ptr = true>
|
||||
struct pointee_impl
|
||||
{
|
||||
template <class T> struct apply : remove_pointer<T> {};
|
||||
};
|
||||
|
||||
template <>
|
||||
struct pointee_impl<false>
|
||||
{
|
||||
template <class T> struct apply
|
||||
{
|
||||
typedef typename T::element_type type;
|
||||
};
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct pointee
|
||||
: pointee_impl<is_pointer<T>::value>::template apply<T>
|
||||
{
|
||||
};
|
||||
|
||||
}}} // namespace boost::python::detail
|
||||
|
||||
#endif // POINTEE_DWA2002323_HPP
|
||||
22
include/boost/python/has_back_reference.hpp
Normal file
22
include/boost/python/has_back_reference.hpp
Normal file
@@ -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 <class T>
|
||||
struct has_back_reference
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, value = false);
|
||||
};
|
||||
|
||||
|
||||
}} // namespace boost::python
|
||||
|
||||
#endif // HAS_BACK_REFERENCE_DWA2002323_HPP
|
||||
63
test/bases.cpp
Normal file
63
test/bases.cpp
Normal file
@@ -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 <boost/python/bases.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
#include <boost/type_traits/same_traits.hpp>
|
||||
|
||||
struct A;
|
||||
struct B;
|
||||
|
||||
template <class X, class Y, class Z>
|
||||
struct choose_bases
|
||||
: boost::python::detail::select_bases<
|
||||
X
|
||||
, typename boost::python::detail::select_bases<
|
||||
Y
|
||||
, typename boost::python::detail::select_bases<Z>::type
|
||||
>::type>
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
BOOST_STATIC_ASSERT((boost::python::detail::specifies_bases<
|
||||
boost::python::bases<A,B> >::value));
|
||||
|
||||
BOOST_STATIC_ASSERT((!boost::python::detail::specifies_bases<
|
||||
boost::python::bases<A,B>& >::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<char*>::type > collected1;
|
||||
|
||||
BOOST_STATIC_ASSERT((boost::is_same<collected1::type,boost::python::bases<> >::value));
|
||||
BOOST_STATIC_ASSERT((boost::is_same<choose_bases<int,char*,long>::type,boost::python::bases<> >::value));
|
||||
|
||||
typedef boost::python::detail::select_bases<
|
||||
int
|
||||
, boost::python::detail::select_bases<
|
||||
boost::python::bases<A,B>
|
||||
, boost::python::detail::select_bases<
|
||||
A
|
||||
>::type
|
||||
>::type
|
||||
> collected2;
|
||||
|
||||
BOOST_STATIC_ASSERT((boost::is_same<collected2::type,boost::python::bases<A,B> >::value));
|
||||
BOOST_STATIC_ASSERT((boost::is_same<choose_bases<int,boost::python::bases<A,B>,long>::type,boost::python::bases<A,B> >::value));
|
||||
|
||||
return 0;
|
||||
}
|
||||
61
test/if_else.cpp
Normal file
61
test/if_else.cpp
Normal file
@@ -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 <boost/static_assert.hpp>
|
||||
#include <boost/python/detail/if_else.hpp>
|
||||
#include <boost/type_traits/same_traits.hpp>
|
||||
|
||||
typedef char c1;
|
||||
typedef char c2[2];
|
||||
typedef char c3[3];
|
||||
typedef char c4[4];
|
||||
|
||||
template <unsigned size>
|
||||
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_<void*>::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_<void*>::type type;
|
||||
#endif
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
BOOST_STATIC_ASSERT((boost::is_same<choose<1>::type,c1>::value));
|
||||
BOOST_STATIC_ASSERT((boost::is_same<choose<2>::type,c2>::value));
|
||||
BOOST_STATIC_ASSERT((boost::is_same<choose<3>::type,c3>::value));
|
||||
BOOST_STATIC_ASSERT((boost::is_same<choose<4>::type,c4>::value));
|
||||
BOOST_STATIC_ASSERT((boost::is_same<choose<5>::type,void*>::value));
|
||||
return 0;
|
||||
}
|
||||
35
test/pointee.cpp
Normal file
35
test/pointee.cpp
Normal file
@@ -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 <boost/python/detail/pointee.hpp>
|
||||
#include <boost/type_traits/same_traits.hpp>
|
||||
#include <memory>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
|
||||
struct A;
|
||||
|
||||
int main()
|
||||
{
|
||||
BOOST_STATIC_ASSERT(
|
||||
(boost::is_same<
|
||||
boost::python::detail::pointee<std::auto_ptr<char**> >::type
|
||||
, char**
|
||||
>::value));
|
||||
|
||||
BOOST_STATIC_ASSERT(
|
||||
(boost::is_same<
|
||||
boost::python::detail::pointee<boost::shared_ptr<A> >::type
|
||||
, A>::value));
|
||||
|
||||
#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||
BOOST_STATIC_ASSERT(
|
||||
(boost::is_same<
|
||||
boost::python::detail::pointee<char*>::type
|
||||
, char
|
||||
>::value));
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user