diff --git a/doc/enums.html b/doc/enums.html index 32d61447..03b663ac 100644 --- a/doc/enums.html +++ b/doc/enums.html @@ -75,7 +75,7 @@ BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE // this is a gcc 2.95.2 bug workaround from_python(x, boost::python::type<long>())); } - PyObject* to_python(MyEnumType x) + PyObject* to_python(boost::python::semantics, MyEnumType x) { return to_python(static_cast<long>(x)); } @@ -91,8 +91,8 @@ initialization. These bind the corresponding enum values to the appropriate names so they can be used from Python:
@@ -100,8 +100,8 @@ You can also add these to an extension class definition, if your enum happens to be local to a class and you want the analogous interface in Python:-mymodule.add(boost::python::to_python(enum_value_1), "enum_value_1"); -mymodule.add(boost::python::to_python(enum_value_2), "enum_value_2"); +mymodule.add(boost::python::to_python(boost::python::search_namespace, enum_value_1), "enum_value_1"); +mymodule.add(boost::python::to_python(boost::python::search_namespace, enum_value_2), "enum_value_2"); ...
-my_class_builder.add(boost::python::to_python(enum_value_1), "enum_value_1"); -my_class_builder.add(boost::python::to_python(enum_value_2), "enum_value_2"); +my_class_builder.add(boost::python::to_python(boost::python::search_namespace, enum_value_1), "enum_value_1"); +my_class_builder.add(boost::python::to_python(boost::python::search_namespace, enum_value_2), "enum_value_2"); ...
diff --git a/doc/pointers.html b/doc/pointers.html
index fdbee797..1440bbd1 100644
--- a/doc/pointers.html
+++ b/doc/pointers.html
@@ -65,9 +65,9 @@ wrapped T, you may want to provide an automatic
thin wrappers. You can do this simply as follows:
-BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE // this is a gcc 2.95.2 bug workaround
- PyObject* to_python(const Foo* p) {
- return to_python(*p); // convert const Foo* in terms of const Foo&
+BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE // this is an MSVC / gcc 2.95.2 bug workaround
+ PyObject* to_python(boost::python::semantics, const Foo* p) {
+ return to_python(boost::python::search_namespace, *p); // convert const Foo* in terms of const Foo&
}
BOOST_PYTHON_END_CONVERSION_NAMESPACE
@@ -83,12 +83,12 @@ code before the last Python reference to it disappears:
BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE // this is a gcc 2.95.2 bug workaround
- PyObject* to_python(Foo* p)
+ PyObject* to_python(boost::python::semantics, Foo* p)
{
return boost::python::python_extension_class_converters<Foo>::ptr_to_python(p);
}
- PyObject* to_python(const Foo* p)
+ PyObject* to_python(boost::python::semantics, const Foo* p)
{
return to_python(const_cast<Foo*>(p));
}
diff --git a/doc/special.html b/doc/special.html
index 0caa1924..b928210d 100644
--- a/doc/special.html
+++ b/doc/special.html
@@ -699,7 +699,7 @@ void throw_key_error_if_end(
{
if (p == m.end())
{
- PyErr_SetObject(PyExc_KeyError, boost::python::converters::to_python(key));
+ PyErr_SetObject(PyExc_KeyError, to_python(boost::python::search_namespace, key));
throw boost::python::error_already_set();
}
}
diff --git a/doc/under-the-hood.html b/doc/under-the-hood.html
index 733f0f54..f676fbb0 100644
--- a/doc/under-the-hood.html
+++ b/doc/under-the-hood.html
@@ -27,7 +27,7 @@
provide an argument list
because they can't be named in C++). Then, it calls the appropriate
overloaded functions PyObject*
- to_python(S) and
+ to_python(boost::python::semantics, S) and
S'from_python(PyObject*,
type<S>) which convert between any C++
type S and a PyObject*, the type which represents a
diff --git a/example/do_it_yourself_converters.cpp b/example/do_it_yourself_converters.cpp
index 6d2d2d6a..064f2f0c 100644
--- a/example/do_it_yourself_converters.cpp
+++ b/example/do_it_yourself_converters.cpp
@@ -95,11 +95,11 @@ BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE
// Convert a MillerIndex object to a Python tuple.
//
- PyObject* to_python(const MillerIndex& hkl)
+ PyObject* to_python(python::semantics, const MillerIndex& hkl)
{
python::tuple result(3);
for (int i = 0; i < 3; i++)
- result.set_item(i, python::ref(to_python(hkl.v[i])));
+ result.set_item(i, hkl.v[i]);
return result.reference().release();
}
diff --git a/example/dvect.h b/example/dvect.h
index 8ffe7b50..21351572 100644
--- a/example/dvect.h
+++ b/example/dvect.h
@@ -14,16 +14,14 @@ namespace vects {
{
std::vector::iterator v_it = begin();
for (int i = 0; i < tuple.size(); i++)
- v_it[i] = BOOST_PYTHON_CONVERSION::from_python(tuple[i].get(),
- boost::python::type());
+ v_it[i] = from_python(tuple[i].get(), boost::python::type());
}
boost::python::tuple as_tuple() const
{
boost::python::tuple t(size());
for (int i = 0; i < size(); i++)
- t.set_item(i,
- boost::python::ref(BOOST_PYTHON_CONVERSION::to_python((*this)[i])));
+ t.set_item(i, (*this)[i]);
return t;
}
};
diff --git a/example/ivect.h b/example/ivect.h
index a0187307..3e025e4c 100644
--- a/example/ivect.h
+++ b/example/ivect.h
@@ -14,16 +14,14 @@ namespace vects {
{
std::vector::iterator v_it = begin();
for (int i = 0; i < tuple.size(); i++)
- v_it[i] = BOOST_PYTHON_CONVERSION::from_python(tuple[i].get(),
- boost::python::type());
+ v_it[i] = from_python(tuple[i].get(), boost::python::type());
}
boost::python::tuple as_tuple() const
{
boost::python::tuple t(size());
for (int i = 0; i < size(); i++)
- t.set_item(i,
- boost::python::ref(BOOST_PYTHON_CONVERSION::to_python((*this)[i])));
+ t.set_item(i, (*this)[i]);
return t;
}
};
diff --git a/example/pickle2.cpp b/example/pickle2.cpp
index d6aa3201..269fc190 100644
--- a/example/pickle2.cpp
+++ b/example/pickle2.cpp
@@ -45,8 +45,6 @@ namespace { // Avoid cluttering the global namespace.
// Support for pickle.
- using BOOST_PYTHON_CONVERSION::from_python;
-
python::ref world_getinitargs(const world& w) {
python::tuple result(1);
result.set_item(0, w.get_country());
diff --git a/example/pickle3.cpp b/example/pickle3.cpp
index bfa7dc54..53054ea6 100644
--- a/example/pickle3.cpp
+++ b/example/pickle3.cpp
@@ -94,7 +94,6 @@ BOOST_PYTHON_MODULE_INIT(pickle3)
namespace {
- using BOOST_PYTHON_CONVERSION::from_python;
using boost::python::type;
using boost::python::ref;
using boost::python::tuple;
diff --git a/example/simple_vector.cpp b/example/simple_vector.cpp
index 2b3aa290..67c06c6d 100644
--- a/example/simple_vector.cpp
+++ b/example/simple_vector.cpp
@@ -25,8 +25,7 @@ namespace { // Avoid cluttering the global namespace.
{
std::vector::iterator vd = begin();
for (int i = 0; i < tuple.size(); i++)
- vd[i] = BOOST_PYTHON_CONVERSION::from_python(tuple[i].get(),
- python::type());
+ vd[i] = from_python(tuple[i].get(), python::type());
}
};
@@ -57,8 +56,8 @@ namespace { // Avoid cluttering the global namespace.
python::tuple as_tuple(const std::vector& vd)
{
python::tuple t(vd.size());
- for (int i = 0; i < vd.size(); i++) t.set_item(i,
- python::ref(BOOST_PYTHON_CONVERSION::to_python(vd[i])));
+ for (int i = 0; i < vd.size(); i++)
+ t.set_item(i, vd[i]);
return t;
}
diff --git a/include/boost/python/class_builder.hpp b/include/boost/python/class_builder.hpp
index 4a9ec1b2..a4ed33e9 100644
--- a/include/boost/python/class_builder.hpp
+++ b/include/boost/python/class_builder.hpp
@@ -19,117 +19,118 @@ class class_builder
: python_extension_class_converters // Works around MSVC6.x/GCC2.95.2 bug described below
{
public:
+ /// Construct a class named name in the given module
class_builder(module_builder& module, const char* name)
: m_class(new detail::extension_class(name))
{
module.add(ref(as_object(m_class.get()), ref::increment_count), name);
}
-
- ~class_builder()
- {}
+ /// Tell Boost.Python that for the purposes of pickling, the state is
+ /// completely captured in the object's __dict__.
inline void dict_defines_state() {
- add(ref(BOOST_PYTHON_CONVERSION::to_python(1)), "__dict_defines_state__");
- }
- inline void getstate_manages_dict() {
- add(ref(BOOST_PYTHON_CONVERSION::to_python(1)), "__getstate_manages_dict__");
+ add(ref(to_python(search_namespace, 1)), "__dict_defines_state__");
}
- // define constructors
+ inline void getstate_manages_dict() {
+ add(ref(to_python(search_namespace, 1)), "__getstate_manages_dict__");
+ }
+
+ /// define constructors
template
void def(const signature& s)
{ m_class->def(s); }
- // export heterogeneous reverse-argument operators
- // (type of lhs: 'left', of rhs: 'right')
- // usage: foo_class.def(boost::python::operators<(boost::python::op_add | boost::python::op_sub), Foo>(),
- // boost::python::left_operand());
+ /// export heterogeneous reverse-argument operators
+ /// (type of lhs: 'left', of rhs: 'right')
+ /// usage: foo_class.def(boost::python::operators<(boost::python::op_add | boost::python::op_sub), Foo>(),
+ /// boost::python::left_operand());
template
void def(operators o1, left_operand o2)
{ m_class->def(o1, o2); }
- // export heterogeneous operators (type of lhs: 'left', of rhs: 'right')
- // usage: foo_class.def(boost::python::operators<(boost::python::op_add | boost::python::op_sub), Foo>(),
- // boost::python::right_operand());
+ /// export heterogeneous operators (type of lhs: 'left', of rhs: 'right')
+ /// usage: foo_class.def(boost::python::operators<(boost::python::op_add | boost::python::op_sub), Foo>(),
+ /// boost::python::right_operand());
template
void def(operators o1, right_operand o2)
{ m_class->def(o1, o2); }
- // define a function that passes Python arguments and keywords
- // to C++ verbatim (as a 'tuple const &' and 'dictionary const &'
- // respectively). This is useful for manual argument passing.
- // It's also the only possibility to pass keyword arguments to C++.
- // Fn must have a signatur that is compatible to
- // PyObject * (*)(PyObject * aTuple, PyObject * aDictionary)
+ /// define a function that passes Python arguments and keywords
+ /// to C++ verbatim (as a 'tuple const &' and 'dictionary const &'
+ /// respectively). This is useful for manual argument passing.
+ /// It's also the only way to pass keyword arguments to C++.
+ /// Fn must have a signature that is compatible with
+ /// PyObject * (*)(PyObject * aTuple, PyObject * aDictionary)
template
void def_raw(Fn fn, const char* name)
{ m_class->def_raw(fn, name); }
- // define member functions. In fact this works for free functions, too -
- // they act like static member functions, or if they start with the
- // appropriate self argument (as a pointer or reference), they can be used
- // just like ordinary member functions -- just like Python!
+ /// define member functions. In fact this works for free functions, too -
+ /// they act like static member functions, or if they start with the
+ /// appropriate self argument (as a pointer or reference), they can be used
+ /// just like ordinary member functions -- just like Python!
template
void def(Fn fn, const char* name)
{ m_class->def(fn, name); }
- // Define a virtual member function with a default implementation.
- // default_fn should be a function which provides the default implementation.
- // Be careful that default_fn does not in fact call fn virtually!
+ /// Define a virtual member function with a default implementation.
+ /// default_fn should be a function which provides the default implementation.
+ /// Be careful that default_fn does not in fact call fn virtually!
template
void def(Fn fn, const char* name, DefaultFn default_fn)
{ m_class->def(fn, name, default_fn); }
- // Provide a function which implements x., reading from the given
- // member (pm) of the T obj
+ /// Provide a function which implements x., reading from the given
+ /// member (pm) of the T obj
template
void def_getter(MemberType T::*pm, const char* name)
{ m_class->def_getter(pm, name); }
- // Provide a function which implements assignment to x., writing to
- // the given member (pm) of the T obj
+ /// Provide a function which implements assignment to x., writing to
+ /// the given member (pm) of the T obj
template
void def_setter(MemberType T::*pm, const char* name)
{ m_class->def_getter(pm, name); }
- // Expose the given member (pm) of the T obj as a read-only attribute
+ /// Expose the given member (pm) of the T obj as a read-only attribute
template
void def_readonly(MemberType T::*pm, const char* name)
{ m_class->def_readonly(pm, name); }
- // Expose the given member (pm) of the T obj as a read/write attribute
+ /// Expose the given member (pm) of the T obj as a read/write attribute
template
void def_read_write(MemberType T::*pm, const char* name)
{ m_class->def_read_write(pm, name); }
- // define the standard coercion needed for operator overloading
+ /// define the standard coercion needed for operator overloading
void def_standard_coerce()
{ m_class->def_standard_coerce(); }
- // declare the given class a base class of this one and register
- // conversion functions
+ /// declare the given class a base class of this one and register
+ /// conversion functions
template
void declare_base(class_builder const & base)
{
m_class->declare_base(base.get_extension_class());
}
- // declare the given class a base class of this one and register
- // upcast conversion function
+ /// declare the given class a base class of this one and register
+ /// upcast conversion function
template
void declare_base(class_builder const & base, without_downcast_t)
{
m_class->declare_base(base.get_extension_class(), without_downcast);
}
- // get the embedded ExtensioClass object
+ /// get the embedded ExtensioClass object
detail::extension_class * get_extension_class() const
{
return m_class.get();
}
- // set an arbitrary attribute. Useful for non-function class data members,
- // e.g. enums
+ /// set an arbitrary attribute. Useful for non-function class data members,
+ /// e.g. enums
void add(PyObject* x, const char* name)
{ m_class->set_attribute(name, x); }
void add(ref x, const char* name)
@@ -143,8 +144,8 @@ class class_builder
m_class->declare_base(base);
}
- // declare the given class a base class of this one and register
- // upcast conversion function
+ /// declare the given class a base class of this one and register
+ /// upcast conversion function
template
void declare_base(detail::extension_class * base, without_downcast_t)
{
diff --git a/include/boost/python/classes.hpp b/include/boost/python/classes.hpp
index d38fbba5..688b0bef 100644
--- a/include/boost/python/classes.hpp
+++ b/include/boost/python/classes.hpp
@@ -284,14 +284,14 @@ PyObject* class_t::instance_mapping_subscript(PyObject* obj, PyObject* key) c
template
PyObject* class_t::instance_sequence_item(PyObject* obj, int n) const
{
- ref key(to_python(n));
+ ref key(to_python(search_namespace, n));
return downcast(obj)->get_subscript(key.get());
}
template
int class_t::instance_sequence_ass_item(PyObject* obj, int n, PyObject* value) const
{
- ref key(to_python(n));
+ ref key(to_python(search_namespace, n));
downcast(obj)->set_subscript(key.get(), value);
return 0;
}
diff --git a/include/boost/python/conversions.hpp b/include/boost/python/conversions.hpp
index 47f80989..cf102aea 100644
--- a/include/boost/python/conversions.hpp
+++ b/include/boost/python/conversions.hpp
@@ -52,9 +52,9 @@ class py_enum_as_int_converters
from_python(x, boost::python::type()));
}
- friend PyObject* to_python(EnumType x)
+ friend PyObject* to_python(boost::python::semantics, EnumType x)
{
- return to_python(static_cast(x));
+ return to_python(boost::python::search_namespace, static_cast(x));
}
};
BOOST_PYTHON_END_CONVERSION_NAMESPACE
@@ -116,70 +116,70 @@ BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE
//
// Converters
//
-PyObject* to_python(long);
+PyObject* to_python(boost::python::search_namespace, long);
long from_python(PyObject* p, boost::python::type);
long from_python(PyObject* p, boost::python::type);
-PyObject* to_python(unsigned long);
+PyObject* to_python(boost::python::search_namespace, unsigned long);
unsigned long from_python(PyObject* p, boost::python::type);
unsigned long from_python(PyObject* p, boost::python::type);
-PyObject* to_python(int);
+PyObject* to_python(boost::python::search_namespace, int);
int from_python(PyObject*, boost::python::type);
int from_python(PyObject*, boost::python::type);
-PyObject* to_python(unsigned int);
+PyObject* to_python(boost::python::search_namespace, unsigned int);
unsigned int from_python(PyObject*, boost::python::type);
unsigned int from_python(PyObject*, boost::python::type);
-PyObject* to_python(short);
+PyObject* to_python(boost::python::search_namespace, short);
short from_python(PyObject*, boost::python::type);
short from_python(PyObject*, boost::python::type);
-PyObject* to_python(unsigned short);
+PyObject* to_python(boost::python::search_namespace, unsigned short);
unsigned short from_python(PyObject*, boost::python::type);
unsigned short from_python(PyObject*, boost::python::type);
-PyObject* to_python(char);
+PyObject* to_python(boost::python::search_namespace, char);
char from_python(PyObject*, boost::python::type);
char from_python(PyObject*, boost::python::type);
-PyObject* to_python(signed char);
+PyObject* to_python(boost::python::search_namespace, signed char);
signed char from_python(PyObject*, boost::python::type);
signed char from_python(PyObject*, boost::python::type);
-PyObject* to_python(unsigned char);
+PyObject* to_python(boost::python::search_namespace, unsigned char);
unsigned char from_python(PyObject*, boost::python::type);
unsigned char from_python(PyObject*, boost::python::type);
-PyObject* to_python(float);
+PyObject* to_python(boost::python::search_namespace, float);
float from_python(PyObject*, boost::python::type);
float from_python(PyObject*, boost::python::type);
-PyObject* to_python(double);
+PyObject* to_python(boost::python::search_namespace, double);
double from_python(PyObject*, boost::python::type);
double from_python(PyObject*, boost::python::type);
-PyObject* to_python(bool);
+PyObject* to_python(boost::python::search_namespace, bool);
bool from_python(PyObject*, boost::python::type);
bool from_python(PyObject*, boost::python::type);
-PyObject* to_python(void);
+PyObject* to_python(boost::python::search_namespace, void);
void from_python(PyObject*, boost::python::type);
-PyObject* to_python(const char* s);
+PyObject* to_python(boost::python::search_namespace, const char* s);
const char* from_python(PyObject*, boost::python::type);
-PyObject* to_python(const std::string& s);
+PyObject* to_python(boost::python::search_namespace, const std::string& s);
std::string from_python(PyObject*, boost::python::type);
std::string from_python(PyObject*, boost::python::type);
-inline PyObject* to_python(const std::complex& x)
+inline PyObject* to_python(boost::python::search_namespace, const std::complex& x)
{
return boost::python::detail::complex_to_python(x);
}
-inline PyObject* to_python(const std::complex& x)
+inline PyObject* to_python(boost::python::search_namespace, const std::complex& x)
{
return boost::python::detail::complex_to_python(x);
}
@@ -205,7 +205,7 @@ inline std::complex from_python(PyObject* p,
}
// For when your C++ function really wants to pass/return a PyObject*
-PyObject* to_python(PyObject*);
+PyObject* to_python(boost::python::search_namespace, PyObject*);
PyObject* from_python(PyObject*, boost::python::type);
// Some standard conversions to/from smart pointer types. You can add your own
@@ -259,13 +259,13 @@ boost::shared_ptr from_python(PyObject*p, boost::python::type
-PyObject* to_python(std::auto_ptr p)
+PyObject* to_python(boost::python::search_namespace, std::auto_ptr p)
{
return new boost::python::wrapped_pointer, T>(p);
}
template
-PyObject* to_python(boost::shared_ptr p)
+PyObject* to_python(boost::python::search_namespace, boost::shared_ptr p)
{
return new boost::python::wrapped_pointer, T>(p);
}
@@ -276,43 +276,43 @@ PyObject* to_python(boost::shared_ptr p)
//
#ifndef BOOST_MSVC6_OR_EARLIER
-inline PyObject* to_python(double d)
+inline PyObject* to_python(boost::python::search_namespace, double d)
{
return PyFloat_FromDouble(d);
}
-inline PyObject* to_python(float f)
+inline PyObject* to_python(boost::python::search_namespace, float f)
{
return PyFloat_FromDouble(f);
}
#endif // BOOST_MSVC6_OR_EARLIER
-inline PyObject* to_python(long l)
+inline PyObject* to_python(boost::python::search_namespace, long l)
{
return PyInt_FromLong(l);
}
-inline PyObject* to_python(int x)
+inline PyObject* to_python(boost::python::search_namespace, int x)
{
return PyInt_FromLong(x);
}
-inline PyObject* to_python(short x)
+inline PyObject* to_python(boost::python::search_namespace, short x)
{
return PyInt_FromLong(x);
}
-inline PyObject* to_python(bool b)
+inline PyObject* to_python(boost::python::search_namespace, bool b)
{
return PyInt_FromLong(b);
}
-inline PyObject* to_python(void)
+inline PyObject* to_python(boost::python::search_namespace, void)
{
return boost::python::detail::none();
}
-inline PyObject* to_python(const char* s)
+inline PyObject* to_python(boost::python::search_namespace, const char* s)
{
return PyString_FromString(s);
}
@@ -322,7 +322,7 @@ inline std::string from_python(PyObject* p, boost::python::type());
}
-inline PyObject* to_python(PyObject* p)
+inline PyObject* to_python(boost::python::search_namespace, PyObject* p)
{
Py_INCREF(p);
return p;
diff --git a/include/boost/python/cross_module.hpp b/include/boost/python/cross_module.hpp
index 7c1fe507..ff4d56f1 100644
--- a/include/boost/python/cross_module.hpp
+++ b/include/boost/python/cross_module.hpp
@@ -66,8 +66,8 @@ class python_import_extension_class_converters
return python_import_extension_class_converters();
}
- PyObject* to_python(const T& x) const {
- return boost::python::detail::import_extension_class::get_converters()->to_python(x);
+ PyObject* to_python(boost::python::semantics, const T& x) const {
+ return boost::python::detail::import_extension_class::get_converters()->to_python(boost::python::search_namespace, x);
}
friend T* from_python(PyObject* p, boost::python::type t, bool sig = false) {
@@ -101,8 +101,8 @@ class python_import_extension_class_converters
friend const std::auto_ptr& from_python(PyObject* p, boost::python::type&> t, bool sig = false) {
return boost::python::detail::import_extension_class::get_converters()->from_python_caTr(p, t);
}
- friend PyObject* to_python(std::auto_ptr x, bool sig = false) {
- return boost::python::detail::import_extension_class::get_converters()->to_python(x);
+ friend PyObject* to_python(boost::python::semantics, std::auto_ptr x, bool sig = false) {
+ return boost::python::detail::import_extension_class::get_converters()->to_python(boost::python::search_namespace, x);
}
friend boost::shared_ptr& from_python(PyObject* p, boost::python::type&> t, bool sig = false) {
@@ -114,7 +114,7 @@ class python_import_extension_class_converters
friend const boost::shared_ptr& from_python(PyObject* p, boost::python::type&> t, bool sig = false) {
return boost::python::detail::import_extension_class::get_converters()->from_python_csTr(p, t);
}
- friend PyObject* to_python(boost::shared_ptr x, bool sig = false) {
+ friend PyObject* to_python(boost::python::semantics, boost::shared_ptr x, bool sig = false) {
return boost::python::detail::import_extension_class::get_converters()->to_python(x);
}
};
@@ -142,22 +142,22 @@ struct export_converter_object_base
virtual PyObject* to_python(const T& x) = 0;
- virtual T* from_python_Ts(PyObject* p, boost::python::type t) = 0;
- virtual const T* from_python_cTs(PyObject* p, boost::python::type t) = 0;
- virtual const T* from_python_cTscr(PyObject* p, boost::python::type t) = 0;
- virtual T* from_python_Tscr(PyObject* p, boost::python::type t) = 0;
- virtual T& from_python_Tr(PyObject* p, boost::python::type t) = 0;
- virtual const T& from_python_cTr(PyObject* p, boost::python::type t) = 0;
- virtual const T& from_python_T(PyObject* p, boost::python::type t) = 0;
+ virtual T* from_python_Ts(PyObject* p, type t) = 0;
+ virtual const T* from_python_cTs(PyObject* p, type t) = 0;
+ virtual const T* from_python_cTscr(PyObject* p, type t) = 0;
+ virtual T* from_python_Tscr(PyObject* p, type t) = 0;
+ virtual T& from_python_Tr(PyObject* p, type t) = 0;
+ virtual const T& from_python_cTr(PyObject* p, type t) = 0;
+ virtual const T& from_python_T(PyObject* p, type t) = 0;
- virtual std::auto_ptr& from_python_aTr(PyObject* p, boost::python::type&> t) = 0;
- virtual std::auto_ptr from_python_aT(PyObject* p, boost::python::type > t) = 0;
- virtual const std::auto_ptr& from_python_caTr(PyObject* p, boost::python::type&> t) = 0;
+ virtual std::auto_ptr& from_python_aTr(PyObject* p, type&> t) = 0;
+ virtual std::auto_ptr from_python_aT(PyObject* p, type > t) = 0;
+ virtual const std::auto_ptr& from_python_caTr(PyObject* p, type&> t) = 0;
virtual PyObject* to_python(std::auto_ptr x) = 0;
- virtual boost::shared_ptr& from_python_sTr(PyObject* p, boost::python::type&> t) = 0;
- virtual const boost::shared_ptr& from_python_sT(PyObject* p, boost::python::type > t) = 0;
- virtual const boost::shared_ptr& from_python_csTr(PyObject* p, boost::python::type&> t) = 0;
+ virtual boost::shared_ptr& from_python_sTr(PyObject* p, type&> t) = 0;
+ virtual const boost::shared_ptr& from_python_sT(PyObject* p, type > t) = 0;
+ virtual const boost::shared_ptr& from_python_csTr(PyObject* p, type&> t) = 0;
virtual PyObject* to_python(boost::shared_ptr x) = 0;
};
@@ -171,52 +171,52 @@ struct export_converter_object_noncopyable : export_converter_object_base
throw import_error();
}
- virtual T* from_python_Ts(PyObject* p, boost::python::type t) {
- return BOOST_PYTHON_CONVERSION::from_python(p, t);
+ virtual T* from_python_Ts(PyObject* p, type t) {
+ return from_python(p, t);
}
- virtual const T* from_python_cTs(PyObject* p, boost::python::type t) {
- return BOOST_PYTHON_CONVERSION::from_python(p, t);
+ virtual const T* from_python_cTs(PyObject* p, type t) {
+ return from_python(p, t);
}
- virtual const T* from_python_cTscr(PyObject* p, boost::python::type t) {
- return BOOST_PYTHON_CONVERSION::from_python(p, t);
+ virtual const T* from_python_cTscr(PyObject* p, type t) {
+ return from_python(p, t);
}
- virtual T* from_python_Tscr(PyObject* p, boost::python::type t) {
- return BOOST_PYTHON_CONVERSION::from_python(p, t);
+ virtual T* from_python_Tscr(PyObject* p, type t) {
+ return from_python(p, t);
}
- virtual T& from_python_Tr(PyObject* p, boost::python::type t) {
- return BOOST_PYTHON_CONVERSION::from_python(p, t);
+ virtual T& from_python_Tr(PyObject* p, type t) {
+ return from_python(p, t);
}
- virtual const T& from_python_cTr(PyObject* p, boost::python::type t) {
- return BOOST_PYTHON_CONVERSION::from_python(p, t);
+ virtual const T& from_python_cTr(PyObject* p, type t) {
+ return from_python(p, t);
}
- virtual const T& from_python_T(PyObject* p, boost::python::type t) {
- return BOOST_PYTHON_CONVERSION::from_python(p, t);
+ virtual const T& from_python_T(PyObject* p, type t) {
+ return from_python(p, t);
}
- virtual std::auto_ptr& from_python_aTr(PyObject* p, boost::python::type&> t) {
- return BOOST_PYTHON_CONVERSION::from_python(p, t);
+ virtual std::auto_ptr& from_python_aTr(PyObject* p, type&> t) {
+ return from_python(p, t);
}
- virtual std::auto_ptr from_python_aT(PyObject* p, boost::python::type > t) {
- return BOOST_PYTHON_CONVERSION::from_python(p, t);
+ virtual std::auto_ptr from_python_aT(PyObject* p, type > t) {
+ return from_python(p, t);
}
- virtual const std::auto_ptr& from_python_caTr(PyObject* p, boost::python::type&> t) {
- return BOOST_PYTHON_CONVERSION::from_python(p, t);
+ virtual const std::auto_ptr& from_python_caTr(PyObject* p, type&> t) {
+ return from_python(p, t);
}
virtual PyObject* to_python(std::auto_ptr x) {
- return BOOST_PYTHON_CONVERSION::to_python(x);
+ return to_python(x);
}
- virtual boost::shared_ptr& from_python_sTr(PyObject* p, boost::python::type&> t) {
- return BOOST_PYTHON_CONVERSION::from_python(p, t);
+ virtual boost::shared_ptr& from_python_sTr(PyObject* p, type&> t) {
+ return from_python(p, t);
}
- virtual const boost::shared_ptr& from_python_sT(PyObject* p, boost::python::type > t) {
- return BOOST_PYTHON_CONVERSION::from_python(p, t);
+ virtual const boost::shared_ptr& from_python_sT(PyObject* p, type > t) {
+ return from_python(p, t);
}
- virtual const boost::shared_ptr& from_python_csTr(PyObject* p, boost::python::type&> t) {
- return BOOST_PYTHON_CONVERSION::from_python(p, t);
+ virtual const boost::shared_ptr& from_python_csTr(PyObject* p, type&> t) {
+ return from_python(p, t);
}
virtual PyObject* to_python(boost::shared_ptr x) {
- return BOOST_PYTHON_CONVERSION::to_python(x);
+ return to_python(x);
}
};
@@ -225,7 +225,7 @@ template
struct export_converter_object : export_converter_object_noncopyable
{
virtual PyObject* to_python(const T& x) {
- return BOOST_PYTHON_CONVERSION::py_extension_class_converters(boost::python::type()).to_python(x);
+ return BOOST_PYTHON_CONVERSION::py_extension_class_converters(type()).to_python(x);
}
};
@@ -247,29 +247,29 @@ class import_extension_class
m_py_class = py_class;
}
- static boost::python::export_converter_object_base* get_converters();
+ static export_converter_object_base* get_converters();
private:
static std::string m_module;
static std::string m_py_class;
- static boost::python::export_converter_object_base* imported_converters;
+ static export_converter_object_base* imported_converters;
};
template std::string import_extension_class::m_module;
template std::string import_extension_class::m_py_class;
template
-boost::python::export_converter_object_base*
+export_converter_object_base*
import_extension_class::imported_converters = 0;
template
-boost::python::export_converter_object_base*
+export_converter_object_base*
import_extension_class::get_converters() {
if (imported_converters == 0) {
void* cobject
= import_converter_object(m_module, m_py_class,
converters_attribute_name);
imported_converters
- = static_cast*>(cobject);
+ = static_cast*>(cobject);
check_export_converters_api(
export_converters_api_major,
export_converters_api_minor,
diff --git a/include/boost/python/detail/extension_class.hpp b/include/boost/python/detail/extension_class.hpp
index 5c8e720a..5f893f26 100644
--- a/include/boost/python/detail/extension_class.hpp
+++ b/include/boost/python/detail/extension_class.hpp
@@ -179,31 +179,32 @@ template >
class python_extension_class_converters
{
public:
- // Get an object which can be used to convert T to/from python. This is used
- // as a kind of concept check by the global template
- //
- // PyObject* to_python(const T& x)
- //
- // below this class, to prevent the confusing messages that would otherwise
- // pop up. Now, if T hasn't been wrapped as an extension class, the user
- // will see an error message about the lack of an eligible
- // py_extension_class_converters() function.
- friend python_extension_class_converters py_extension_class_converters(boost::python::type)
+ /// Get an object which can be used to convert T to/from python. This is used
+ /// as a kind of concept check by the free template function
+ ///
+ /// PyObject* to_python(boost::python::semantics, const T& x)
+ ///
+ /// below this class, to prevent the confusing messages that would otherwise
+ /// pop up. Now, if T hasn't been wrapped as an extension class, the user
+ /// will see an error message about the lack of an eligible
+ /// py_extension_class_converters() function.
+ friend python_extension_class_converters py_extension_class_converters(
+ boost::python::type)
{
return python_extension_class_converters();
}
- // This is a member function because in a conforming implementation, friend
- // funcitons defined inline in the class body are all instantiated as soon
- // as the enclosing class is instantiated. If T is not copyable, that causes
- // a compiler error. Instead, we access this function through the global
- // template
- //
- // PyObject* to_python(const T& x)
- //
- // defined below this class. Since template functions are instantiated only
- // on demand, errors will be avoided unless T is noncopyable and the user
- // writes code which causes us to try to copy a T.
+ /// This is a member function because in a conforming implementation, friend
+ /// funcitons defined inline in the class body are all instantiated as soon
+ /// as the enclosing class is instantiated. If T is not copyable, that causes
+ /// a compiler error. Instead, we access this function through the global
+ /// template
+ ///
+ /// PyObject* to_python(boost::python::semantics, const T& x)
+ ///
+ /// defined below this class. Since template functions are instantiated only
+ /// on demand, errors will be avoided unless T is noncopyable and the user
+ /// writes code which causes us to try to copy a T.
PyObject* to_python(const T& x) const
{
boost::python::reference result(create_instance());
@@ -213,6 +214,7 @@ class python_extension_class_converters
return result.release();
}
+ /// Extract a pointer to T from the given PyObject. Will throw argument_error if obj == None.
friend
T* non_null_from_python(PyObject* obj, boost::python::type)
{
@@ -235,16 +237,19 @@ class python_extension_class_converters
throw boost::python::argument_error();
}
- // Convert to T*
+ /// Convert obj to T*. If obj == None, returns 0.
friend T* from_python(PyObject* obj, boost::python::type)
{
+ // forward declaration needed for ordinary lookup.
+ T* non_null_from_python(PyObject*, boost::python::type);
+
if (obj == Py_None)
return 0;
else
return non_null_from_python(obj, boost::python::type());
}
- // Extract from obj a mutable reference to the PtrType object which is holding a T.
+ /// Extract from obj a mutable reference to the PtrType object which is holding a T.
template
static PtrType& smart_ptr_reference(PyObject* obj, boost::python::type)
{
@@ -263,10 +268,10 @@ class python_extension_class_converters
throw boost::python::argument_error();
}
- // Extract from obj a reference to the PtrType object which is holding a
- // T. If it weren't for auto_ptr, it would be a constant reference. Do not
- // modify the referent except by copying an auto_ptr! If obj is None, the
- // reference denotes a default-constructed PtrType
+ /// Extract from obj a reference to the PtrType object which is holding a
+ /// T. If it weren't for auto_ptr, it would be a constant reference. Do not
+ /// modify the referent except by copying an auto_ptr! If obj is None, the
+ /// reference denotes a default-constructed PtrType
template
static PtrType& smart_ptr_value(PyObject* obj, boost::python::type)
{
@@ -277,7 +282,9 @@ class python_extension_class_converters
}
return smart_ptr_reference(obj, boost::python::type());
}
-
+
+ /// Wrap x in a Python object which implements the functionality of a
+ /// regular wrapped T by dereferencing a copy of x.
template
static PyObject* smart_ptr_to_python(PtrType x)
{
@@ -293,6 +300,9 @@ class python_extension_class_converters
return result.release();
}
+ /// Create a Python object which is an instance of the Python type wrapper
+ /// for T. The result does not actually contain the neccessary instance of
+ /// T. This function is an implementation detail.
static boost::python::reference create_instance()
{
PyTypeObject* class_object = boost::python::detail::class_registry::class_object();
@@ -303,15 +313,15 @@ class python_extension_class_converters
new boost::python::detail::extension_instance(class_object));
}
- // Convert to const T*
+ /// Convert p to const T*
friend const T* from_python(PyObject* p, boost::python::type)
{ return from_python(p, boost::python::type()); }
- // Convert to const T* const&
+ /// Convert p to const T* const&
friend const T* from_python(PyObject* p, boost::python::type)
{ return from_python(p, boost::python::type()); }
- // Convert to T* const&
+ /// Convert p to T* const&
friend T* from_python(PyObject* p, boost::python::type)
{ return from_python(p, boost::python::type()); }
@@ -319,11 +329,11 @@ class python_extension_class_converters
friend T& from_python(PyObject* p, boost::python::type)
{ return *boost::python::detail::check_non_null(non_null_from_python(p, boost::python::type())); }
- // Convert to const T&
+ // Convert p to const T&
friend const T& from_python(PyObject* p, boost::python::type)
{ return from_python(p, boost::python::type()); }
- // Convert to T
+ /// Convert p to T
friend const T& from_python(PyObject* p, boost::python::type)
{ return from_python(p, boost::python::type()); }
@@ -336,7 +346,7 @@ class python_extension_class_converters
friend const std::auto_ptr& from_python(PyObject* p, boost::python::type&>)
{ return smart_ptr_value(p, boost::python::type >()); }
- friend PyObject* to_python(std::auto_ptr x)
+ friend PyObject* to_python(boost::python::semantics, std::auto_ptr x)
{ return smart_ptr_to_python(x); }
friend boost::shared_ptr