Geant4_10
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 66892 2013-01-17 10:57:59Z gunter $
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:
78  AClass a;
79  BClass b;
80  XBase* xbase;
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
tuple a
Definition: test.py:11
Definition: AClass.hh:41
AClass()
Definition: test10.cc:38
~XBase()
Definition: test10.cc:64
ZClass()
Definition: test10.cc:83
TFile f
Definition: plotHisto.C:6
~ZClass()
Definition: test10.cc:84
~AClass()
Definition: test10.cc:43
void VMethodA(const AClass *a)
Definition: test10.cc:104
tuple b
Definition: test.py:12
void Process()
Definition: test10.cc:90
XBase()
Definition: XBase.cc:43
void d_VMethodB(const BClass *b)
Definition: test10.cc:123
BOOST_PYTHON_MODULE(TestEm0)
Definition: pyTestEm0.cc:88
BClass()
Definition: test10.cc:51
const XML_Char int const XML_Char int const XML_Char * base
Definition: expat.h:331
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