Skip to content

Commit 9d3d50c

Browse files
committed
initial checkin
[SVN r13256]
1 parent 453fbbe commit 9d3d50c

8 files changed

Lines changed: 411 additions & 0 deletions

File tree

include/boost/python/args.hpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright David Abrahams 2002. Permission to copy, use,
2+
// modify, sell and distribute this software is granted provided this
3+
// copyright notice appears in all copies. This software is provided
4+
// "as is" without express or implied warranty, and with no claim as
5+
// to its suitability for any purpose.
6+
#ifndef ARGS_DWA2002323_HPP
7+
# define ARGS_DWA2002323_HPP
8+
# include <boost/mpl/type_list.hpp>
9+
10+
namespace boost { namespace python {
11+
12+
// A type list for specifying arguments
13+
template < BOOST_MPL_LIST_DEFAULT_PARAMETERS(typename A, ::boost::mpl::null_argument) >
14+
struct args : ::boost::mpl::type_list< BOOST_MPL_LIST_PARAMETERS(A) >::type
15+
{};
16+
17+
}} // namespace boost::python
18+
19+
#endif // ARGS_DWA2002323_HPP

include/boost/python/bases.hpp

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Copyright David Abrahams 2002. Permission to copy, use,
2+
// modify, sell and distribute this software is granted provided this
3+
// copyright notice appears in all copies. This software is provided
4+
// "as is" without express or implied warranty, and with no claim as
5+
// to its suitability for any purpose.
6+
#ifndef BASES_DWA2002321_HPP
7+
# define BASES_DWA2002321_HPP
8+
# include <boost/type_traits/object_traits.hpp>
9+
# include <boost/mpl/type_list.hpp>
10+
# include <boost/mpl/select_type.hpp>
11+
# include <boost/mpl/identity/identity.hpp>
12+
13+
namespace boost { namespace python {
14+
// A type list for specifying bases
15+
template < BOOST_MPL_LIST_DEFAULT_PARAMETERS(typename B, ::boost::mpl::null_argument) >
16+
struct bases : ::boost::mpl::type_list< BOOST_MPL_LIST_PARAMETERS(B) >::type
17+
{};
18+
19+
namespace detail
20+
{
21+
# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
22+
template <class T> struct specifies_bases
23+
{
24+
BOOST_STATIC_CONSTANT(bool, value = false);
25+
};
26+
template < BOOST_MPL_LIST_PARAMETERS(class B) >
27+
struct specifies_bases< bases< BOOST_MPL_LIST_PARAMETERS(B) > >
28+
{
29+
BOOST_STATIC_CONSTANT(bool, value = true);
30+
};
31+
# else
32+
template < BOOST_MPL_LIST_PARAMETERS(class B) >
33+
static char is_bases_helper(bases< BOOST_MPL_LIST_PARAMETERS(B) > const&);
34+
35+
static char (& is_bases_helper(...) )[256];
36+
37+
template <class T> struct specifies_bases
38+
{
39+
private:
40+
static typename add_reference<T>::type make();
41+
BOOST_STATIC_CONSTANT(bool, non_ref = !is_reference<T>::value);
42+
public:
43+
BOOST_STATIC_CONSTANT(bool, value = non_ref & (sizeof(is_bases_helper(make())) == 1));
44+
};
45+
# endif
46+
template <class T, class Prev = bases<> >
47+
struct select_bases
48+
: mpl::select_type<
49+
specifies_bases<T>::value
50+
, T
51+
, Prev
52+
>
53+
{
54+
};
55+
}
56+
}} // namespace boost::python
57+
58+
#endif // BASES_DWA2002321_HPP
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
// Copyright David Abrahams 2002. Permission to copy, use,
2+
// modify, sell and distribute this software is granted provided this
3+
// copyright notice appears in all copies. This software is provided
4+
// "as is" without express or implied warranty, and with no claim as
5+
// to its suitability for any purpose.
6+
#ifndef IF_ELSE_DWA2002322_HPP
7+
# define IF_ELSE_DWA2002322_HPP
8+
# include <boost/config.hpp>
9+
10+
namespace boost { namespace python { namespace detail {
11+
12+
template <class T> struct elif_selected;
13+
14+
template <class T>
15+
struct if_selected
16+
{
17+
template <bool b>
18+
struct elif : elif_selected<T>
19+
{
20+
};
21+
22+
template <class U>
23+
struct else_
24+
{
25+
typedef T type;
26+
};
27+
};
28+
29+
# if defined(BOOST_MSVC) && (BOOST_MSVC == 1300)
30+
namespace msvc70_aux {
31+
32+
template< bool > struct inherit_from
33+
{
34+
template< typename T > struct result
35+
{
36+
typedef T type;
37+
};
38+
};
39+
40+
template<> struct inherit_from<true>
41+
{
42+
template< typename T > struct result
43+
{
44+
struct type {};
45+
};
46+
};
47+
48+
template< typename T >
49+
struct never_true
50+
{
51+
BOOST_STATIC_CONSTANT(bool, value = false);
52+
};
53+
54+
} // namespace msvc70_aux
55+
56+
#endif // # if defined(BOOST_MSVC) && (BOOST_MSVC == 1300)
57+
58+
template <class T>
59+
struct elif_selected
60+
{
61+
# if !(defined(BOOST_MSVC) && BOOST_MSVC <= 1300 || defined(__MWERKS__) && __MWERKS__ <= 0x2407)
62+
template <class U> class then;
63+
# elif defined(BOOST_MSVC) && (BOOST_MSVC == 1300)
64+
template <class U>
65+
struct then : msvc70_aux::inherit_from< msvc70_aux::never_true<U>::value >
66+
::template result< if_selected<T> >::type
67+
{
68+
};
69+
# else
70+
template <class U>
71+
struct then : if_selected<T>
72+
{
73+
};
74+
# endif
75+
};
76+
77+
# if !(defined(BOOST_MSVC) && BOOST_MSVC <= 1300 || defined(__MWERKS__) && __MWERKS__ <= 0x2407)
78+
template <class T>
79+
template <class U>
80+
class elif_selected<T>::then : public if_selected<T>
81+
{
82+
};
83+
# endif
84+
85+
template <bool b> struct if_
86+
{
87+
template <class T>
88+
struct then : if_selected<T>
89+
{
90+
};
91+
};
92+
93+
struct if_unselected
94+
{
95+
template <bool b> struct elif : if_<b>
96+
{
97+
};
98+
99+
template <class U>
100+
struct else_
101+
{
102+
typedef U type;
103+
};
104+
};
105+
106+
template <>
107+
struct if_<false>
108+
{
109+
template <class T>
110+
struct then : if_unselected
111+
{
112+
};
113+
};
114+
115+
}}} // namespace boost::python::detail
116+
117+
#endif // IF_ELSE_DWA2002322_HPP
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright David Abrahams 2002. Permission to copy, use,
2+
// modify, sell and distribute this software is granted provided this
3+
// copyright notice appears in all copies. This software is provided
4+
// "as is" without express or implied warranty, and with no claim as
5+
// to its suitability for any purpose.
6+
#ifndef POINTEE_DWA2002323_HPP
7+
# define POINTEE_DWA2002323_HPP
8+
9+
# include <boost/type_traits/object_traits.hpp>
10+
11+
namespace boost { namespace python { namespace detail {
12+
13+
template <bool is_ptr = true>
14+
struct pointee_impl
15+
{
16+
template <class T> struct apply : remove_pointer<T> {};
17+
};
18+
19+
template <>
20+
struct pointee_impl<false>
21+
{
22+
template <class T> struct apply
23+
{
24+
typedef typename T::element_type type;
25+
};
26+
};
27+
28+
template <class T>
29+
struct pointee
30+
: pointee_impl<is_pointer<T>::value>::template apply<T>
31+
{
32+
};
33+
34+
}}} // namespace boost::python::detail
35+
36+
#endif // POINTEE_DWA2002323_HPP
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright David Abrahams 2002. Permission to copy, use,
2+
// modify, sell and distribute this software is granted provided this
3+
// copyright notice appears in all copies. This software is provided
4+
// "as is" without express or implied warranty, and with no claim as
5+
// to its suitability for any purpose.
6+
#ifndef HAS_BACK_REFERENCE_DWA2002323_HPP
7+
# define HAS_BACK_REFERENCE_DWA2002323_HPP
8+
9+
namespace boost { namespace python {
10+
11+
// traits class which users can specialize to indicate that a class
12+
// contains a back-reference to its owning PyObject*
13+
template <class T>
14+
struct has_back_reference
15+
{
16+
BOOST_STATIC_CONSTANT(bool, value = false);
17+
};
18+
19+
20+
}} // namespace boost::python
21+
22+
#endif // HAS_BACK_REFERENCE_DWA2002323_HPP

