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