Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_33_1/libs/python/test/ben_scott1.cpp @ 12

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

added boost

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.