Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
test12.cc
이 파일의 문서화 페이지로 가기
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: test12.cc 86624 2014-11-14 08:59:40Z kmura $
27 // ====================================================================
28 // test12.cc
29 //
30 // test for indexing a STL vector
31 //
32 // 2005 Q
33 // ====================================================================
34 #include <boost/python.hpp>
35 #if BOOST_VERSION < 103300
36 #include "vector_indexing_suite.hpp"
37 #else
38 #include <boost/python/suite/indexing/vector_indexing_suite.hpp>
39 #endif
40 
41 #include <vector>
42 #include <iostream>
43 
44 class AClass {
45 private:
46  int ival;
47 
48 public:
49  AClass() : ival(0) {
50  }
51 
52  AClass(const AClass& right) {
53  ival= right.ival;
54  std::cout << "*** copy constructor is called" << std::endl;
55  }
56 
57  ~AClass() { }
58 
59  void SetIVal(int i) { ival= i; }
60  int GetIVal() { return ival; }
61 
62  void Print() const {
63  std::cout << "*** @" << this << ": i="
64  << ival << std::endl;
65  }
66 
67 };
68 
69 typedef std::vector<AClass*> AVector;
70 
71 
72 void PrintVector(const AVector& vec) {
73  std::cout << "*** size of AVector= " << vec.size() << std::endl;
74  for (int i=0; i< vec.size(); i++) {
75  vec[i]-> Print();
76  }
77 }
78 
79 
80 // Boost.Python...
81 
82 using namespace boost::python;
83 
85 {
86  class_<AClass, AClass*>("AClass", "a class")
87  .add_property("ival", &AClass::GetIVal, &AClass::SetIVal)
88  .def("Print", &AClass::Print)
89  ;
90 
91  class_<AVector> ("AVector", "AClass vector")
92  .def(vector_indexing_suite<AVector>())
93  ;
94 
95  def("PrintVector", PrintVector);
96 }
97 
int GetIVal()
Definition: test12.cc:60
~AClass()
Definition: test12.cc:57
int GetIVal() const
void Print() const
Definition: test12.cc:62
AClass()
Definition: test12.cc:49
std::vector< AClass * > AVector
Definition: test12.cc:69
void PrintVector(const AVector &vec)
Definition: test12.cc:72
AClass(const AClass &right)
Definition: test12.cc:52
void SetIVal(int i)
Definition: test12.cc:59
void Print(G4Element &ele)
Definition: pyG4Element.cc:56
BOOST_PYTHON_MODULE(testem0)
Definition: pytestem0.cc:88