Skip to content

Commit f30fde3

Browse files
committed
list implementation
[SVN r14261]
1 parent d7273de commit f30fde3

23 files changed

+776
-397
lines changed

Jamfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ if $(UNIX) && ( $(OS) = AIX )
1313

1414
dll bpl
1515
:
16+
src/list.cpp
1617
src/aix_init_module.cpp
1718
src/converter/from_python.cpp
1819
src/converter/registry.cpp

include/boost/python/converter/arg_to_python.hpp

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
# include <boost/python/to_python_indirect.hpp>
1515
# include <boost/type_traits/cv_traits.hpp>
1616
# include <boost/python/detail/convertible.hpp>
17+
# include <boost/python/detail/string_literal.hpp>
1718
# include <boost/python/base_type_traits.hpp>
1819
// Bring in specializations
1920
# include <boost/python/converter/builtin_converters.hpp>
@@ -73,6 +74,11 @@ namespace detail
7374
template <class T>
7475
struct select_arg_to_python
7576
{
77+
// Special handling for char const[N]; interpret them as char
78+
// const* for the sake of conversion
79+
BOOST_STATIC_CONSTANT(
80+
bool, is_string = python::detail::is_string_literal<T const>::value);
81+
7682
BOOST_STATIC_CONSTANT(
7783
bool, manager = is_object_manager<T>::value);
7884

@@ -89,22 +95,27 @@ namespace detail
8995
typedef typename unwrap_pointer<T>::type unwrapped_ptr;
9096

9197
typedef typename mpl::select_type<
92-
manager
93-
, object_manager_arg_to_python<T>
98+
is_string
99+
, arg_to_python<char const*>
94100
, typename mpl::select_type<
95-
ptr
96-
, pointer_deep_arg_to_python<T>
101+
manager
102+
, object_manager_arg_to_python<T>
97103
, typename mpl::select_type<
98-
ptr_wrapper
99-
, pointer_shallow_arg_to_python<unwrapped_ptr>
104+
ptr
105+
, pointer_deep_arg_to_python<T>
100106
, typename mpl::select_type<
101-
ref_wrapper
102-
, reference_arg_to_python<unwrapped_referent>
103-
, value_arg_to_python<T>
107+
ptr_wrapper
108+
, pointer_shallow_arg_to_python<unwrapped_ptr>
109+
, typename mpl::select_type<
110+
ref_wrapper
111+
, reference_arg_to_python<unwrapped_referent>
112+
, value_arg_to_python<T>
113+
>::type
104114
>::type
105115
>::type
106116
>::type
107-
>::type type;
117+
>::type
118+
type;
108119
};
109120
}
110121

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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 PYTYPE_ARG_FROM_PYTHON_DWA2002628_HPP
7+
# define PYTYPE_ARG_FROM_PYTHON_DWA2002628_HPP
8+
9+
# include <boost/python/detail/wrap_python.hpp>
10+
11+
//
12+
// arg_from_python converters for Python type wrappers, to be used as
13+
// base classes for specializations.
14+
//
15+
namespace boost { namespace python { namespace converter {
16+
17+
template <PyTypeObject* python_type>
18+
struct pytype_arg_from_python
19+
{
20+
pytype_arg_from_python(PyObject*);
21+
bool convertible() const;
22+
private:
23+
PyObject* m_src;
24+
};
25+
26+
// rvalue converter base
27+
template <class Wrapper, PyTypeObject* python_type>
28+
struct pytype_wrapper_value_arg_from_python
29+
: pytype_arg_from_python<python_type>
30+
{
31+
typedef Wrapper result_type;
32+
33+
pytype_wrapper_value_arg_from_python(PyObject*);
34+
Wrapper operator()(PyObject*) const;
35+
};
36+
37+
// Special case for Wrapper& - must store an lvalue internally. This
38+
// OK because the entire state of the object is actually in the Python
39+
// object.
40+
template <class Wrapper, PyTypeObject* python_type>
41+
struct pytype_wrapper_ref_arg_from_python
42+
: pytype_arg_from_python<python_type>
43+
{
44+
typedef Wrapper& result_type;
45+
46+
pytype_wrapper_ref_arg_from_python(PyObject*);
47+
Wrapper& operator()(PyObject*) const;
48+
private:
49+
mutable Wrapper m_result;
50+
};
51+
52+
//
53+
// implementations
54+
//
55+
56+
template <PyTypeObject* python_type>
57+
inline pytype_arg_from_python<python_type>::pytype_arg_from_python(PyObject* x)
58+
: m_src(x)
59+
{
60+
}
61+
62+
template <PyTypeObject* python_type>
63+
inline bool pytype_arg_from_python<python_type>::convertible() const
64+
{
65+
return PyObject_IsInstance(m_src, (PyObject*)python_type);
66+
}
67+
68+
template <class Wrapper, PyTypeObject* python_type>
69+
pytype_wrapper_value_arg_from_python<Wrapper,python_type>::pytype_wrapper_value_arg_from_python(
70+
PyObject* p)
71+
: pytype_arg_from_python<python_type>(p)
72+
{
73+
}
74+
75+
template <class Wrapper, PyTypeObject* python_type>
76+
Wrapper pytype_wrapper_value_arg_from_python<Wrapper,python_type>::operator()(
77+
PyObject* x) const
78+
{
79+
return Wrapper(python::detail::borrowed_reference(x));
80+
}
81+
82+
template <class Wrapper, PyTypeObject* python_type>
83+
pytype_wrapper_ref_arg_from_python<Wrapper,python_type>::pytype_wrapper_ref_arg_from_python(
84+
PyObject* p)
85+
: pytype_arg_from_python<python_type>(p)
86+
, m_result(python::detail::borrowed_reference(p))
87+
{
88+
}
89+
90+
template <class Wrapper, PyTypeObject* python_type>
91+
Wrapper& pytype_wrapper_ref_arg_from_python<Wrapper,python_type>::operator()(
92+
PyObject* x) const
93+
{
94+
return m_result;
95+
}
96+
97+
}}} // namespace boost::python::converter
98+
99+
#endif // PYTYPE_ARG_FROM_PYTHON_DWA2002628_HPP
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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 RAW_PYOBJECT_DWA2002628_HPP
7+
# define RAW_PYOBJECT_DWA2002628_HPP
8+
9+
namespace boost { namespace python { namespace detail {
10+
11+
//
12+
// Define some types which we can use to get around the vagaries of
13+
// PyObject*. We will use these to initialize object instances, and
14+
// keep them in namespace detail to make sure they stay out of the
15+
// hands of users. That is much simpler than trying to grant
16+
// friendship to all the appropriate parties.
17+
//
18+
19+
// New references are checked for null
20+
struct new_reference_t;
21+
typedef new_reference_t* new_reference;
22+
23+
// Borrowed references are assumed to be non-null
24+
struct borrowed_reference_t;
25+
typedef borrowed_reference_t* borrowed_reference;
26+
27+
}}} // namespace boost::python::detail
28+
29+
#endif // RAW_PYOBJECT_DWA2002628_HPP
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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 STRING_LITERAL_DWA2002629_HPP
7+
# define STRING_LITERAL_DWA2002629_HPP
8+
9+
# include <cstddef>
10+
# include <boost/type.hpp>
11+
# include <boost/type_traits/array_traits.hpp>
12+
# include <boost/type_traits/same_traits.hpp>
13+
14+
namespace boost { namespace python { namespace detail {
15+
16+
# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
17+
template <class T>
18+
struct is_string_literal
19+
{
20+
BOOST_STATIC_CONSTANT(bool, value = false);
21+
};
22+
23+
# if !defined(__MWERKS__) || __MWERKS__ > 0x2407
24+
template <std::size_t n>
25+
struct is_string_literal<char const[n]>
26+
{
27+
BOOST_STATIC_CONSTANT(bool, value = true);
28+
};
29+
# else
30+
// CWPro7 has trouble with the array type deduction above
31+
template <class T, std::size_t n>
32+
struct is_string_literal<T[n]>
33+
: is_same<T, char const>
34+
{
35+
};
36+
# endif
37+
# else
38+
template <bool is_array = true>
39+
struct string_literal_helper
40+
{
41+
typedef char (&yes_string_literal)[1];
42+
typedef char (&no_string_literal)[2];
43+
44+
template <class T>
45+
struct apply
46+
{
47+
typedef apply<T> self;
48+
static T x;
49+
static yes_string_literal check(char const*);
50+
static no_string_literal check(char*);
51+
static no_string_literal check(void const volatile*);
52+
53+
BOOST_STATIC_CONSTANT(
54+
bool, value = sizeof(self::check(x)) == sizeof(yes_string_literal));
55+
};
56+
};
57+
58+
template <>
59+
struct string_literal_helper<false>
60+
{
61+
template <class T>
62+
struct apply
63+
{
64+
BOOST_STATIC_CONSTANT(bool, value = false);
65+
};
66+
};
67+
68+
template <class T>
69+
struct is_string_literal
70+
: string_literal_helper<is_array<T>::value>::apply<T>
71+
{
72+
};
73+
# endif
74+
75+
}}} // namespace boost::python::detail
76+
77+
#endif // STRING_LITERAL_DWA2002629_HPP

0 commit comments

Comments
 (0)