From fd2fe8dd36e8e7f2977b0893abc6e04f7ef13f7f Mon Sep 17 00:00:00 2001
From: Marcelo Matus
@@ -1502,6 +1502,8 @@ public:
Complex(double r = 0, double i = 0) : rpart(r), ipart(i) { }
Complex(const Complex &c) : rpart(c.rpart), ipart(c.ipart) { }
Complex &operator=(const Complex &c);
+
+ Complex operator+=(const Complex &c) const;
Complex operator+(const Complex &c) const;
Complex operator-(const Complex &c) const;
Complex operator*(const Complex &c) const;
@@ -1524,6 +1526,12 @@ When wrapped, it works like you expect:
10.0
>>> e.im()
12.0
+>>> c += d
+>>> c.re()
+10.0
+>>> c.im()
+12.0
+
@@ -1541,15 +1549,12 @@ friend Complex operator+(double, const Complex &c);
-then SWIG doesn't know what to do with the friend function--in fact,
-it simply ignores it and issues a warning. You can still wrap the operator,
+then SWIG ignores it and issues a warning. You can still wrap the operator,
but you may have to encapsulate it in a special function. For example:
$ swig -python example.i
-$ gcc -c example.c
-$ gcc -c example_wrap.c -I/usr/local/include/python2.0
+$ gcc -c -fPIC example.c
+$ gcc -c -fPIC example_wrap.c -I/usr/local/include/python2.0
$ gcc -shared example.o example_wrap.o -o _example.so
@@ -2376,29 +2381,67 @@ Python.
Typemaps for input and output of most of the basic types from director
classes have been written. These are roughly the reverse of the usual
input and output typemaps used by the wrapper code. The typemap
-operation names are 'directorin', 'directorout', and 'directorargout'. The director code does
-not use any of the other kinds of typemaps yet. It is not clear at this
-point which kinds are appropriate and need to be supported.
+operation names are 'directorin', 'directorout', and 'directorargout'.
+The director code does not use any of the other kinds of typemaps
+yet. It is not clear at this point which kinds are appropriate and
+need to be supported.
+
%rename(Complex_add_dc) operator+(double, const Complex &);
-...
-Complex operator+(double, const Complex &c);
+Director typemaps for STL classes are in place, and hence you should +be able to use std::vector, std::string, etc., as any other raw type.
-Typemaps for STL classes are under construction. So far there is support -for std::string, std::vector, and std::complex, although there's no -guarantee these are fully functional yet. -
+Note: The director typemaps for return types based in const +references, such as -
+
+class Foo {
+…
+ virtual const int& bar();
+…
+};
+
+
+
+will work only for simple call scenarios. Usually the resulting code
+is neither thread or reentrant safe. Hence, the user is adviced to
+avoid returning const reference in director methods. For example,
+the user could modify the method interface to use a lvalue return
+types, when possible, i.e.
+
+
+
+class Foo {
+…
+ virtual int bar();
+…
+};
+
+
+
+If that is not possible, the user should avoid to enable the
+director feature for reentrant, recursive or threaded member
+methods that return const references.
+
+
-+However, the best source of typemap information (and examples) is +probably the Python module itself. In fact, all of SWIG's default +type handling is defined by typemaps. You can view these typemaps by +looking at the files in the SWIG library. Just take into account that +in the latest versions of swig (1.3.22+), the library files are not +very pristine clear for the casual reader, as they used to be. The +extensive use of macros and other ugly techniques in the latest +version produce a very powerful and consistent python typemap library, +but at the cost of simplicity and pedagogic value. + +To learn how to write a simple or your first typemap, you better take +a look at the SWIG library version 1.3.20 or so. -Additional typemap examples can also be found in the typemaps.i file.-$ swig -python -co python.swg -'python.swg' checked out from the SWIG library. -$ cat python.swg --
-then the friend declaration does not result in any wrapper code. On the other hand, -a declaration of the function itself will work fine. For instance: +then the friend declaration does result in a wrapper code +equivalent to one generated for the following declaration@@ -780,26 +781,41 @@ public:
class Foo {
public:
...
- friend void blah(Foo *f); // Ignored
- ...
};
-void blah(Foo *f); // Generates wrappers
+void blah(Foo *f);
-Unlike normal member functions or static member functions, a friend
-declaration does not define a method that operates on an instance of
-an object nor does it define a declaration in the scope of the class.
-Therefore, it would make no sense for SWIG to create wrappers as such.
+A friend declaration, as in C++, is understood to be in the same scope
+where the class is declared, hence, you can do
+
+
+
+
+%ignore bar::blah(Foo *f);
+
+namespace bar {
+
+ class Foo {
+ public:
+ ...
+ friend void blah(Foo *f);
+ ...
+ };
+}
+
+
+
+and a wrapper for the method 'blah' will not be generated.
Note: The special treatment for references to primitive datatypes is necessary to provide more seamless integration with more advanced C++ wrapping applications---especially related to templates and the STL. This was first added in SWIG-1.3.12.
+
+
+class Foo {
+public:
+ template<class T> void bar(T x, T y) { ... };
+ ...
+};
+...
+
+%template(barint) Foo::bar<int>;
+%template(bardouble) Foo::bar<double>;
+
+
+
+
Note: because of the way that templates are handled, the %template directive
must always appear after the definition of the template to be expanded.
@@ -2637,7 +2676,8 @@ Miraculously, you will find that each expansion of Foo has member
functions bari() and bard() added.
-A common use of member templates is to define constructors for copies and conversions. For example: +A common use of member templates is to define constructors for copies +and conversions. For example:
@@ -3422,8 +3462,8 @@ accessible through operator->(). This includes any methods that might be accessible through inheritance. However, there are a number of restrictions:-
- Only member variables and methods are wrapped through a smart pointer. Static members, enumerations, -constructors, and destructors are not wrapped. +
- Member variables and methods are wrapped through a smart +pointer. Enumerations, constructors, and destructors are not wrapped.
- If the smart-pointer class and the underlying object both define a method or