From 5ec52662843559ce8896f9a6d1d61d5e3e4217e4 Mon Sep 17 00:00:00 2001 From: Ivan Popivanov Date: Sat, 17 Dec 2016 16:26:10 -0800 Subject: [PATCH] Renamed all operators beginning with underscore. --- Examples/r/class/example.cxx | 27 +++++++++++++++ Examples/r/class/example.h | 7 ++++ Examples/r/class/runme.R | 8 +++++ Lib/r/ropers.swg | 64 +++++++++++++++--------------------- 4 files changed, 68 insertions(+), 38 deletions(-) diff --git a/Examples/r/class/example.cxx b/Examples/r/class/example.cxx index 046304519..3a3d1cfbb 100644 --- a/Examples/r/class/example.cxx +++ b/Examples/r/class/example.cxx @@ -19,10 +19,37 @@ double Circle::perimeter() { return 2*M_PI*radius; } +Circle::Circle(double xx, double yy, double rr) + : radius(rr) +{ + x = xx; + y = yy; +} + +bool Circle::operator==(const Circle & other) +{ + return x == other.x && y == other.y && radius == other.radius; +} + +bool Circle::operator!=(const Circle & other) +{ + return !operator==(other); +} + double Square::area() { return width*width; } +bool Square::operator==(const Square & other) +{ + return x == other.x && y == other.y && width == other.width; +} + +bool Square::operator!=(const Square & other) +{ + return !operator==(other); +} + double Square::perimeter() { return 4*width; } diff --git a/Examples/r/class/example.h b/Examples/r/class/example.h index 0dff185b2..b51e646fc 100644 --- a/Examples/r/class/example.h +++ b/Examples/r/class/example.h @@ -20,8 +20,12 @@ private: double radius; public: Circle(double r) : radius(r) { } + Circle(double xx, double yy, double rr); virtual double area(); virtual double perimeter(); + + bool operator==(const Circle & other); + bool operator!=(const Circle & other); }; class Square : public Shape { @@ -31,4 +35,7 @@ public: Square(double w) : width(w) { } virtual double area(); virtual double perimeter(); + + bool operator==(const Square & other); + bool operator!=(const Square & other); }; diff --git a/Examples/r/class/runme.R b/Examples/r/class/runme.R index 4a2028553..c8331b677 100644 --- a/Examples/r/class/runme.R +++ b/Examples/r/class/runme.R @@ -31,6 +31,14 @@ print("Here is their current position:") sprintf(" Circle = (%f, %f)", circle$x,circle$y) sprintf(" Square = (%f, %f)", square$x,square$y) +c2 <- Circle(1, 5, 15) +c1 <- circle +c1$move(1, 5) +print(Circle_MemberEq(c1, c2)) +print(Circle_MemberNotEq(c1, c2)) + +print(c1$MemberEq(c2)) + # ----- Call some methods ----- print ("Here are some properties of the shapes:") diff --git a/Lib/r/ropers.swg b/Lib/r/ropers.swg index c02f7b2f3..9dec7bb17 100644 --- a/Lib/r/ropers.swg +++ b/Lib/r/ropers.swg @@ -1,42 +1,31 @@ #ifdef __cplusplus -// These are auto-supported by the Perl-module -%rename(__plusplus__) *::operator++; -%rename(__minmin__) *::operator--; -%rename(__add__) *::operator+; -%rename(__sub__) *::operator-; -%rename(__neg__) *::operator-(); -%rename(__neg__) *::operator-() const; -%rename(__mul__) *::operator*; -%rename(__div__) *::operator/; -%rename(__eq__) *::operator==; -%rename(__ne__) *::operator!=; -%rename(__mod__) *::operator%; -%rename(__gt__) *::operator>; -%rename(__lt__) *::operator<; -%rename(__not__) *::operator!; - -// These are renamed, but no 'use overload...' is added -%rename(__lshift__) *::operator<<; -%rename(__rshift__) *::operator>>; -%rename(__and__) *::operator&; -%rename(__or__) *::operator|; -%rename(__xor__) *::operator^; -%rename(__invert__) *::operator~; -%rename(__le__) *::operator<=; -%rename(__ge__) *::operator>=; -%rename(__call__) *::operator(); -%rename(__getitem__) *::operator[]; - -%rename(__seteq__) *::operator=; - - -%rename(__land__) operator&&; -%rename(__lor__) operator||; -%rename(__plusplus__) *::operator++; -%rename(__minusminus__) *::operator--; -%rename(__arrowstar__) *::operator->*; -%rename(__index__) *::operator[]; +%rename(MemberPlusPlus) *::operator++; +%rename(MemberMinMin) *::operator--; +%rename(MemberAdd) *::operator+; +%rename(MemberSub) *::operator-; +%rename(MemberNeg) *::operator-(); +%rename(MemberNegConst) *::operator-() const; +%rename(MemberMul) *::operator*; +%rename(MemberDiv) *::operator/; +%rename(MemberEq) *::operator==; +%rename(MemberNotEq) *::operator!=; +%rename(MemberMod) *::operator%; +%rename(MemberGreater) *::operator>; +%rename(MemberLess) *::operator<; +%rename(MemberNot) *::operator!; +%rename(MemberLShift) *::operator<<; +%rename(MemberRShift) *::operator>>; +%rename(MemberAnd) *::operator&; +%rename(MemberOr) *::operator|; +%rename(MemberXor) *::operator^; +%rename(MemberInvert) *::operator~; +%rename(MemberLessOrEq) *::operator<=; +%rename(MemberGreaterOrEq) *::operator>=; +%rename(MemberCall) *::operator(); +%rename(MemberGetItem) *::operator[]; +%rename(MemberAssign) *::operator=; +%rename(MemberArrowStar) *::operator->*; %rename(Equal) operator =; %rename(PlusEqual) operator +=; @@ -66,5 +55,4 @@ %rename(MinusMinusPrefix) operator--(); %rename(MinusMinusPostfix) operator--(int); - #endif