Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/python/test/raw_ctor.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.1 KB
Line 
1// Copyright David Abrahams 2004. Distributed under the Boost
2// Software License, Version 1.0. (See accompanying
3// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
4
5#include <boost/python/class.hpp>
6#include <boost/python/raw_function.hpp>
7#include <boost/python/make_constructor.hpp>
8#include <boost/python/dict.hpp>
9#include <boost/python/tuple.hpp>
10#include <boost/python/module.hpp>
11
12using namespace boost::python;
13
14class Foo
15{
16 public:
17    Foo(tuple args, dict kw)
18      : args(args), kw(kw) {}
19   
20    tuple args;
21    dict kw;
22};
23
24object init_foo(tuple args, dict kw)
25{
26    tuple rest(args.slice(1,_));
27    return args[0].attr("__init__")(rest, kw);
28}
29
30BOOST_PYTHON_MODULE(raw_ctor_ext)
31{
32    // using no_init postpones defining __init__ function until after
33    // raw_function for proper overload resolution order, since later
34    // defs get higher priority.
35    class_<Foo>("Foo", no_init) 
36        .def("__init__", raw_function(&init_foo))
37        .def(init<tuple, dict>())
38        .def_readwrite("args", &Foo::args)
39        .def_readwrite("kw", &Foo::kw)
40        ;
41}
42
43#include "module_tail.cpp"
Note: See TracBrowser for help on using the repository browser.