Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/python/test/ben_scott1.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.2 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#include <boost/python.hpp>
5#include <iostream>
6using namespace boost::python;
7using namespace boost;
8
9struct Product {};
10typedef shared_ptr<Product> ProductPtr;
11
12
13struct Creator
14{
15   virtual ~Creator() {}
16   virtual ProductPtr create() = 0;
17};
18
19
20struct Factory
21{
22   void reg(Creator* c) { mC = c; }
23   ProductPtr create()
24   {
25      std::cout << "Name: " << (typeid(*mC)).name() << std::endl;
26      return mC->create();
27   }
28
29private:
30   Creator* mC;
31};
32
33struct CreatorWrap : public Creator
34{
35   CreatorWrap(PyObject* self) : mSelf(self) {}
36   ProductPtr create() { return call_method<ProductPtr>(mSelf, "create"); }
37   PyObject* mSelf;
38};
39
40BOOST_PYTHON_MODULE(ben_scott1_ext)
41{
42   class_<Product, ProductPtr>("Product");
43
44   class_<Creator, CreatorWrap, noncopyable>("Creator")
45       .def("create", &CreatorWrap::create)
46       ;
47
48   class_<Factory>("Factory")
49      .def("reg", &Factory::reg, with_custodian_and_ward<1,2>())
50      .def("create", &Factory::create)
51       ;
52}
53
54#include "../test/module_tail.cpp"
Note: See TracBrowser for help on using the repository browser.