Added support for operator overrides (PyNumberMethods) and
member variable access. test suite now croaks on inplaceadd. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/szager-python-builtin@12345 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
399ae62561
commit
b1682d4d80
4 changed files with 1933 additions and 1755 deletions
|
|
@ -5,41 +5,53 @@
|
|||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#define %pybinoperator(pyname,oper) %rename(pyname) oper; %pythonmaybecall oper
|
||||
|
||||
%pybinoperator(__add__, *::operator+);
|
||||
%pybinoperator(__pos__, *::operator+());
|
||||
%pybinoperator(__pos__, *::operator+() const);
|
||||
%pybinoperator(__sub__, *::operator-);
|
||||
%pybinoperator(__neg__, *::operator-());
|
||||
%pybinoperator(__neg__, *::operator-() const);
|
||||
%pybinoperator(__mul__, *::operator*);
|
||||
%pybinoperator(__div__, *::operator/);
|
||||
%pybinoperator(__mod__, *::operator%);
|
||||
%pybinoperator(__lshift__, *::operator<<);
|
||||
%pybinoperator(__rshift__, *::operator>>);
|
||||
%pybinoperator(__and__, *::operator&);
|
||||
%pybinoperator(__or__, *::operator|);
|
||||
%pybinoperator(__xor__, *::operator^);
|
||||
%pybinoperator(__lt__, *::operator<);
|
||||
%pybinoperator(__le__, *::operator<=);
|
||||
%pybinoperator(__gt__, *::operator>);
|
||||
%pybinoperator(__ge__, *::operator>=);
|
||||
%pybinoperator(__eq__, *::operator==);
|
||||
%pybinoperator(__ne__, *::operator!=);
|
||||
#if defined(SWIGPYTHON_BUILTIN)
|
||||
#define %pybinoperator(pyname,oper,functp,slot) %rename(pyname) oper; %pythonmaybecall oper; %feature("pyslot", #slot, functype=#functp) oper;
|
||||
#define %pycompare(pyname,oper,comptype) %rename(pyname) oper; %pythonmaybecall oper; %feature("pycompare", #comptype) oper;
|
||||
#else
|
||||
#define %pybinoperator(pyname,oper,functp,slot) %rename(pyname) oper; %pythonmaybecall oper
|
||||
#define %pycompare(pyname,oper,comptype) %pybinoperator(pyname,oper,,comptype)
|
||||
#endif
|
||||
|
||||
%pybinoperator(__add__, *::operator+, binary_func, nb_add);
|
||||
%pybinoperator(__pos__, *::operator+(), unary_func, nb_positive);
|
||||
%pybinoperator(__pos__, *::operator+() const, unary_func, nb_positive);
|
||||
%pybinoperator(__sub__, *::operator-, binary_func, nb_subtract);
|
||||
%pybinoperator(__neg__, *::operator-(), unary_func, nb_negative);
|
||||
%pybinoperator(__neg__, *::operator-() const, unary_func, nb_negative);
|
||||
%pybinoperator(__mul__, *::operator*, binary_func, nb_multiply);
|
||||
%pybinoperator(__div__, *::operator/, binary_func, nb_div);
|
||||
%pybinoperator(__mod__, *::operator%, binary_func, nb_remainder);
|
||||
%pybinoperator(__lshift__, *::operator<<, binary_func, nb_lshift);
|
||||
%pybinoperator(__rshift__, *::operator>>, binary_func, nb_rshift);
|
||||
%pybinoperator(__and__, *::operator&, binary_func, nb_and);
|
||||
%pybinoperator(__or__, *::operator|, binary_func, nb_or);
|
||||
%pybinoperator(__xor__, *::operator^, binary_func, nb_xor);
|
||||
%pycompare(__lt__, *::operator<, Py_LT);
|
||||
%pycompare(__le__, *::operator<=, Py_LE);
|
||||
%pycompare(__gt__, *::operator>, Py_GT);
|
||||
%pycompare(__ge__, *::operator>=, Py_GE);
|
||||
%pycompare(__eq__, *::operator==, Py_EQ);
|
||||
%pycompare(__ne__, *::operator!=, Py_NE);
|
||||
|
||||
%feature("pyslot", "nb_truediv", functype="binary_func") *::operator/;
|
||||
|
||||
/* Special cases */
|
||||
%rename(__invert__) *::operator~;
|
||||
%feature("pyslot", "nb_invert", functype="unary_func") *::operator~;
|
||||
%rename(__call__) *::operator();
|
||||
%feature("pyslot", "tp_call", functype="ternary_func") *::operator();
|
||||
|
||||
#if defined(SWIGPYTHON_BUILTIN)
|
||||
%pybinoperator(__nonzero__, *::operator bool, unary_func, nb_nonzero);
|
||||
#else
|
||||
%feature("shadow") *::operator bool %{
|
||||
def __nonzero__(self):
|
||||
return $action(self)
|
||||
__bool__ = __nonzero__
|
||||
%};
|
||||
%rename(__nonzero__) *::operator bool;
|
||||
#endif
|
||||
|
||||
/* Ignored operators */
|
||||
%ignoreoperator(LNOT) operator!;
|
||||
|
|
@ -90,18 +102,22 @@ __bool__ = __nonzero__
|
|||
|
||||
*/
|
||||
|
||||
#define %pyinplaceoper(SwigPyOper, Oper) %delobject Oper; %newobject Oper; %rename(SwigPyOper) Oper
|
||||
#if defined(SWIGPYTHON_BUILTIN)
|
||||
#define %pyinplaceoper(SwigPyOper, Oper, functp, slot) %rename(SwigPyOper) Oper; %feature("pyslot", #slot, functype=#functp) Oper;
|
||||
#else
|
||||
#define %pyinplaceoper(SwigPyOper, Oper, functp, slot) %delobject Oper; %newobject Oper; %rename(SwigPyOper) Oper
|
||||
#endif
|
||||
|
||||
%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 >>=);
|
||||
%pyinplaceoper(__iadd__ , *::operator +=, binary_func, nb_inplace_add);
|
||||
%pyinplaceoper(__isub__ , *::operator -=, binary_func, nb_inplace_subtract);
|
||||
%pyinplaceoper(__imul__ , *::operator *=, binary_func, nb_inplace_multiply);
|
||||
%pyinplaceoper(__idiv__ , *::operator /=, binary_func, nb_inplace_divide);
|
||||
%pyinplaceoper(__imod__ , *::operator %=, binary_func, nb_inplace_remainder);
|
||||
%pyinplaceoper(__iand__ , *::operator &=, binary_func, nb_inplace_and);
|
||||
%pyinplaceoper(__ior__ , *::operator |=, binary_func, nb_inplace_or);
|
||||
%pyinplaceoper(__ixor__ , *::operator ^=, binary_func, nb_inplace_xor);
|
||||
%pyinplaceoper(__ilshift__, *::operator <<=, binary_func, nb_inplace_lshift);
|
||||
%pyinplaceoper(__irshift__, *::operator >>=, binary_func, nb_inplace_rshift);
|
||||
|
||||
|
||||
/* Finally, in python we need to mark the binary operations to fail as
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue