Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_33_1/libs/python/test/staticmethod.cpp @ 14

Last change on this file since 14 was 12, checked in by landauf, 18 years ago

added boost

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