Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 // $Id: test05.cc 66892 2013-01-17 10:57:59Z gunter $
27 // ====================================================================
28 // test05.cc
29 //
30 // test of function overloading
31 // - constructor
32 // - default arguments
33 // - auto-overloading
34 // - docstrings
35 //
36 // 2005 Q
37 // ====================================================================
38 #include <boost/python.hpp>
39 
40 #include "XFunc.hh"
41 #include "AClass.hh"
42 
43 using namespace boost::python;
44 
46 //int(*func2_1)(int) = func2;
47 //int(*func2_2)(int,int) = func2;
48 
50 int(*func3_2)(double)= func3;
51 
52 BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(f_AMethod, AMethod, 0, 2);
53 BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(f_CMethod, CMethod, 1, 3);
54 
56 double(AClass::*f2_BMethod)(double) = &AClass::BMethod;
57 
58 
60  // this is a temporal solution
61  def("func2", (int(*)(int,int))0, f_func2());
62  //def("func2", func2_1);
63  //def("func2", func2_2);
64 
65  def("func3", func3_2);
66  def("func3", func3_1);
67 
68  class_<AClass>( "AClass", "a class")
69  .def(init<>())
70  .def(init<int, optional<double> >())
71  .add_property("i", &AClass::GetIVal, &AClass::SetIVal)
72  .def("AMethod", (int(AClass::*)(int,double))0,
73  f_AMethod(args("i","d"), "amethod"))
74  .def("BMethod", f1_BMethod)
75  .def("BMethod", f2_BMethod, args("i","d"), "bmethod2")
76  .def("CMethod", &AClass::CMethod,
77  f_CMethod((arg("i"), arg("d1")=1., arg("d2")=2.),
78  "cmethod: return i*d1*d2")
79  )
80  ;
81 }
82 
void SetIVal(int i)
double CMethod(int i, double d1=1., double d2=2.)
int func2(int i)
Definition: XFunc.cc:51
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)
BOOST_PYTHON_FUNCTION_OVERLOADS(f_func2, func2, 1, 2)
int func3(int i)
Definition: XFunc.cc:61
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(f_AMethod, AMethod, 0, 2)
int GetIVal() const
double(AClass::* f2_BMethod)(double)
Definition: test05.cc:56
BOOST_PYTHON_MODULE(test05)
Definition: test05.cc:59
int(* func3_2)(double)
Definition: test05.cc:50
int(* func3_1)(int)
Definition: test05.cc:49
int(AClass::* f1_BMethod)()
Definition: test05.cc:55