1 | // Copyright David Abrahams and Gottfried Ganssauge 2003. |
---|
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/return_opaque_pointer.hpp> |
---|
6 | # include <boost/python/def.hpp> |
---|
7 | # include <boost/python/module.hpp> |
---|
8 | # include <boost/python/return_value_policy.hpp> |
---|
9 | |
---|
10 | typedef struct opaque_ *opaque; |
---|
11 | typedef struct opaque2_ *opaque2; |
---|
12 | |
---|
13 | opaque the_op = ((opaque) 0x47110815); |
---|
14 | opaque2 the_op2 = ((opaque2) 0x08154711); |
---|
15 | |
---|
16 | opaque get() { return the_op; } |
---|
17 | |
---|
18 | void use(opaque op) |
---|
19 | { |
---|
20 | if (op != the_op) |
---|
21 | throw std::runtime_error (std::string ("failed")); |
---|
22 | } |
---|
23 | |
---|
24 | int useany(opaque op) |
---|
25 | { |
---|
26 | return op ? 1 : 0; |
---|
27 | } |
---|
28 | |
---|
29 | opaque getnull() |
---|
30 | { |
---|
31 | return 0; |
---|
32 | } |
---|
33 | |
---|
34 | void failuse (opaque op) |
---|
35 | { |
---|
36 | if (op == the_op) |
---|
37 | throw std::runtime_error (std::string ("success")); |
---|
38 | } |
---|
39 | |
---|
40 | opaque2 get2 () { return the_op2; } |
---|
41 | |
---|
42 | void use2 (opaque2 op) |
---|
43 | { |
---|
44 | if (op != the_op2) |
---|
45 | throw std::runtime_error (std::string ("failed")); |
---|
46 | } |
---|
47 | |
---|
48 | void failuse2 (opaque2 op) |
---|
49 | { |
---|
50 | if (op == the_op2) |
---|
51 | throw std::runtime_error (std::string ("success")); |
---|
52 | } |
---|
53 | |
---|
54 | BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID(opaque_) |
---|
55 | BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID(opaque2_) |
---|
56 | |
---|
57 | namespace bpl = boost::python; |
---|
58 | |
---|
59 | BOOST_PYTHON_MODULE(opaque_ext) |
---|
60 | { |
---|
61 | bpl::def ( |
---|
62 | "get", &::get, bpl::return_value_policy<bpl::return_opaque_pointer>()); |
---|
63 | bpl::def ("use", &::use); |
---|
64 | bpl::def ("useany", &::useany); |
---|
65 | bpl::def ("getnull", &::getnull, bpl::return_value_policy<bpl::return_opaque_pointer>()); |
---|
66 | bpl::def ("failuse", &::failuse); |
---|
67 | |
---|
68 | bpl::def ( |
---|
69 | "get2", |
---|
70 | &::get2, |
---|
71 | bpl::return_value_policy<bpl::return_opaque_pointer>()); |
---|
72 | bpl::def ("use2", &::use2); |
---|
73 | bpl::def ("failuse2", &::failuse2); |
---|
74 | } |
---|
75 | |
---|
76 | # include "module_tail.cpp" |
---|