Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/python/test/opaque.cpp @ 29

Last change on this file since 29 was 29, checked in by landauf, 16 years ago

updated boost from 1_33_1 to 1_34_1

File size: 1.8 KB
Line 
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
10typedef struct opaque_ *opaque;
11typedef struct opaque2_ *opaque2;
12
13opaque the_op   = ((opaque) 0x47110815);
14opaque2 the_op2 = ((opaque2) 0x08154711);
15
16opaque get() { return the_op; }
17
18void use(opaque op)
19{
20    if (op != the_op)
21        throw std::runtime_error (std::string ("failed"));
22}
23
24int useany(opaque op)
25{
26    return op ? 1 : 0;
27}
28
29opaque getnull()
30{
31    return 0;
32}
33
34void failuse (opaque op)
35{
36    if (op == the_op)
37        throw std::runtime_error (std::string ("success"));
38}
39
40opaque2 get2 () { return the_op2; }
41
42void use2 (opaque2 op)
43{
44    if (op != the_op2)
45        throw std::runtime_error (std::string ("failed"));
46}
47
48void failuse2 (opaque2 op)
49{
50    if (op == the_op2)
51        throw std::runtime_error (std::string ("success"));
52}
53
54BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID(opaque_)
55BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID(opaque2_)
56
57namespace bpl = boost::python;
58
59BOOST_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"
Note: See TracBrowser for help on using the repository browser.