Geant4  10.01.p01
test10.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 // $Id: test10.cc 86624 2014-11-14 08:59:40Z kmura $
27 // ====================================================================
28 // test10.cc
29 //
30 // test for call by-reference
31 //
32 // 2005 Q
33 // ====================================================================
34 #include <iostream>
35 
36 class AClass {
37 public:
38  AClass() {
39  std::cout << "*** AClass is created..." << this
40  << std::endl;
41  }
42 
43  ~AClass() {
44  std::cout << "*** AClass is deleted..." << this
45  << std::endl;
46  }
47 };
48 
49 class BClass {
50 public:
51  BClass() {
52  std::cout << "*** BClass is created..." << this
53  << std::endl;
54  }
55  ~BClass() {
56  std::cout << "*** BClass is deleted..." << this
57  << std::endl;
58  }
59 };
60 
61 class XBase {
62 public:
63  XBase() {}
64  ~XBase() {}
65 
66  virtual void VMethodA(const AClass* a) {
67  std::cout << "*** XBase::VMethod...A() is called." << std::endl;
68  }
69 
70  virtual void VMethodB(const BClass* b) {
71  std::cout << "*** XBase::VMethod...B() is called." << std::endl;
72  }
73 };
74 
75 
76 class ZClass {
77 private:
81 
82 public:
83  ZClass() : xbase(0) { }
84  ~ZClass() { }
85 
86  void SetXBase(XBase* base) {
87  xbase= base;
88  }
89 
90  void Process() {
91  xbase-> VMethodA(&a);
92  xbase-> VMethodB(&b);
93  }
94 };
95 
96 
97 // Boost.Python...
98 #include <boost/python.hpp>
99 
100 using namespace boost::python;
101 
102 // call backs
103 struct CB_XBase : XBase, wrapper<XBase> {
104  void VMethodA(const AClass* a) {
105  if(const override& f= get_override("VMethodA"))
106  f(a);
107  else
108  XBase::VMethodA(a);
109  }
110 
111  void d_VMethodA(const AClass* a) {
112  XBase::VMethodA(a);
113  }
114 
115  //
116  void VMethodB(const BClass* b) {
117  if(const override& f= get_override("VMethodB"))
118  f(b);
119  else
120  XBase::VMethodB(b);
121  }
122 
123  void d_VMethodB(const BClass* b) {
124  XBase::VMethodB(b);
125  }
126 };
127 
128 
130 {
131  class_<AClass, AClass*>("AClass", "a class")
132  .def(init<>())
133  ;
134 
135  class_<BClass>("BClass", "b class")
136  .def(init<>())
137  ;
138 
139  class_<CB_XBase, boost::noncopyable>("XBase", "xbase class")
140  .def(init<>())
141  .def("VMethodA", &XBase::VMethodA, &CB_XBase::d_VMethodA)
142  .def("VMethodB", &XBase::VMethodB, &CB_XBase::d_VMethodB)
143  ;
144 
145  class_<ZClass>("ZClass", "z class")
146  .def(init<>())
147  .def("SetXBase", &ZClass::SetXBase)
148  .def("Process", &ZClass::Process)
149  ;
150 }
151 
void SetXBase(XBase *base)
Definition: test10.cc:86
virtual void VMethodB(const BClass *b)
Definition: test10.cc:70
~BClass()
Definition: test10.cc:55
Definition: AClass.hh:41
AClass()
Definition: test10.cc:38
G4double a
Definition: TRTMaterials.hh:39
~XBase()
Definition: test10.cc:64
ZClass()
Definition: test10.cc:83
BClass b
Definition: test10.cc:79
BOOST_PYTHON_MODULE(test10)
Definition: test10.cc:129
Definition: XBase.hh:41
~ZClass()
Definition: test10.cc:84
~AClass()
Definition: test10.cc:43
void VMethodA(const AClass *a)
Definition: test10.cc:104
void Process()
Definition: test10.cc:90
AClass a
Definition: test10.cc:78
XBase()
Definition: test10.cc:63
void d_VMethodB(const BClass *b)
Definition: test10.cc:123
XBase * xbase
Definition: test10.cc:80
BClass()
Definition: test10.cc:51
virtual void VMethodA(const AClass *a)
Definition: test10.cc:66
Definition: test10.cc:76
void d_VMethodA(const AClass *a)
Definition: test10.cc:111
Definition: BClass.hh:43
void VMethodB(const BClass *b)
Definition: test10.cc:116