LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
test13.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 // test13.cc
28 //
29 // test for a list argument/return
30 //
31 // 2005 Q
32 // ====================================================================
33 #include <iostream>
34 
35 int* alloc_int()
36 {
37  int* intlist= new int [10];
38  for (int i=0; i<10; i++) intlist[i]= 0;
39 
40  return intlist;
41 }
42 
43 
44 void operate_list(int vec[10])
45 {
46  for(int i=0; i<10; i++) {
47  std::cout << vec[i] << std::endl;
48  vec[i]++;
49  }
50 }
51 
52 // Boost.Python...
53 #include <boost/python.hpp>
54 
55 using namespace boost::python;
56 
57 
59 {
60  int* aaa= alloc_int();
61  int n= 10;
62  list x;
63  for(int i=0; i<n; i++) {
64  x.append(aaa[i]);
65  }
66  return x;
67 }
68 
69 void f_operate_list(list& alist)
70 {
71  int* intlist= new int [10];
72  for (int i=0; i<10; i++) {
73  intlist[i]= extract<int>(alist[i]);
74  }
75 
76  operate_list(intlist);
77 
78  for (int i=0; i<10; i++) {
79  alist[i]= intlist[i];
80  }
81 
82  delete intlist;
83 }
84 
86 {
87  def("alloc_int", f_alloc_int);
88  def("operate_list", f_operate_list);
89 }
90 
Float_t x
Definition: compare.C:6
void operate_list(int vec[10])
Definition: test13.cc:44
void f_operate_list(list &alist)
Definition: test13.cc:69
BOOST_PYTHON_MODULE(test13)
Definition: test13.cc:85
int * alloc_int()
Definition: test13.cc:35
list f_alloc_int()
Definition: test13.cc:58
Char_t n[5]