// Copyright David Abrahams 2002.
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define BOOST_ENABLE_ASSERT_HANDLER
#include
using namespace boost::python;
BOOST_STATIC_ASSERT(converter::is_object_manager >::value);
int apply_int_int(PyObject* f, int x)
{
return call(f, x);
}
void apply_void_int(PyObject* f, int x)
{
call(f, x);
}
struct X
{
explicit X(int x) : x(x), magic(7654321) { ++counter; }
X(X const& rhs) : x(rhs.x), magic(7654321) { ++counter; }
~X() { BOOST_ASSERT(magic == 7654321); magic = 6666666; x = 9999; --counter; }
void set(int _x) { BOOST_ASSERT(magic == 7654321); this->x = _x; }
int value() const { BOOST_ASSERT(magic == 7654321); return x; }
static int count() { return counter; }
private:
void operator=(X const&);
private:
int x;
long magic;
static int counter;
};
X apply_X_X(PyObject* f, X x)
{
return call(f, x);
}
void apply_void_X_ref(PyObject* f, X& x)
{
call(f, boost::ref(x));
}
X& apply_X_ref_handle(PyObject* f, handle<> obj)
{
return call(f, obj);
}
X* apply_X_ptr_handle_cref(PyObject* f, handle<> const& obj)
{
return call(f, obj);
}
void apply_void_X_cref(PyObject* f, X const& x)
{
call(f, boost::cref(x));
}
void apply_void_X_ptr(PyObject* f, X* x)
{
call(f, ptr(x));
}
void apply_void_X_deep_ptr(PyObject* f, X* x)
{
call(f, x);
}
char const* apply_cstring_cstring(PyObject* f, char const* s)
{
return call(f, s);
}
char const* apply_cstring_pyobject(PyObject* f, PyObject* s)
{
return call(f, borrowed(s));
}
char apply_char_char(PyObject* f, char c)
{
return call(f, c);
}
char const* apply_to_string_literal(PyObject* f)
{
return call(f, "hello, world");
}
handle<> apply_to_own_type(handle<> x)
{
// Tests that we can return handle<> from a callback and that we
// can pass arbitrary handle.
return call >(x.get(), type_handle(borrowed(x->ob_type)));
}
object apply_object_object(PyObject* f, object x)
{
return call