Requires: The first form requires that the expression
function0<void>(f)
+ href="../../../function/doc/reference.html#functionN">function0<void>(f)
is valid. The second form requires that a C++ exception is currently
being handled (see section 15.1 in the C++ standard).
diff --git a/doc/v2/foo.cpp b/doc/v2/foo.cpp
deleted file mode 100644
index e92c2d72..00000000
--- a/doc/v2/foo.cpp
+++ /dev/null
@@ -1,142 +0,0 @@
-// 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
-#include
-#include
-#include
-
-class Bar { int x; }
-
-class Foo
-{
- public:
- Foo(int x) : b(x) {}
- Bar const& get_bar() const { return b; }
- private:
- Bar b;
-};
-
-using namespace boost::python;
-BOOST_PYTHON_MODULE_INIT(my_module)
-{
- module m("my_module")
- .add(
- class_()
- )
- .add(
- class_()
- .def_init(args())
- .def("get_bar", &Foo::get_bar
- , return_value_policy())
- )
-}
-
-using namespace boost::python;
-ref foo =
-class_ >()
- .def_init(args())
- .def_init(args())
- .def("get_name", &Foo::get_name, return_internal_reference<>())
- .def("set_name", &Foo::set_name)
- .object();
-
-
-
-#include <string>
-#include <boost/python/errors.hpp>
-#include <boost/python/reference.hpp>
-
-// Returns a std::string which has the same value as obj's "__name__"
-// attribute.
-std::string get_name(boost::python::ref obj)
-{
- // throws if there's no __name__ attribute
- PyObject* p = boost::python::expect_non_null(
- PyObject_GetAttrString(obj.get(), "__name__"));
-
- // throws if it's not a Python string
- std::string result(
- boost::python::expect_non_null(
- PyString_AsString(p)));
-
- Py_XDECREF(p); // Done with p
-
- return result;
-}
-
-//
-// Demonstrate form 1 of handle_exception
-//
-
-// Place a Python Int object whose value is 1 if a and b have
-// identical "__name__" attributes, 0 otherwise.
-void same_name_impl(PyObject*& result, PyObject* a, PyObject* b)
-{
- result = PyInt_FromLong(
- get_name(boost::python::ref(a1)) == get_name(boost::python::ref(a2)));
-}
-
-// This is an example Python 'C' API interface function
-extern "C" PyObject*
-same_name(PyObject* args, PyObject* keywords)
-{
- PyObject* a1;
- PyObject* a2;
- PyObject* result = 0;
-
- if (!PyArg_ParseTuple(args, const_cast<char*>("OO"), &a1, &a2))
- return 0;
-
- // Use boost::bind to make an object compatible with
- // boost::Function0<void>
- if (boost::python::handle_exception(
- boost::bind<void>(same_name_impl, boost::ref(result), a1, a2)))
- {
- // an exception was thrown; the Python error was set by
- // handle_exception()
- return 0;
- }
-
- return result;
-}
-
-//
-// Demonstrate form 2 of handle_exception. Not well-supported by all
-// compilers.
-//
-extern "C" PyObject*
-same_name2(PyObject* args, PyObject* keywords)
-{
- PyObject* a1;
- PyObject* a2;
- PyObject* result = 0;
-
- if (!PyArg_ParseTuple(args, const_cast<char*>("OO"), &a1, &a2))
- return 0;
- try {
- return PyInt_FromLong(
- get_name(boost::python::ref(a1)) == get_name(boost::python::ref(a2)));
- }
- catch(...)
- {
- // If an exception was thrown, translate it to Python
- boost::python::handle_exception();
- return 0;
- }
-}
-
-
+
+make_function() and
+make_constructor()
+are the functions used internally by class_<>::def,
+class_<>::def,
+and
+class_<>::def_init
+to produce Python callable objects which wrap C++ functions and member
+functions.
+
Requires:F is a function pointer or member
+ function pointer type
+
+
Effects: Creates a Python callable object which, when
+ called from Python, converts its arguments to C++ and calls
+ f. If F is a pointer-to-member-function
+ type, the target object of the function call (*this)
+ will be taken from the first Python argument, and subsequent Python
+ arguments will be used as the arguments to f. If
+ policies are supplied, it must be a model of CallPolicies, and will be applied to
+ the function as described here.
+
+
Returns: A pointer convertible to PyObject*
+ which refers to the new Python callable object.
Requires:T is a class
+ type. ArgList is an MPL sequence of C++
+ argument types (A1, A2,... AN) such that if
+ a1, a2... aN are objects of type
+ A1, A2,... AN respectively, the expression
+ new Generator::apply<T>::type(a1, a2... aN) is
+ valid. Generator is a model of HolderGenerator.
+
+
+
Effects: Creates a Python callable object which, when
+ called from Python, expects its first argument to be a Boost.Python
+ extension class object. It converts its remaining its arguments to
+ C++ and passes them to the constructor of a dynamically-allocated
+ Generator::apply<T>::type object. The result is
+ installed in the extension class object.
+
+
+
+
Returns: The new Python callable object
+
+
+
+
Example
+
+
C++ function exposed below returns a callable object wrapping one
+of two functions.
+
+
+manage_new_object is a model of ResultConverterGenerator
+which can be used to wrap C++ functions which return a pointer to an
+object allocated with a new-expression, and expect the caller
+to take responsibility for deleting that object.
+