LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
test12.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 // test12.cc
28 //
29 // test for indexing a STL vector
30 //
31 // 2005 Q
32 // ====================================================================
33 #include <boost/python.hpp>
34 #if BOOST_VERSION < 103300
36 #else
37 #include <boost/python/suite/indexing/vector_indexing_suite.hpp>
38 #endif
39 
40 #include <vector>
41 #include <iostream>
42 
43 class AClass {
44 private:
45  int ival;
46 
47 public:
48  AClass() : ival(0) {
49  }
50 
51  AClass(const AClass& right) {
52  ival= right.ival;
53  std::cout << "*** copy constructor is called" << std::endl;
54  }
55 
56  ~AClass() { }
57 
58  void SetIVal(int i) { ival= i; }
59  int GetIVal() { return ival; }
60 
61  void Print() const {
62  std::cout << "*** @" << this << ": i="
63  << ival << std::endl;
64  }
65 
66 };
67 
68 typedef std::vector<AClass*> AVector;
69 
70 
71 void PrintVector(const AVector& vec) {
72  std::cout << "*** size of AVector= " << vec.size() << std::endl;
73  for (int i=0; i< vec.size(); i++) {
74  vec[i]-> Print();
75  }
76 }
77 
78 
79 // Boost.Python...
80 
81 using namespace boost::python;
82 
84 {
85  class_<AClass, AClass*>("AClass", "a class")
86  .add_property("ival", &AClass::GetIVal, &AClass::SetIVal)
87  .def("Print", &AClass::Print)
88  ;
89 
90  class_<AVector> ("AVector", "AClass vector")
92  ;
93 
94  def("PrintVector", PrintVector);
95 }
96 
int ival
Definition: AClass.hh:42
int GetIVal()
Definition: test12.cc:59
constexpr auto const & right(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
Definition: AssnsIter.h:102
~AClass()
Definition: test12.cc:56
int GetIVal() const
Definition: AClass.hh:66
void Print() const
Definition: test12.cc:61
AClass()
Definition: test12.cc:48
std::vector< AClass * > AVector
Definition: test12.cc:68
void PrintVector(const AVector &vec)
Definition: test12.cc:71
AClass(const AClass &right)
Definition: test12.cc:51
BOOST_PYTHON_MODULE(test12)
Definition: test12.cc:83
void SetIVal(int i)
Definition: test12.cc:58
Definition: AClass.hh:40