source: trunk/environments/g4py/tests/test10/test10.cc @ 1337

Last change on this file since 1337 was 1337, checked in by garnier, 14 years ago

tag geant4.9.4 beta 1 + modifs locales

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