LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
test05.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 // test05.cc
28 //
29 // test of function overloading
30 // - constructor
31 // - default arguments
32 // - auto-overloading
33 // - docstrings
34 //
35 // 2005 Q
36 // ====================================================================
37 #include <boost/python.hpp>
38 
39 #include "XFunc.hh"
40 #include "AClass.hh"
41 
42 using namespace boost::python;
43 
45 //int(*func2_1)(int) = func2;
46 //int(*func2_2)(int,int) = func2;
47 
48 int(*func3_1)(int)= func3;
49 int(*func3_2)(double)= func3;
50 
51 BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(f_AMethod, AMethod, 0, 2);
52 BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(f_CMethod, CMethod, 1, 3);
53 
55 double(AClass::*f2_BMethod)(double) = &AClass::BMethod;
56 
57 
59  // this is a temporal solution
60  def("func2", (int(*)(int,int))0, f_func2());
61  //def("func2", func2_1);
62  //def("func2", func2_2);
63 
64  def("func3", func3_2);
65  def("func3", func3_1);
66 
67  class_<AClass>( "AClass", "a class")
68  .def(init<>())
69  .def(init<int, optional<double> >())
70  .add_property("i", &AClass::GetIVal, &AClass::SetIVal)
71  .def("AMethod", (int(AClass::*)(int,double))0,
72  f_AMethod(args("i","d"), "amethod"))
73  .def("BMethod", f1_BMethod)
74  .def("BMethod", f2_BMethod, args("i","d"), "bmethod2")
75  .def("CMethod", &AClass::CMethod,
76  f_CMethod((arg("i"), arg("d1")=1., arg("d2")=2.),
77  "cmethod: return i*d1*d2")
78  )
79  ;
80 }
81 
double CMethod(int i, double d1=1., double d2=2.)
Definition: AClass.cc:102
int GetIVal() const
Definition: AClass.hh:66
int func3(int i)
Definition: XFunc.cc:60
BOOST_PYTHON_FUNCTION_OVERLOADS(f_func2, func2, 1, 2)
int func2(int i)
Definition: XFunc.cc:50
int(* func3_2)(double)
Definition: test05.cc:49
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(f_AMethod, AMethod, 0, 2)
void SetIVal(int i)
Definition: AClass.hh:65
BOOST_PYTHON_MODULE(test05)
Definition: test05.cc:58
double(AClass::* f2_BMethod)(double)
Definition: test05.cc:55
Definition: AClass.hh:40
int(AClass::* f1_BMethod)()
Definition: test05.cc:54
int(* func3_1)(int)
Definition: test05.cc:48
int BMethod()
Definition: AClass.cc:87