test/bases.cpp

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Copyright David Abrahams 2002. Permission to copy, use,
2+
// modify, sell and distribute this software is granted provided this
3+
// copyright notice appears in all copies. This software is provided
4+
// "as is" without express or implied warranty, and with no claim as
5+
// to its suitability for any purpose.
6+
#include <boost/python/bases.hpp>
7+
#include <boost/static_assert.hpp>
8+
#include <boost/type_traits/same_traits.hpp>
9+
10+
struct A;
11+
struct B;
12+
13+
template <class X, class Y, class Z>
14+
struct choose_bases
15+
: boost::python::detail::select_bases<
16+
X
17+
, typename boost::python::detail::select_bases<
18+
Y
19+
, typename boost::python::detail::select_bases<Z>::type
20+
>::type>
21+
{
22+
23+
};
24+
25+
int main()
26+
{
27+
BOOST_STATIC_ASSERT((boost::python::detail::specifies_bases<
28+
boost::python::bases<A,B> >::value));
29+
30+
BOOST_STATIC_ASSERT((!boost::python::detail::specifies_bases<
31+
boost::python::bases<A,B>& >::value));
32+
33+
BOOST_STATIC_ASSERT((!boost::python::detail::specifies_bases<
34+
void* >::value));
35+
36+
BOOST_STATIC_ASSERT((!boost::python::detail::specifies_bases<
37+
int >::value));
38+
39+
BOOST_STATIC_ASSERT((!boost::python::detail::specifies_bases<
40+
int[5] >::value));
41+
42+
typedef boost::python::detail::select_bases<
43+
int
44+
, boost::python::detail::select_bases<char*>::type > collected1;
45+
46+
BOOST_STATIC_ASSERT((boost::is_same<collected1::type,boost::python::bases<> >::value));
47+
BOOST_STATIC_ASSERT((boost::is_same<choose_bases<int,char*,long>::type,boost::python::bases<> >::value));
48+
49+
typedef boost::python::detail::select_bases<
50+
int
51+
, boost::python::detail::select_bases<
52+
boost::python::bases<A,B>
53+
, boost::python::detail::select_bases<
54+
A
55+
>::type
56+
>::type
57+
> collected2;
58+
59+
BOOST_STATIC_ASSERT((boost::is_same<collected2::type,boost::python::bases<A,B> >::value));
60+
BOOST_STATIC_ASSERT((boost::is_same<choose_bases<int,boost::python::bases<A,B>,long>::type,boost::python::bases<A,B> >::value));
61+
62+
return 0;
63+
}

