Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/python/test/staticmethod.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.3 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/class.hpp>
7#include <boost/python/module.hpp>
8#include <boost/python/def.hpp>
9#include <boost/python/call_method.hpp>
10#include <boost/ref.hpp>
11#include <boost/utility.hpp>
12#include <boost/assert.hpp>
13
14using namespace boost::python;
15
16struct X
17{
18    explicit X(int x) : x(x), magic(7654321) { ++counter; }
19    X(X const& rhs) : x(rhs.x), magic(7654321) { ++counter; }
20    virtual ~X() { BOOST_ASSERT(magic == 7654321); magic = 6666666; x = 9999; --counter; }
21
22    void set(int x) { BOOST_ASSERT(magic == 7654321); this->x = x; }
23    int value() const { BOOST_ASSERT(magic == 7654321); return x; }
24    static int count() { return counter; }
25 private:
26    void operator=(X const&);
27 private:
28    int x;
29    long magic;
30    static int counter;
31};
32int X::counter;
33int getXmagic(){return 7654321;}
34
35BOOST_PYTHON_MODULE(staticmethod_ext)
36{
37    class_<X>("X", init<int>())
38        .def("value", &X::value)
39        .def("set", &X::set)
40        .def("count", &X::count)
41        .staticmethod("count")
42        .def("magic", &getXmagic)
43        .staticmethod("magic")
44        ;
45}
46
47#include "module_tail.cpp"
Note: See TracBrowser for help on using the repository browser.