Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/python/test/auto_ptr.cpp @ 45

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

updated boost from 1_33_1 to 1_34_1

File size: 1.8 KB
Line 
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
6#include <boost/python/module.hpp>
7#include "test_class.hpp"
8#include <boost/python/class.hpp>
9#include <boost/python/extract.hpp>
10#include <boost/python/def.hpp>
11#include <boost/python/implicit.hpp>
12
13#include <boost/detail/workaround.hpp>
14
15#include <memory>
16
17using namespace boost::python;
18
19typedef test_class<> X;
20
21struct Y : X
22{
23    Y(int n) : X(n) {};
24};
25
26int look(std::auto_ptr<X> const& x)
27{
28    return (x.get()) ? x->value() : -1;
29}
30
31int steal(std::auto_ptr<X> x)
32{
33    return x->value();
34}
35
36int maybe_steal(std::auto_ptr<X>& x, bool doit)
37{
38    int n = x->value();
39    if (doit)
40        x.release();
41    return n;
42}
43
44std::auto_ptr<X> make()
45{
46    return std::auto_ptr<X>(new X(77));
47}
48
49std::auto_ptr<X> callback(object f)
50{
51    std::auto_ptr<X> x(new X(77));
52    return call<std::auto_ptr<X> >(f.ptr(), x);
53}
54
55std::auto_ptr<X> extract_(object o)
56{
57    return extract<std::auto_ptr<X>&>(o)
58#if BOOST_MSVC <= 1300
59        ()
60#endif
61        ;
62}
63
64BOOST_PYTHON_MODULE(auto_ptr_ext)
65{
66    class_<X, std::auto_ptr<X>, boost::noncopyable>("X", init<int>())
67        .def("value", &X::value)
68        ;
69   
70    class_<Y, std::auto_ptr<Y>, bases<X>, boost::noncopyable>("Y", init<int>())
71        ;
72
73    // VC6 auto_ptrs do not have converting constructors   
74#if BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, < 306)
75    scope().attr("broken_auto_ptr") = 1;
76#else
77    scope().attr("broken_auto_ptr") = 0;
78    implicitly_convertible<std::auto_ptr<Y>, std::auto_ptr<X> >();
79#endif
80   
81    def("look", look);
82    def("steal", steal);
83    def("maybe_steal", maybe_steal);
84    def("make", make);
85    def("callback", callback);
86    def("extract", extract_);
87}
88
89#include "module_tail.cpp"
90
Note: See TracBrowser for help on using the repository browser.