LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
test09.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 // test09.cc
28 //
29 // test for operators
30 //
31 // 2005 Q
32 // ====================================================================
33 #include <iostream>
34 
35 class AClass {
36 private:
37  int ival;
38 
39 public:
40  AClass() :ival(999) { }
41  AClass(int i) :ival(i) { }
42  ~AClass() { }
43 
44  void SetIVal(int i) { ival= i; }
45  int GetIVal() const { return ival; }
46 
47  AClass operator+(const AClass& aclass) {
48  AClass atemp;
49  atemp.ival= ival + aclass.ival;
50  return atemp;
51  }
52 
53  AClass& operator+=(const AClass& aclass) {
54  ival+= aclass.ival;
55  return *this;
56  }
57 
58  bool operator==(const AClass& aclass) const {
59  if(ival == aclass.ival) return true;
60  return false;
61  }
62 };
63 
64 std::ostream& operator<<(std::ostream& ostr, const AClass& aclass)
65 {
66  return ostr << aclass.GetIVal();
67 }
68 
69 
70 // Boost.Python...
71 #include <boost/python.hpp>
72 
73 using namespace boost::python;
74 
76 {
77  class_<AClass>( "AClass", "a class")
78  .def(init<>())
79  .def(init<int>())
80  .add_property("ival", &AClass::GetIVal, &AClass::SetIVal)
81  .def(self + self)
82  .def(self += self)
83  .def(self == self)
84  .def(self_ns::str(self))
85  ;
86 }
int ival
Definition: AClass.hh:42
~AClass()
Definition: test09.cc:42
int GetIVal() const
Definition: test09.cc:45
AClass()
Definition: test09.cc:40
std::ostream & operator<<(std::ostream &ostr, const AClass &aclass)
Definition: test09.cc:64
AClass & operator+=(const AClass &aclass)
Definition: test09.cc:53
void SetIVal(int i)
Definition: test09.cc:44
BOOST_PYTHON_MODULE(test09)
Definition: test09.cc:75
Definition: AClass.hh:40
AClass(int i)
Definition: test09.cc:41
AClass operator+(const AClass &aclass)
Definition: test09.cc:47
bool operator==(const AClass &aclass) const
Definition: test09.cc:58