From 75f9cf4e432644fbffdd0c295e5f6a0fb47d532d Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sat, 31 Dec 2005 00:13:36 +0000 Subject: [PATCH] add increment/decrement operators git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@8141 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- SWIG/Examples/test-suite/operator_overload.i | 27 +++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/SWIG/Examples/test-suite/operator_overload.i b/SWIG/Examples/test-suite/operator_overload.i index a6de369cd..27a3fe67b 100644 --- a/SWIG/Examples/test-suite/operator_overload.i +++ b/SWIG/Examples/test-suite/operator_overload.i @@ -34,6 +34,25 @@ see bottom for a set of possible tests %rename(GreaterThanEqual) operator >=; %rename(And) operator and; %rename(Or) operator or; +%rename(PlusPlusPrefix) operator++(); +%rename(PlusPlusPostfix) operator++(int); +%rename(MinusMinusPrefix) operator--(); +%rename(MinusMinusPostfix) operator--(int); +#endif + +#ifdef SWIGCSHARP +%csmethodmodifiers operator++() "protected"; +%csmethodmodifiers operator++(int) "private"; +%csmethodmodifiers operator--() "private"; +%csmethodmodifiers operator--(int) "protected"; +%typemap(cscode) Op %{ + public static Op operator++(Op op) { + return op.PlusPlusPostfix(0); + } + public static Op operator--(Op op) { + return op.MinusMinusPrefix(); + } +%} #endif %inline %{ @@ -86,7 +105,13 @@ public: int operator()(int a=0){return i+a;} int operator()(int a,int b){return i+a+b;} - // TODO: ++,--,<<,<<= + // increment/decrement operators + Op& operator++(){++i; return *this;} // prefix ++ + Op& operator++(int){i++; return *this;} // postfix ++ + Op& operator--(){--i; return *this;} // prefix -- + Op& operator--(int){i--; return *this;} // postfix -- + + // TODO: <<,<<= }; // just to complicate matters