add C++ operator aliases
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@7924 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
dccd97af1c
commit
db923a855e
2 changed files with 73 additions and 45 deletions
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
%define %pybinoperator(pyname,oper)
|
||||
%rename(pyname) oper;
|
||||
%pythonmaybecall oper;
|
||||
|
|
@ -30,31 +31,6 @@
|
|||
%pybinoperator(__eq__, *::operator==);
|
||||
%pybinoperator(__ne__, *::operator!=);
|
||||
|
||||
%define %pybinoperation(oper)
|
||||
%pythonmaybecall __ ## oper ## __;
|
||||
%pythonmaybecall __r ## oper ## __;
|
||||
%enddef
|
||||
|
||||
%pybinoperation(add);
|
||||
%pybinoperation(pos);
|
||||
%pybinoperation(pos);
|
||||
%pybinoperation(sub);
|
||||
%pybinoperation(neg);
|
||||
%pybinoperation(neg);
|
||||
%pybinoperation(mul);
|
||||
%pybinoperation(div);
|
||||
%pybinoperation(mod);
|
||||
%pybinoperation(lshift);
|
||||
%pybinoperation(rshift);
|
||||
%pybinoperation(and);
|
||||
%pybinoperation(or);
|
||||
%pybinoperation(xor);
|
||||
%pybinoperation(lt);
|
||||
%pybinoperation(le);
|
||||
%pybinoperation(gt);
|
||||
%pybinoperation(ge);
|
||||
%pybinoperation(eq);
|
||||
%pybinoperation(ne);
|
||||
|
||||
|
||||
/* Special cases */
|
||||
|
|
@ -63,19 +39,14 @@
|
|||
|
||||
/* Ignored operators */
|
||||
%ignorewarn("361:operator! ignored") operator!;
|
||||
%ignorewarn("361:operator not ignored") operator not;
|
||||
%ignorewarn("381:operator&& ignored") operator&&;
|
||||
%ignorewarn("381:operator and ignored") operator and;
|
||||
%ignorewarn("382:operator|| ignored") operator||;
|
||||
%ignorewarn("382:operator or ignored") operator or;
|
||||
%ignorewarn("362:operator= ignored") *::operator=;
|
||||
%ignorewarn("383:operator++ ignored") *::operator++;
|
||||
%ignorewarn("384:operator-- ignored") *::operator--;
|
||||
%ignorewarn("386:operator->* ignored") *::operator->*;
|
||||
%ignorewarn("389:operator[] ignored (consider using %extend)") *::operator[];
|
||||
|
||||
|
||||
|
||||
/*
|
||||
Inplace operator declarations.
|
||||
|
||||
|
|
@ -115,21 +86,70 @@
|
|||
|
||||
*/
|
||||
|
||||
%define %swig_inplace_oper(Oper, PyOper)
|
||||
%feature("self:disown") *::Oper;
|
||||
%feature("new") *::Oper;
|
||||
%rename(__##PyOper##__) *::Oper;
|
||||
%define %pyinplaceoper(PyOper, Oper)
|
||||
%feature("self:disown") Oper;
|
||||
%feature("new") Oper;
|
||||
%rename(PyOper) Oper;
|
||||
%enddef
|
||||
|
||||
%swig_inplace_oper(operator +=, iadd);
|
||||
%swig_inplace_oper(operator -=, isub);
|
||||
%swig_inplace_oper(operator *=, imul);
|
||||
%swig_inplace_oper(operator /=, idiv);
|
||||
%swig_inplace_oper(operator %=, imod);
|
||||
%swig_inplace_oper(operator &=, iand);
|
||||
%swig_inplace_oper(operator |=, ior);
|
||||
%swig_inplace_oper(operator ^=, ixor);
|
||||
%swig_inplace_oper(operator <<=, ilshift);
|
||||
%swig_inplace_oper(operator >>=, irshift);
|
||||
%pyinplaceoper(__iadd__ , *::operator +=);
|
||||
%pyinplaceoper(__isub__ , *::operator -=);
|
||||
%pyinplaceoper(__imul__ , *::operator *=);
|
||||
%pyinplaceoper(__idiv__ , *::operator /=);
|
||||
%pyinplaceoper(__imod__ , *::operator %=);
|
||||
%pyinplaceoper(__iand__ , *::operator &=);
|
||||
%pyinplaceoper(__ior__ , *::operator |=);
|
||||
%pyinplaceoper(__ixor__ , *::operator ^=);
|
||||
%pyinplaceoper(__ilshift__, *::operator <<=);
|
||||
%pyinplaceoper(__irshift__, *::operator >>=);
|
||||
|
||||
|
||||
|
||||
/* C++ operator aliases */
|
||||
|
||||
%ignorewarn("381:operator and ignored") operator and; // `and' `&&'
|
||||
%ignorewarn("361:operator not ignored") operator not; // `not' `!'
|
||||
%ignorewarn("382:operator or ignored") operator or; // `or' `||'
|
||||
%pyinplaceoper(__iand__, *::operator and_eq); // `and_eq' `&='
|
||||
%pybinoperator(__and__, *::operator bitand) // `bitand' `&'
|
||||
%pybinoperator(__or__, *::operator bitor); // `bitor' `|'
|
||||
%rename(__invert__) *::operator compl; // `compl' `~'
|
||||
%pybinoperator(__ne__, *::operator not_eq); // `not_eq' `!='
|
||||
%pyinplaceoper(__ior__, *::operator or_eq); // `or_eq' `|='
|
||||
%pybinoperator(__xor__, *::operator xor); // `xor' `^'
|
||||
%pyinplaceoper(__ixor__, *::operator xor_eq); // `xor_eq' `^='
|
||||
|
||||
|
||||
/* Finally, in python we need to mark the binary operations to fail as
|
||||
'maybecall' methods */
|
||||
|
||||
%define %pybinopermaybecall(oper)
|
||||
%pythonmaybecall __ ## oper ## __;
|
||||
%pythonmaybecall __r ## oper ## __;
|
||||
%enddef
|
||||
|
||||
%pybinopermaybecall(add);
|
||||
%pybinopermaybecall(pos);
|
||||
%pybinopermaybecall(pos);
|
||||
%pybinopermaybecall(sub);
|
||||
%pybinopermaybecall(neg);
|
||||
%pybinopermaybecall(neg);
|
||||
%pybinopermaybecall(mul);
|
||||
%pybinopermaybecall(div);
|
||||
%pybinopermaybecall(mod);
|
||||
%pybinopermaybecall(lshift);
|
||||
%pybinopermaybecall(rshift);
|
||||
%pybinopermaybecall(and);
|
||||
%pybinopermaybecall(or);
|
||||
%pybinopermaybecall(xor);
|
||||
%pybinopermaybecall(lt);
|
||||
%pybinopermaybecall(le);
|
||||
%pybinopermaybecall(gt);
|
||||
%pybinopermaybecall(ge);
|
||||
%pybinopermaybecall(eq);
|
||||
%pybinopermaybecall(ne);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue