LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
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 // ====================================================================
27 // test10.cc
28 //
29 // test for call by-reference
30 //
31 // 2005 Q
32 // ====================================================================
33 #include <iostream>
34 
35 class AClass {
36 public:
37  AClass() {
38  std::cout << "*** AClass is created..." << this
39  << std::endl;
40  }
41 
42  ~AClass() {
43  std::cout << "*** AClass is deleted..." << this
44  << std::endl;
45  }
46 };
47 
48 class BClass {
49 public:
50  BClass() {
51  std::cout << "*** BClass is created..." << this
52  << std::endl;
53  }
54  ~BClass() {
55  std::cout << "*** BClass is deleted..." << this
56  << std::endl;
57  }
58 };
59 
60 class XBase {
61 public:
62  XBase() {}
63  ~XBase() {}
64 
65  virtual void VMethodA(const AClass* a) {
66  std::cout << "*** XBase::VMethod...A() is called." << std::endl;
67  }
68 
69  virtual void VMethodB(const BClass* b) {
70  std::cout << "*** XBase::VMethod...B() is called." << std::endl;
71  }
72 };
73 
74 
75 class ZClass {
76 private:
80 
81 public:
82  ZClass() : xbase(0) { }
83  ~ZClass() { }
84 
85  void SetXBase(XBase* base) {
86  xbase= base;
87  }
88 
89  void Process() {
90  xbase-> VMethodA(&a);
91  xbase-> VMethodB(&b);
92  }
93 };
94 
95 
96 // Boost.Python...
97 #include <boost/python.hpp>
98 
99 using namespace boost::python;
100 
101 // call backs
102 struct CB_XBase : XBase, wrapper<XBase> {
103  void VMethodA(const AClass* a) {
104  if(const override& f= get_override("VMethodA"))
105  f(a);
106  else
107  XBase::VMethodA(a);
108  }
109 
110  void d_VMethodA(const AClass* a) {
111  XBase::VMethodA(a);
112  }
113 
114  //
115  void VMethodB(const BClass* b) {
116  if(const override& f= get_override("VMethodB"))
117  f(b);
118  else
119  XBase::VMethodB(b);
120  }
121 
122  void d_VMethodB(const BClass* b) {
123  XBase::VMethodB(b);
124  }
125 };
126 
127 
129 {
130  class_<AClass, AClass*>("AClass", "a class")
131  .def(init<>())
132  ;
133 
134  class_<BClass>("BClass", "b class")
135  .def(init<>())
136  ;
137 
138  class_<CB_XBase, boost::noncopyable>("XBase", "xbase class")
139  .def(init<>())
140  .def("VMethodA", &XBase::VMethodA, &CB_XBase::d_VMethodA)
141  .def("VMethodB", &XBase::VMethodB, &CB_XBase::d_VMethodB)
142  ;
143 
144  class_<ZClass>("ZClass", "z class")
145  .def(init<>())
146  .def("SetXBase", &ZClass::SetXBase)
147  .def("Process", &ZClass::Process)
148  ;
149 }
150 
Definition: BClass.hh:42
~BClass()
Definition: test10.cc:54
~AClass()
Definition: test10.cc:42
AClass a
Definition: test10.cc:77
void VMethodA(const AClass *a)
Definition: test10.cc:103
virtual void VMethodB(const BClass *b)
Definition: test10.cc:69
AClass()
Definition: test10.cc:37
void VMethodB(const BClass *b)
Definition: test10.cc:115
BOOST_PYTHON_MODULE(test10)
Definition: test10.cc:128
void SetXBase(XBase *base)
Definition: test10.cc:85
virtual void VMethodA(const AClass *a)
Definition: test10.cc:65
TFile f
Definition: plotHisto.C:6
void d_VMethodA(const AClass *a)
Definition: test10.cc:110
XBase * xbase
Definition: test10.cc:79
BClass()
Definition: test10.cc:50
void d_VMethodB(const BClass *b)
Definition: test10.cc:122
Definition: AClass.hh:40
XBase()
Definition: test10.cc:62
Definition: test10.cc:75
Definition: XBase.hh:40
ZClass()
Definition: test10.cc:82
~ZClass()
Definition: test10.cc:83
void Process()
Definition: test10.cc:89
BClass b
Definition: test10.cc:78
~XBase()
Definition: test10.cc:63