1 | // Copyright David Abrahams 2002. |
---|
2 | // Distributed under the Boost Software License, Version 1.0. (See |
---|
3 | // accompanying file LICENSE_1_0.txt or copy at |
---|
4 | // http://www.boost.org/LICENSE_1_0.txt) |
---|
5 | #include <boost/python/operators.hpp> |
---|
6 | #include <boost/python/class.hpp> |
---|
7 | #include <boost/python/module.hpp> |
---|
8 | #include <boost/python/def.hpp> |
---|
9 | #include <boost/python/scope.hpp> |
---|
10 | #include <boost/python/manage_new_object.hpp> |
---|
11 | #include "test_class.hpp" |
---|
12 | |
---|
13 | // Just use math.h here; trying to use std::pow() causes too much |
---|
14 | // trouble for non-conforming compilers and libraries. |
---|
15 | #include <math.h> |
---|
16 | |
---|
17 | using namespace boost::python; |
---|
18 | |
---|
19 | typedef test_class<> X; |
---|
20 | |
---|
21 | X* create(int x) |
---|
22 | { |
---|
23 | return new X(x); |
---|
24 | } |
---|
25 | |
---|
26 | unsigned long fact(unsigned long n) |
---|
27 | { |
---|
28 | return n <= 1 ? n : n * fact(n - 1); |
---|
29 | } |
---|
30 | |
---|
31 | BOOST_PYTHON_MODULE(docstring_ext) |
---|
32 | { |
---|
33 | scope().attr("__doc__") = |
---|
34 | "A simple test module for documentation strings\n" |
---|
35 | "Exercised by docstring.py" |
---|
36 | ; |
---|
37 | |
---|
38 | class_<X>("X", |
---|
39 | "A simple class wrapper around a C++ int\n" |
---|
40 | "includes some error-checking" |
---|
41 | |
---|
42 | , init<int>( |
---|
43 | "this is the __init__ function\n" |
---|
44 | "its documentation has two lines." |
---|
45 | ) |
---|
46 | |
---|
47 | ) |
---|
48 | .def("value", &X::value, |
---|
49 | "gets the value of the object") |
---|
50 | .def( "value", &X::value, |
---|
51 | "also gets the value of the object") |
---|
52 | ; |
---|
53 | |
---|
54 | def("create", create, return_value_policy<manage_new_object>(), |
---|
55 | "creates a new X object"); |
---|
56 | |
---|
57 | def("fact", fact, "compute the factorial"); |
---|
58 | } |
---|
59 | |
---|
60 | #include "module_tail.cpp" |
---|