test/if_else.cpp

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Copyright David Abrahams 2002. Permission to copy, use,
2+
// modify, sell and distribute this software is granted provided this
3+
// copyright notice appears in all copies. This software is provided
4+
// "as is" without express or implied warranty, and with no claim as
5+
// to its suitability for any purpose.
6+
#include <boost/static_assert.hpp>
7+
#include <boost/python/detail/if_else.hpp>
8+
#include <boost/type_traits/same_traits.hpp>
9+
10+
typedef char c1;
11+
typedef char c2[2];
12+
typedef char c3[3];
13+
typedef char c4[4];
14+
15+
template <unsigned size>
16+
struct choose
17+
{
18+
#if 1
19+
typedef typename boost::python::detail::if_<
20+
(sizeof(c1) == size)
21+
>::template then<
22+
c1
23+
>::template elif<
24+
(sizeof(c2) == size)
25+
>::template then<
26+
c2
27+
>::template elif<
28+
(sizeof(c3) == size)
29+
>::template then<
30+
c3
31+
>::template elif<
32+
(sizeof(c4) == size)
33+
>::template then<
34+
c4
35+
>::template else_<void*>::type type;
36+
#else
37+
typedef typename boost::python::detail::if_<
38+
(sizeof(c1) == size)
39+
, c1
40+
>::template elif<
41+
(sizeof(c2) == size)
42+
, c2
43+
>::template elif<
44+
(sizeof(c3) == size)
45+
, c3
46+
>::template elif<
47+
(sizeof(c4) == size)
48+
, c4
49+
>::template else_<void*>::type type;
50+
#endif
51+
};
52+
53+
int main()
54+
{
55+
BOOST_STATIC_ASSERT((boost::is_same<choose<1>::type,c1>::value));
56+
BOOST_STATIC_ASSERT((boost::is_same<choose<2>::type,c2>::value));
57+
BOOST_STATIC_ASSERT((boost::is_same<choose<3>::type,c3>::value));
58+
BOOST_STATIC_ASSERT((boost::is_same<choose<4>::type,c4>::value));
59+
BOOST_STATIC_ASSERT((boost::is_same<choose<5>::type,void*>::value));
60+
return 0;
61+
}

0 commit comments

Comments
 (0)