/
usr
/
share
/
swig
/
3.0.12
/
python
/
/usr/share/swig/3.0.12/python
mkdir
upload
Name
Size
Mode
Actions
argcargv.i
2642
0644
edit
dl
rm
attribute.i
34
0644
edit
dl
rm
boost_shared_ptr.i
16295
0644
edit
dl
rm
builtin.swg
25016
0644
edit
dl
rm
carrays.i
338
0644
edit
dl
rm
ccomplex.i
763
0644
edit
dl
rm
cdata.i
30
0644
edit
dl
rm
cmalloc.i
32
0644
edit
dl
rm
cni.i
42
0644
edit
dl
rm
complex.i
80
0644
edit
dl
rm
cpointer.i
33
0644
edit
dl
rm
cstring.i
32
0644
edit
dl
rm
cwstring.i
60
0644
edit
dl
rm
defarg.swg
1154
0644
edit
dl
rm
director.swg
10638
0644
edit
dl
rm
embed.i
2530
0644
edit
dl
rm
exception.i
139
0644
edit
dl
rm
factory.i
32
0644
edit
dl
rm
file.i
1035
0644
edit
dl
rm
implicit.i
287
0644
edit
dl
rm
jstring.i
1759
0644
edit
dl
rm
pyabc.i
418
0644
edit
dl
rm
pyapi.swg
1339
0644
edit
dl
rm
pybackward.swg
1162
0644
edit
dl
rm
pybuffer.i
2782
0644
edit
dl
rm
pyclasses.swg
3474
0644
edit
dl
rm
pycomplex.swg
2243
0644
edit
dl
rm
pycontainer.swg
29789
0644
edit
dl
rm
pydocs.swg
1104
0644
edit
dl
rm
pyerrors.swg
1689
0644
edit
dl
rm
pyfragments.swg
551
0644
edit
dl
rm
pyhead.swg
5741
0644
edit
dl
rm
pyinit.swg
13525
0644
edit
dl
rm
pyiterators.swg
10650
0644
edit
dl
rm
pymacros.swg
38
0644
edit
dl
rm
pyname_compat.i
4124
0644
edit
dl
rm
pyopers.swg
10223
0644
edit
dl
rm
pyprimtypes.swg
8070
0644
edit
dl
rm
pyrun.swg
53129
0644
edit
dl
rm
pyruntime.swg
795
0644
edit
dl
rm
pystdcommon.swg
7102
0644
edit
dl
rm
pystrings.swg
4422
0644
edit
dl
rm
python.swg
2035
0644
edit
dl
rm
pythonkw.swg
2355
0644
edit
dl
rm
pythreads.swg
2864
0644
edit
dl
rm
pytuplehlp.swg
308
0644
edit
dl
rm
pytypemaps.swg
3208
0644
edit
dl
rm
pyuserdir.swg
6326
0644
edit
dl
rm
pywstrings.swg
2097
0644
edit
dl
rm
std_alloc.i
27
0644
edit
dl
rm
std_array.i
3693
0644
edit
dl
rm
std_auto_ptr.i
585
0644
edit
dl
rm
std_basic_string.i
2817
0644
edit
dl
rm
std_carray.i
1583
0644
edit
dl
rm
std_char_traits.i
33
0644
edit
dl
rm
std_common.i
2319
0644
edit
dl
rm
std_complex.i
469
0644
edit
dl
rm
std_container.i
58
0644
edit
dl
rm
std_deque.i
678
0644
edit
dl
rm
std_except.i
35
0644
edit
dl
rm
std_ios.i
66
0644
edit
dl
rm
std_iostream.i
107
0644
edit
dl
rm
std_list.i
668
0644
edit
dl
rm
std_map.i
9975
0644
edit
dl
rm
std_multimap.i
2578
0644
edit
dl
rm
std_multiset.i
1085
0644
edit
dl
rm
std_pair.i
6167
0644
edit
dl
rm
std_set.i
1490
0644
edit
dl
rm
std_shared_ptr.i
68
0644
edit
dl
rm
std_sstream.i
29
0644
edit
dl
rm
std_streambuf.i
31
0644
edit
dl
rm
std_string.i
35
0644
edit
dl
rm
std_unordered_map.i
8653
0644
edit
dl
rm
std_unordered_multimap.i
3115
0644
edit
dl
rm
std_unordered_multiset.i
1436
0644
edit
dl
rm
std_unordered_set.i
1719
0644
edit
dl
rm
std_vector.i
886
0644
edit
dl
rm
std_vectora.i
829
0644
edit
dl
rm
std_wios.i
26
0644
edit
dl
rm
std_wiostream.i
166
0644
edit
dl
rm
std_wsstream.i
30
0644
edit
dl
rm
std_wstreambuf.i
32
0644
edit
dl
rm
std_wstring.i
63
0644
edit
dl
rm
stl.i
182
0644
edit
dl
rm
typemaps.i
4453
0644
edit
dl
rm
wchar.i
186
0644
edit
dl
rm
Edit:
/usr/share/swig/3.0.12/python/pyopers.swg
(10223B)
/* ------------------------------------------------------------ * Overloaded operator support The directives in this file apply whether or not you use the -builtin option to SWIG, but operator overloads are particularly attractive when using -builtin, because they are much faster than named methods. If you're using the -builtin option to SWIG, and you want to define python operator overloads beyond the defaults defined in this file, here's what you need to know: There are two ways to define a python slot function: dispatch to a statically defined function; or dispatch to a method defined on the operand. To dispatch to a statically defined function, use %feature("python:<slot>"), where <slot> is the name of a field in a PyTypeObject, PyNumberMethods, PyMappingMethods, PySequenceMethods, or PyBufferProcs. For example: %feature("python:tp_hash") MyClass "myHashFunc"; class MyClass { public: ... }; %{ // Note: Py_hash_t was introduced in Python 3.2 static Py_hash_t myHashFunc(PyObject *pyobj) { MyClass *cobj; // Convert pyobj to cobj return (cobj->field1 * (cobj->field2 << 7)); } %} NOTE: It is the responsibility of the programmer (that's you) to ensure that a statically defined slot function has the correct signature. If, instead, you want to dispatch to an instance method, you can use %feature("python:slot"). For example: %feature("python:slot", "tp_hash", functype="hashfunc") MyClass::myHashFunc; class MyClass { public: Py_hash_t myHashFunc () const; ... }; NOTE: Some python slots use a method signature which does not match the signature of SWIG-wrapped methods. For those slots, SWIG will automatically generate a "closure" function to re-marshall the arguments before dispatching to the wrapped method. Setting the "functype" attribute of the feature enables SWIG to generate a correct closure function. -------------------------------------------------------------- The tp_richcompare slot is a special case: SWIG automatically generates a rich compare function for all wrapped types. If a type defines C++ operator overloads for comparison (operator==, operator<, etc.), they will be called from the generated rich compare function. If you want to explicitly choose a method to handle a certain comparison operation, you may use a different feature, %feature("python:compare") like this: %feature("python:compare", "Py_LT") MyClass::lessThan; class MyClass { public: bool lessThan(const MyClass& other) const; ... }; ... where "Py_LT" is one of the rich comparison opcodes defined in the python header file object.h. If there's no method defined to handle a particular comparison operation, the default behavior is to compare pointer values of the wrapped C++ objects. -------------------------------------------------------------- For more information about python slots, including their names and signatures, you may refer to the python documentation : http://docs.python.org/c-api/typeobj.html * ------------------------------------------------------------ */ #ifdef __cplusplus #if defined(SWIGPYTHON_BUILTIN) #define %pybinoperator(pyname,oper,functp,slt) %rename(pyname) oper; %pythonmaybecall oper; %feature("python:slot", #slt, functype=#functp) oper; %feature("python:slot", #slt, functype=#functp) pyname; #define %pycompare(pyname,oper,comptype) %rename(pyname) oper; %pythonmaybecall oper; %feature("python:compare", #comptype) oper; %feature("python:compare", #comptype) pyname; #else #define %pybinoperator(pyname,oper,functp,slt) %rename(pyname) oper; %pythonmaybecall oper #define %pycompare(pyname,oper,comptype) %pybinoperator(pyname,oper,,comptype) #endif %pybinoperator(__add__, *::operator+, binaryfunc, nb_add); %pybinoperator(__pos__, *::operator+(), unaryfunc, nb_positive); %pybinoperator(__pos__, *::operator+() const, unaryfunc, nb_positive); %pybinoperator(__sub__, *::operator-, binaryfunc, nb_subtract); %pybinoperator(__neg__, *::operator-(), unaryfunc, nb_negative); %pybinoperator(__neg__, *::operator-() const, unaryfunc, nb_negative); %pybinoperator(__mul__, *::operator*, binaryfunc, nb_multiply); %pybinoperator(__mod__, *::operator%, binaryfunc, nb_remainder); %pybinoperator(__lshift__, *::operator<<, binaryfunc, nb_lshift); %pybinoperator(__rshift__, *::operator>>, binaryfunc, nb_rshift); %pybinoperator(__and__, *::operator&, binaryfunc, nb_and); %pybinoperator(__or__, *::operator|, binaryfunc, nb_or); %pybinoperator(__xor__, *::operator^, binaryfunc, 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); /* Special cases */ %rename(__invert__) *::operator~; %feature("python:slot", "nb_invert", functype="unaryfunc") *::operator~; %rename(__call__) *::operator(); %feature("python:slot", "tp_call", functype="ternarycallfunc") *::operator(); #if defined(SWIGPYTHON_BUILTIN) %pybinoperator(__nonzero__, *::operator bool, inquiry, nb_nonzero); %pybinoperator(__truediv__, *::operator/ , binaryfunc, nb_divide); #else %feature("shadow") *::operator bool %{ def __nonzero__(self): return $action(self) __bool__ = __nonzero__ %}; %rename(__nonzero__) *::operator bool; %feature("shadow") *::operator/ %{ def __truediv__(self, *args): return $action(self, *args) __div__ = __truediv__ %}; %rename(__truediv__) *::operator/; %pythonmaybecall *::operator/; #endif /* Ignored operators */ %ignoreoperator(LNOT) operator!; %ignoreoperator(LAND) operator&&; %ignoreoperator(LOR) operator||; %ignoreoperator(EQ) *::operator=; %ignoreoperator(PLUSPLUS) *::operator++; %ignoreoperator(MINUSMINUS) *::operator--; %ignoreoperator(ARROWSTAR) *::operator->*; %ignoreoperator(INDEX) *::operator[]; /* Inplace operator declarations. They translate the inplace C++ operators (+=, -=, ...) into the corresponding python equivalents(__iadd__,__isub__), etc, disabling the ownership of the input 'this' pointer, and assigning it to the returning object: %feature("del") *::Operator; // disables ownership by generating SWIG_POINTER_DISOWN %feature("new") *::Operator; // claims ownership by generating SWIG_POINTER_OWN This makes the most common case safe, ie: A& A::operator+=(int i) { ...; return *this; } ^^^^ ^^^^^^ will work fine, even when the resulting python object shares the 'this' pointer with the input one. The input object is usually deleted after the operation, including the shared 'this' pointer, producing 'strange' seg faults, as reported by Lucriz (lucriz@sitilandia.it). If you have an interface that already takes care of that, ie, you already are using inplace operators and you are not getting seg. faults, with the new scheme you could end with 'free' elements that never get deleted (maybe, not sure, it depends). But if that is the case, you could recover the old behaviour using %feature("del","0") A::operator+=; %feature("new","0") A::operator+=; which recovers the old behaviour for the class 'A', or if you are 100% sure your entire system works fine in the old way, use: %feature("del","") *::operator+=; %feature("new","") *::operator+=; The default behaviour assumes that the 'this' pointer's memory is already owned by the SWIG object; it relinquishes ownership then takes it back. This may not be the case though as the SWIG object might be owned by memory managed elsewhere, eg after calling a function that returns a C++ reference. In such case you will need to use the features above to recover the old behaviour too. */ #if defined(SWIGPYTHON_BUILTIN) #define %pyinplaceoper(SwigPyOper, Oper, functp, slt) %delobject Oper; %newobject Oper; %feature("python:slot", #slt, functype=#functp) Oper; %rename(SwigPyOper) Oper #else #define %pyinplaceoper(SwigPyOper, Oper, functp, slt) %delobject Oper; %newobject Oper; %rename(SwigPyOper) Oper #endif %pyinplaceoper(__iadd__ , *::operator +=, binaryfunc, nb_inplace_add); %pyinplaceoper(__isub__ , *::operator -=, binaryfunc, nb_inplace_subtract); %pyinplaceoper(__imul__ , *::operator *=, binaryfunc, nb_inplace_multiply); %pyinplaceoper(__imod__ , *::operator %=, binaryfunc, nb_inplace_remainder); %pyinplaceoper(__iand__ , *::operator &=, binaryfunc, nb_inplace_and); %pyinplaceoper(__ior__ , *::operator |=, binaryfunc, nb_inplace_or); %pyinplaceoper(__ixor__ , *::operator ^=, binaryfunc, nb_inplace_xor); %pyinplaceoper(__ilshift__, *::operator <<=, binaryfunc, nb_inplace_lshift); %pyinplaceoper(__irshift__, *::operator >>=, binaryfunc, nb_inplace_rshift); /* Special cases */ #if defined(SWIGPYTHON_BUILTIN) %pyinplaceoper(__itruediv__ , *::operator /=, binaryfunc, nb_inplace_divide); #else %delobject *::operator /=; %newobject *::operator /=; %feature("shadow") *::operator /= %{ def __itruediv__(self, *args): return $action(self, *args) __idiv__ = __itruediv__ %}; %rename(__itruediv__) *::operator /=; #endif /* Finally, in python we need to mark the binary operations to fail as 'maybecall' methods */ #define %pybinopermaybecall(oper) %pythonmaybecall __ ## oper ## __; %pythonmaybecall __r ## oper ## __ %pybinopermaybecall(add); %pybinopermaybecall(pos); %pybinopermaybecall(pos); %pybinopermaybecall(sub); %pybinopermaybecall(neg); %pybinopermaybecall(neg); %pybinopermaybecall(mul); %pybinopermaybecall(div); %pybinopermaybecall(truediv); %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
Save
cmd:
run