Merge branch 'master' into directorargout_and_java_typemaps
This commit is contained in:
commit
4ba9de370e
470 changed files with 15434 additions and 3110 deletions
14
.travis.yml
14
.travis.yml
|
|
@ -91,7 +91,17 @@ matrix:
|
||||||
dist: trusty
|
dist: trusty
|
||||||
- compiler: gcc
|
- compiler: gcc
|
||||||
os: linux
|
os: linux
|
||||||
env: SWIGLANG=php
|
env: SWIGLANG=php5
|
||||||
|
sudo: required
|
||||||
|
dist: trusty
|
||||||
|
- compiler: gcc
|
||||||
|
os: linux
|
||||||
|
env: SWIGLANG=php VER=7.0
|
||||||
|
sudo: required
|
||||||
|
dist: trusty
|
||||||
|
- compiler: gcc
|
||||||
|
os: linux
|
||||||
|
env: SWIGLANG=php VER=7.1
|
||||||
sudo: required
|
sudo: required
|
||||||
dist: trusty
|
dist: trusty
|
||||||
- compiler: gcc
|
- compiler: gcc
|
||||||
|
|
@ -249,7 +259,7 @@ matrix:
|
||||||
env: SWIGLANG=perl5
|
env: SWIGLANG=perl5
|
||||||
- compiler: clang
|
- compiler: clang
|
||||||
os: osx
|
os: osx
|
||||||
env: SWIGLANG=php
|
env: SWIGLANG=php5
|
||||||
- compiler: clang
|
- compiler: clang
|
||||||
os: osx
|
os: osx
|
||||||
env: SWIGLANG=python
|
env: SWIGLANG=python
|
||||||
|
|
|
||||||
8
ANNOUNCE
8
ANNOUNCE
|
|
@ -1,8 +1,8 @@
|
||||||
*** ANNOUNCE: SWIG 3.0.11 (in progress) ***
|
*** ANNOUNCE: SWIG 3.0.12 (in progress) ***
|
||||||
|
|
||||||
http://www.swig.org
|
http://www.swig.org
|
||||||
|
|
||||||
We're pleased to announce SWIG-3.0.11, the latest SWIG release.
|
We're pleased to announce SWIG-3.0.12, the latest SWIG release.
|
||||||
|
|
||||||
What is SWIG?
|
What is SWIG?
|
||||||
=============
|
=============
|
||||||
|
|
@ -27,11 +27,11 @@ Availability
|
||||||
============
|
============
|
||||||
The release is available for download on Sourceforge at
|
The release is available for download on Sourceforge at
|
||||||
|
|
||||||
http://prdownloads.sourceforge.net/swig/swig-3.0.11.tar.gz
|
http://prdownloads.sourceforge.net/swig/swig-3.0.12.tar.gz
|
||||||
|
|
||||||
A Windows version is also available at
|
A Windows version is also available at
|
||||||
|
|
||||||
http://prdownloads.sourceforge.net/swig/swigwin-3.0.11.zip
|
http://prdownloads.sourceforge.net/swig/swigwin-3.0.12.zip
|
||||||
|
|
||||||
Please report problems with this release to the swig-devel mailing list,
|
Please report problems with this release to the swig-devel mailing list,
|
||||||
details at http://www.swig.org/mail.html.
|
details at http://www.swig.org/mail.html.
|
||||||
|
|
|
||||||
320
CHANGES
320
CHANGES
|
|
@ -2,6 +2,322 @@ SWIG (Simplified Wrapper and Interface Generator)
|
||||||
|
|
||||||
See the CHANGES.current file for changes in the current version.
|
See the CHANGES.current file for changes in the current version.
|
||||||
See the RELEASENOTES file for a summary of changes in each release.
|
See the RELEASENOTES file for a summary of changes in each release.
|
||||||
|
Issue # numbers mentioned below can be found on Github. For more details, add
|
||||||
|
the issue number to the end of the URL: https://github.com/swig/swig/issues/
|
||||||
|
|
||||||
|
Version 3.0.11 (29 Dec 2016)
|
||||||
|
============================
|
||||||
|
|
||||||
|
2016-12-24: wsfulton
|
||||||
|
[C#] Add %feature("csdirectordelegatemodifiers") to enable customization
|
||||||
|
of the delegate access modifiers generated in director classes.
|
||||||
|
Fixes issue #748.
|
||||||
|
|
||||||
|
2016-12-23: wsfulton
|
||||||
|
[Python] Fix builtin "python:slot" feature failing for tp_hash when using
|
||||||
|
hashfunc closure with a "Wrong type for hash function" for Python 2.
|
||||||
|
Issue #843.
|
||||||
|
|
||||||
|
2016-12-21: joequamt
|
||||||
|
Changed generation of functions so that only functions
|
||||||
|
that end in _set generate accessor functions rather than
|
||||||
|
looking for "set".
|
||||||
|
Change generation of operators to not have underscores
|
||||||
|
to start in R. Users need to provide custom names for these operator overloads.
|
||||||
|
|
||||||
|
2016-12-21: olly
|
||||||
|
Fix isfinite() checks to work with all C++11 compilers.
|
||||||
|
Fixes issues #615, #788 and #849.
|
||||||
|
|
||||||
|
2016-12-20: wsfulton
|
||||||
|
%namewarn unnecessarily caused keyword warnings for non-instantiated template classes
|
||||||
|
and duplicate warnings for instantiated template classes when keywords were used.
|
||||||
|
Issue #845.
|
||||||
|
|
||||||
|
2016-12-18: ezralanglois
|
||||||
|
[Python, Ruby, Octave] Memory leak fix on error in std::pair wrappers.
|
||||||
|
Issue #851.
|
||||||
|
|
||||||
|
2016-12-18: wsfulton
|
||||||
|
Zero initialize arrays when using %array_class and %array_functions.
|
||||||
|
|
||||||
|
2016-12-18: t-ikegami
|
||||||
|
[Python] Fix #446
|
||||||
|
Python %array_class of carrays.i failed with -builtin option.
|
||||||
|
|
||||||
|
2016-12-16: bcaine
|
||||||
|
[Guile] Patch #744 Added support for Guile's native pointer functionality
|
||||||
|
|
||||||
|
2016-12-01: wsfulton
|
||||||
|
[Python] Issue #769.
|
||||||
|
Add optional moduleimport attribute to %module so that the
|
||||||
|
default module import code can be overridden. See the "Searching for the wrapper module"
|
||||||
|
documentation in Python.html. Example:
|
||||||
|
|
||||||
|
%module(moduleimport="import _foo") foo
|
||||||
|
|
||||||
|
$module also expands to the low-level C/C++ module name, so the following is the
|
||||||
|
same as above
|
||||||
|
|
||||||
|
%module(moduleimport="import $module") foo
|
||||||
|
|
||||||
|
2016-11-30: olly
|
||||||
|
[PHP] Add support for PHP7. PHP5's C extension API has changed
|
||||||
|
substantially so you need to use -php7 to specify you want PHP7
|
||||||
|
compatible wrappers. The default extension for generated wrappers
|
||||||
|
is now .cxx (to match SWIG's default for every other language - to
|
||||||
|
generate foo_wrap.cpp you can run SWIG with -cppext cpp). Fixes
|
||||||
|
issue #571.
|
||||||
|
|
||||||
|
As part of this change, the language subdirectory for PHP5 has
|
||||||
|
changed from "php" to "php5" - if you are making use of the search
|
||||||
|
path feature where the language subdirectory of each directory
|
||||||
|
is also searched, you'll need to update your bindings. A simple
|
||||||
|
fix which works for older and newer SWIG is to add a symlink:
|
||||||
|
ln -s php php5
|
||||||
|
|
||||||
|
*** POTENTIAL INCOMPATIBILITY ***
|
||||||
|
|
||||||
|
2016-11-30: olly
|
||||||
|
[PHP] Only emit one copy of each distinct arginfo. Previously we
|
||||||
|
emitted a separate one for every wrapped function, but typically
|
||||||
|
many functions have the same number of parameters and combinations
|
||||||
|
of parameters passed by reference or not.
|
||||||
|
|
||||||
|
This change significantly reduces both the size of the generated
|
||||||
|
wrapper, and of the compiled PHP extension module (e.g. by ~6% for
|
||||||
|
the stripped extension module for Xapian's PHP7 bindings).
|
||||||
|
|
||||||
|
2016-11-28: wsfulton
|
||||||
|
Fix %rename override of wildcard %rename for templates. For example:
|
||||||
|
|
||||||
|
%rename(GlobalIntOperator) *::operator bool; // wildcard %rename
|
||||||
|
|
||||||
|
%rename(XIntOperator) X::operator bool; // fix now overrides first %rename above
|
||||||
|
OR
|
||||||
|
%rename(XIntOperator) X<int>::operator bool; // fix now overrides first %rename above
|
||||||
|
|
||||||
|
template<typename T> struct X {
|
||||||
|
operator bool();
|
||||||
|
...
|
||||||
|
};
|
||||||
|
%template(Xint) X<int>;
|
||||||
|
|
||||||
|
This also fixes %rename override of global %rename for templates. For example:
|
||||||
|
|
||||||
|
// Global rename to make all functions start with a lower case letter
|
||||||
|
%rename("%(firstlowercase)s", %$isfunction ) "";
|
||||||
|
%rename(woohoo) W::Woo; // fix now overrides above %rename
|
||||||
|
|
||||||
|
template<typename T> struct W {
|
||||||
|
W Woo();
|
||||||
|
...
|
||||||
|
};
|
||||||
|
%template(Wint) W<int>;
|
||||||
|
|
||||||
|
The above also introduces a possibly unexpected change. Many of the STL containers
|
||||||
|
provided by SWIG use %rename to rename some methods, eg in std::vector, push_back
|
||||||
|
is renamed to add in Java. Previously this intended rename did not happen when using
|
||||||
|
using global %rename rules and the method would remain as push_back, but is now
|
||||||
|
renamed to add. Some more info in issue #856.
|
||||||
|
|
||||||
|
*** POTENTIAL INCOMPATIBILITY ***
|
||||||
|
|
||||||
|
2016-11-26: m7thon
|
||||||
|
[Python] Issue #709 - improved wrapping of division operators
|
||||||
|
'from __future__ import division' now works in Python 2 whether or not the
|
||||||
|
-py3 flag is used.
|
||||||
|
|
||||||
|
2016-11-12: joequant
|
||||||
|
[R] Issue #697 - fix comma issue with overload methods
|
||||||
|
|
||||||
|
2016-11-12: joequant
|
||||||
|
[R] Issue #555 - R runtime needs stdio.h
|
||||||
|
|
||||||
|
2016-11-02: wsfulton
|
||||||
|
[Python] Issue #816 - fix compilation error when using -extranative and -builtin.
|
||||||
|
|
||||||
|
2016-11-02: liorgold
|
||||||
|
Patch #741 - Add support for C++11 alias templates, see updated CPlusPlus11.html
|
||||||
|
documentation.
|
||||||
|
|
||||||
|
2016-10-30: myd7349
|
||||||
|
[C#] Patch #740 Add std_array.i for C# for wrapping std::array.
|
||||||
|
|
||||||
|
Patch also enhances std::vector<std::wstring> C# wrappers with additional functions
|
||||||
|
(Contains, IndexOf, LastIndexOf and Remove).
|
||||||
|
|
||||||
|
2016-10-30: tobilau
|
||||||
|
[Java] Fix wrappers for wstring parameters in director methods to cleanup local
|
||||||
|
ref after director callback has finished.
|
||||||
|
|
||||||
|
2016-10-23: wsfulton
|
||||||
|
[C#] Add missing csdirectorin VOID_INT_PTR and csdirectorout VOID_INT_PTR typemaps.
|
||||||
|
|
||||||
|
2016-10-23: jiulongw
|
||||||
|
Patch #781 - Fix wrapping of C compound expressions containing char constants
|
||||||
|
in quotes such as:
|
||||||
|
|
||||||
|
#define H_SUPPRESS_SCALING_MAGIC (('s'<<24) | ('u'<<16) | ('p'<<8) | 'p')
|
||||||
|
|
||||||
|
enum DifferentTypes {
|
||||||
|
typecharcompound='A'+1,
|
||||||
|
typecharcompound2='B' << 2
|
||||||
|
};
|
||||||
|
|
||||||
|
2016-10-13: wsfulton
|
||||||
|
[Python] Issue #808 - fix Python pickling and metaclass for builtin wrappers.
|
||||||
|
|
||||||
|
The metaclass (SwigPyObjectType) for SWIG objects was not defined in
|
||||||
|
a way that let importlib successfully import the Python wrappers.
|
||||||
|
The pickle module previously failed to pickle objects because it couldn't
|
||||||
|
determine what module the SWIG wrapped objects were in.
|
||||||
|
|
||||||
|
2016-09-29: wsfulton
|
||||||
|
[Allegrocl, CFFI, GO, Javascript, Ocaml, R, Scilab]
|
||||||
|
Add missing support for the "ret" typemap in a few target languages.
|
||||||
|
The documentation also now has info on the "ret" typemap.
|
||||||
|
|
||||||
|
2016-09-27: ahmed-usman
|
||||||
|
[xml] Handle template parameters correctly.
|
||||||
|
|
||||||
|
2016-09-27: dontpanic92
|
||||||
|
[Go] Fix argument names in inherited functions taking more than 8
|
||||||
|
parameters. Fixes #795.
|
||||||
|
|
||||||
|
2016-09-26: smarchetto
|
||||||
|
[Scilab] mlists that map pointers can be given a custom type name.
|
||||||
|
|
||||||
|
2016-09-25: wsfulton
|
||||||
|
Patch #793 from q-p to expand exception handling to include std::bad_cast
|
||||||
|
in std_except.i.
|
||||||
|
|
||||||
|
2016-09-24: olly
|
||||||
|
[PHP] Fix code generated for feature("director:except") -
|
||||||
|
previously the return value of call_user_function() was ignored and
|
||||||
|
we checked an uninitialised value instead. Fixes #627. Based on
|
||||||
|
patch from Sergey Seroshtan.
|
||||||
|
|
||||||
|
2016-09-22: wsfulton
|
||||||
|
[Python] More flexible python builtin slots for overloaded C++ function.
|
||||||
|
|
||||||
|
The closure names used for builtin slots are mangled with their functype so
|
||||||
|
that overloaded C++ method names can be used for multiple slots.
|
||||||
|
For example:
|
||||||
|
|
||||||
|
%feature("python:slot", "mp_subscript", functype="binaryfunc") SimpleArray::__getitem__;
|
||||||
|
%feature("python:slot", "sq_item", functype="ssizeargfunc") SimpleArray::__getitem__(Py_ssize_t n);
|
||||||
|
|
||||||
|
will generate closures:
|
||||||
|
|
||||||
|
SWIGPY_SSIZEARGFUNC_CLOSURE(_wrap_SimpleArray___getitem__) /* defines _wrap_SimpleArray___getitem___ssizeargfunc_closure */
|
||||||
|
SWIGPY_BINARYFUNC_CLOSURE(_wrap_SimpleArray___getitem__) /* defines _wrap_SimpleArray___getitem___binaryfunc_closure */
|
||||||
|
|
||||||
|
Previously only one name was defined: _wrap_SimpleArray___getitem___closure.
|
||||||
|
Hence the overloaded __getitem__ method can be used to support both mp_subscript and sq_item slots.
|
||||||
|
|
||||||
|
2016-09-17: wsfulton
|
||||||
|
[Python] Fix iterators for containers of NULL pointers (or Python None) when using
|
||||||
|
-builtin. Previously iteration would stop at the first element that was NULL.
|
||||||
|
|
||||||
|
2016-09-16: olly
|
||||||
|
[Javascript] Fix SWIG_exception() macro to return from the current
|
||||||
|
function. Fixes #789, reported by Julien Dutriaux.
|
||||||
|
|
||||||
|
2016-09-16: olly
|
||||||
|
[PHP] Fix SWIG_exception() macro to return from the current function.
|
||||||
|
Fixes #240, reported by Sergey Seroshtan.
|
||||||
|
|
||||||
|
2016-09-12: xypron
|
||||||
|
[C#] Patch #786 Keyword rename to be CLS compliant by adding an underscore
|
||||||
|
suffix instead of an underscore prefix to the C symbol name. Please use an explicit
|
||||||
|
%rename to rename the symbol with a _ prefix if you want the old symbol name.
|
||||||
|
|
||||||
|
*** POTENTIAL INCOMPATIBILITY ***
|
||||||
|
|
||||||
|
2016-09-09: olly
|
||||||
|
[Python] Fix import handling for Python 2.6 to work in a frozen
|
||||||
|
application. Fixes #145, reported by Thomas Kluyver.
|
||||||
|
|
||||||
|
2016-09-02: smarchetto
|
||||||
|
[Scilab] Pointers are mapped to mlist instead of tlist
|
||||||
|
(mlist better for scilab overloading)
|
||||||
|
|
||||||
|
2016-09-02: olly
|
||||||
|
[PHP] Fix "out" typemap for member function pointers and "in"
|
||||||
|
typemap for char INPUT[ANY].
|
||||||
|
|
||||||
|
2016-09-01: wsfulton
|
||||||
|
[Python] More efficient Python slicing.
|
||||||
|
Call reserve for container types that support it to avoid repeated
|
||||||
|
memory reallocations for new slices or slices that grow in size.
|
||||||
|
|
||||||
|
2016-09-01: wsfulton
|
||||||
|
[Python] #771 - Make builtin types hashable by default.
|
||||||
|
Default hash is the underlying C/C++ pointer. This matches up with testing for
|
||||||
|
equivalence (Py_EQ in SwigPyObject_richcompare) which compares the pointers.
|
||||||
|
|
||||||
|
2016-08-22: wsfulton
|
||||||
|
[Python] The following builtin slots can be customized like other slots via the
|
||||||
|
"python:<x>" and "python:slot" features where <x> is the appropriate slot name:
|
||||||
|
tp_allocs
|
||||||
|
tp_bases
|
||||||
|
tp_basicsize
|
||||||
|
tp_cache
|
||||||
|
tp_del
|
||||||
|
tp_dealloc
|
||||||
|
tp_flags
|
||||||
|
tp_frees
|
||||||
|
tp_getset
|
||||||
|
tp_is_gc
|
||||||
|
tp_maxalloc
|
||||||
|
tp_methods
|
||||||
|
tp_mro
|
||||||
|
tp_new
|
||||||
|
tp_next
|
||||||
|
tp_prev
|
||||||
|
tp_richcompare
|
||||||
|
tp_subclasses
|
||||||
|
tp_weaklist
|
||||||
|
was_sq_ass_slice
|
||||||
|
was_sq_slice
|
||||||
|
|
||||||
|
A few documentation improvements for slot customization.
|
||||||
|
|
||||||
|
2016-08-09: joequant
|
||||||
|
[R] Patch #765 Fix extern "C" header includes for C++ code.
|
||||||
|
|
||||||
|
2016-08-05: olly
|
||||||
|
[xml] Fix how the output filename is built to avoid problems when
|
||||||
|
it contains the embedded strings ".c", ".cpp" or ".cxx".
|
||||||
|
Fixes #540 reported by djack42.
|
||||||
|
|
||||||
|
2016-07-01: wsfulton
|
||||||
|
Fix corner case of wrapping std::vector of T pointers where a pointer to a pointer of T
|
||||||
|
also exists in the wrapped code. SF Bug 2359417 (967).
|
||||||
|
|
||||||
|
2016-06-26: wkalinin
|
||||||
|
[Java, C#] Patch #681 Fix seg fault when ignoring nested classes.
|
||||||
|
|
||||||
|
2016-06-25: mromberg
|
||||||
|
[Python] #711 Fix -castmode and conversion of signed and unsigned integer types.
|
||||||
|
See 2015-12-23 CHANGES entry for details of these improvements when they were
|
||||||
|
implemented for the default options (ie not using -castmode).
|
||||||
|
|
||||||
|
2016-06-25: ahnolds
|
||||||
|
Patch #730 - Fix %implicitconv for overloaded functions when using
|
||||||
|
-castmode or -fastdispatch options.
|
||||||
|
|
||||||
|
The result is that in all overload cases where there are multiple possibilities
|
||||||
|
with the same number of arguments, the dispatch function will first check for
|
||||||
|
exact (aka non implicit) matches, and then subsequently check for implicit
|
||||||
|
casting matches. This was already happening in the normal dispatch situation,
|
||||||
|
and in the -fastdispatch case two passes through the candidates were happening,
|
||||||
|
just with SWIG_POINTER_IMPLICIT_CONV always set. After this patch, it is not set
|
||||||
|
on the first pass, and then set on the second pass.
|
||||||
|
|
||||||
|
2016-06-25: liorgold
|
||||||
|
Patch #727 - Add support for C++11 type aliasing.
|
||||||
|
|
||||||
Version 3.0.10 (12 Jun 2016)
|
Version 3.0.10 (12 Jun 2016)
|
||||||
============================
|
============================
|
||||||
|
|
@ -177,7 +493,7 @@ Version 3.0.9 (29 May 2016)
|
||||||
|
|
||||||
2016-03-01: olly
|
2016-03-01: olly
|
||||||
Fix isfinite() check to work with GCC6. Fixes
|
Fix isfinite() check to work with GCC6. Fixes
|
||||||
https://github.com/swig/swig/issues/615 reported by jplesnik.
|
issue #615 reported by jplesnik.
|
||||||
|
|
||||||
2016-02-17: olly
|
2016-02-17: olly
|
||||||
[Python] Add missing keywords 'as' and 'with' to pythonkw.swg.
|
[Python] Add missing keywords 'as' and 'with' to pythonkw.swg.
|
||||||
|
|
@ -234,7 +550,7 @@ Version 3.0.9 (29 May 2016)
|
||||||
|
|
||||||
2016-01-12: olly
|
2016-01-12: olly
|
||||||
[Javascript] For v8 >= 4.3.0, use V8_MAJOR_VERSION.
|
[Javascript] For v8 >= 4.3.0, use V8_MAJOR_VERSION.
|
||||||
Fixes https://github.com/swig/swig/issues/561.
|
Fixes issue 561.
|
||||||
|
|
||||||
2016-01-10: ahnolds
|
2016-01-10: ahnolds
|
||||||
Improved size_t and ptrdiff_t typemaps to support large values
|
Improved size_t and ptrdiff_t typemaps to support large values
|
||||||
|
|
|
||||||
214
CHANGES.current
214
CHANGES.current
|
|
@ -1,184 +1,68 @@
|
||||||
Below are the changes for the current release.
|
Below are the changes for the current release.
|
||||||
See the CHANGES file for changes in older releases.
|
See the CHANGES file for changes in older releases.
|
||||||
See the RELEASENOTES file for a summary of changes in each release.
|
See the RELEASENOTES file for a summary of changes in each release.
|
||||||
|
Issue # numbers mentioned below can be found on Github. For more details, add
|
||||||
|
the issue number to the end of the URL: https://github.com/swig/swig/issues/
|
||||||
|
|
||||||
Version 3.0.11 (in progress)
|
Version 3.0.12 (in progress)
|
||||||
============================
|
============================
|
||||||
|
|
||||||
2016-10-30: myd7349
|
2017-01-16: wkalinin
|
||||||
[C#] Patch #740 Add std_array.i for C# for wrapping std::array.
|
[C#] Fix #733 regression introduced in swig-3.0.9.
|
||||||
|
Missing virtual function override in C# layer when using %import.
|
||||||
|
|
||||||
Patch also enhances std::vector<std::wstring> C# wrappers with additional functions
|
2017-01-16: fschlimb
|
||||||
(Contains, IndexOf, LastIndexOf and Remove).
|
Fix #813 template symbol name lookup bug when typedef names are the same but in different
|
||||||
|
namespaces.
|
||||||
|
|
||||||
2016-10-30: tobilau
|
2017-01-15: wsfulton
|
||||||
[Java] Fix wrappers for wstring parameters in director methods to cleanup local
|
[C# D Java]
|
||||||
ref after director callback has finished.
|
The SWIG library no longer uses the javatype, dtype or cstype typemaps, thereby
|
||||||
|
completely freeing them up for users to use without having to replicate the library
|
||||||
|
code that they previously added. The code previously generated by these typemaps
|
||||||
|
has been replaced by the new %proxycode directive. Their use in the library code
|
||||||
|
was fairly minimal:
|
||||||
|
|
||||||
2016-10-23: wsfulton
|
C# cstype: std_array.i std_map.i std_vector.i
|
||||||
[C#] Add missing csdirectorin VOID_INT_PTR and csdirectorout VOID_INT_PTR typemaps.
|
D dtype: std_vector.i
|
||||||
|
Java javatype: arrays_java.i
|
||||||
|
|
||||||
2016-10-23: jiulongw
|
2017-01-14: wsfulton
|
||||||
Patch #781 - Fix wrapping of C compound expressions containing char constants
|
The %extend directive can now optionally support one of the 'class', 'struct' or 'union'
|
||||||
in quotes such as:
|
keywords before the identifier name, for example:
|
||||||
|
|
||||||
#define H_SUPPRESS_SCALING_MAGIC (('s'<<24) | ('u'<<16) | ('p'<<8) | 'p')
|
struct X { ... };
|
||||||
|
%extend struct X { ... }
|
||||||
|
|
||||||
enum DifferentTypes {
|
Previously this had to specified as:
|
||||||
typecharcompound='A'+1,
|
|
||||||
typecharcompound2='B' << 2
|
|
||||||
};
|
|
||||||
|
|
||||||
2016-10-13: wsfulton
|
struct X { ... };
|
||||||
[Python] Issue #808 - fix Python pickling and metaclass for builtin wrappers.
|
%extend X { ... }
|
||||||
|
|
||||||
The metaclass (SwigPyObjectType) for SWIG objects was not defined in
|
2017-01-13: wsfulton
|
||||||
a way that let importlib successfully import the Python wrappers.
|
[C# D Java] Add new %proxycode directive which is a macro for %insert("proxycode").
|
||||||
The pickle module previously failed to pickle objects because it couldn't
|
This is a way of adding pure C#/D/Java code into the appropriate proxy class, eg:
|
||||||
determine what module the SWIG wrapped objects were in.
|
|
||||||
|
|
||||||
2016-09-29: wsfulton
|
%extend Proxy2 {
|
||||||
[Allegrocl, CFFI, GO, Javascript, Ocaml, R, Scilab]
|
%proxycode %{
|
||||||
Add missing support for the "ret" typemap in a few target languages.
|
public int proxycode2(int i) {
|
||||||
The documentation also now has info on the "ret" typemap.
|
return i+2;
|
||||||
|
}
|
||||||
|
%}
|
||||||
|
}
|
||||||
|
|
||||||
2016-09-27: ahmed-usman
|
%inline %{
|
||||||
[xml] Handle template parameters correctly.
|
struct Proxy2 {};
|
||||||
|
%}
|
||||||
|
|
||||||
2016-09-27: dontpanic92
|
There will then be a pure Java/C#/D method called proxycode2 in the Proxy2 class.
|
||||||
[Go] Fix argument names in inherited functions taking more than 8
|
|
||||||
parameters. Fixes #795.
|
|
||||||
|
|
||||||
2016-09-26: smarchetto
|
2016-12-31: ajrheading1
|
||||||
[Scilab] mlists that map pointers can be given a custom type name.
|
Issue #860 - Remove use of std::unary_function and std::binary_function
|
||||||
|
which is deprecated in C++11.
|
||||||
|
|
||||||
2016-09-25: wsfulton
|
2016-12-30: olly
|
||||||
Patch #793 from q-p to expand exception handling to include std::bad_cast
|
[PHP7] Register internal 'swig_runtime_data_type_pointer' constant
|
||||||
in std_except.i.
|
as "CONST_PERSISTENT" to avoid segmentation fault on module unload.
|
||||||
|
Fixes https://github.com/swig/swig/issues/859 reported by Timotheus
|
||||||
2016-09-24: olly
|
Pokorra - thanks also to Javier Torres for a minimal reproducer.
|
||||||
[PHP] Fix code generated for feature("director:except") -
|
|
||||||
previously the return value of call_user_function() was ignored and
|
|
||||||
we checked an uninitialised value instead. Fixes #627. Based on
|
|
||||||
patch from Sergey Seroshtan.
|
|
||||||
|
|
||||||
2016-09-22: wsfulton
|
|
||||||
[Python] More flexible python builtin slots for overloaded C++ function.
|
|
||||||
|
|
||||||
The closure names used for builtin slots are mangled with their functype so
|
|
||||||
that overloaded C++ method names can be used for multiple slots.
|
|
||||||
For example:
|
|
||||||
|
|
||||||
%feature("python:slot", "mp_subscript", functype="binaryfunc") SimpleArray::__getitem__;
|
|
||||||
%feature("python:slot", "sq_item", functype="ssizeargfunc") SimpleArray::__getitem__(Py_ssize_t n);
|
|
||||||
|
|
||||||
will generate closures:
|
|
||||||
|
|
||||||
SWIGPY_SSIZEARGFUNC_CLOSURE(_wrap_SimpleArray___getitem__) /* defines _wrap_SimpleArray___getitem___ssizeargfunc_closure */
|
|
||||||
SWIGPY_BINARYFUNC_CLOSURE(_wrap_SimpleArray___getitem__) /* defines _wrap_SimpleArray___getitem___binaryfunc_closure */
|
|
||||||
|
|
||||||
Previously only one name was defined: _wrap_SimpleArray___getitem___closure.
|
|
||||||
Hence the overloaded __getitem__ method can be used to support both mp_subscript and sq_item slots.
|
|
||||||
|
|
||||||
2016-09-17: wsfulton
|
|
||||||
[Python] Fix iterators for containers of NULL pointers (or Python None) when using
|
|
||||||
-builtin. Previously iteration would stop at the first element that was NULL.
|
|
||||||
|
|
||||||
2016-09-16: olly
|
|
||||||
[Javascript] Fix SWIG_exception() macro to return from the current
|
|
||||||
function. Fixes #789, reported by Julien Dutriaux.
|
|
||||||
|
|
||||||
2016-09-16: olly
|
|
||||||
[PHP] Fix SWIG_exception() macro to return from the current function.
|
|
||||||
Fixes #240, reported by Sergey Seroshtan.
|
|
||||||
|
|
||||||
2016-09-12: xypron
|
|
||||||
[C#] Patch #786 Keyword rename to be CLS compliant by adding an underscore
|
|
||||||
suffix instead of an underscore suffix to the C symbol name. Please use an explicit
|
|
||||||
%rename to rename the symbol with a _ prefix if you want the old symbol name.
|
|
||||||
|
|
||||||
*** POTENTIAL INCOMPATIBILITY ***
|
|
||||||
|
|
||||||
2016-09-09: olly
|
|
||||||
[Python] Fix import handling for Python 2.6 to work in a frozen
|
|
||||||
application. Fixes #145, reported by Thomas Kluyver.
|
|
||||||
|
|
||||||
2016-09-02: smarchetto
|
|
||||||
[Scilab] Pointers are mapped to mlist instead of tlist
|
|
||||||
(mlist better for scilab overloading)
|
|
||||||
|
|
||||||
2016-09-02: olly
|
|
||||||
[PHP] Fix "out" typemap for member function pointers and "in"
|
|
||||||
typemap for char INPUT[ANY].
|
|
||||||
|
|
||||||
2016-09-01: wsfulton
|
|
||||||
[Python] More efficient Python slicing.
|
|
||||||
Call reserve for container types that support it to avoid repeated
|
|
||||||
memory reallocations for new slices or slices that grow in size.
|
|
||||||
|
|
||||||
2016-09-01: wsfulton
|
|
||||||
[Python] #771 - Make builtin types hashable by default.
|
|
||||||
Default hash is the underlying C/C++ pointer. This matches up with testing for
|
|
||||||
equivalence (Py_EQ in SwigPyObject_richcompare) which compares the pointers.
|
|
||||||
|
|
||||||
2016-08-22: wsfulton
|
|
||||||
[Python] The following builtin slots can be customized like other slots via the
|
|
||||||
"python:<x>" and "python:slot" features where <x> is the appropriate slot name:
|
|
||||||
tp_allocs
|
|
||||||
tp_bases
|
|
||||||
tp_basicsize
|
|
||||||
tp_cache
|
|
||||||
tp_del
|
|
||||||
tp_dealloc
|
|
||||||
tp_flags
|
|
||||||
tp_frees
|
|
||||||
tp_getset
|
|
||||||
tp_is_gc
|
|
||||||
tp_maxalloc
|
|
||||||
tp_methods
|
|
||||||
tp_mro
|
|
||||||
tp_new
|
|
||||||
tp_next
|
|
||||||
tp_prev
|
|
||||||
tp_richcompare
|
|
||||||
tp_subclasses
|
|
||||||
tp_weaklist
|
|
||||||
was_sq_ass_slice
|
|
||||||
was_sq_slice
|
|
||||||
|
|
||||||
A few documentation improvements for slot customization.
|
|
||||||
|
|
||||||
2016-08-09: joequant
|
|
||||||
[R] Patch #765 Fix extern "C" header includes for C++ code.
|
|
||||||
|
|
||||||
2016-08-05: olly
|
|
||||||
[xml] Fix how the output filename is built to avoid problems when
|
|
||||||
it contains the embedded strings ".c", ".cpp" or ".cxx".
|
|
||||||
Fixes #540 reported by djack42.
|
|
||||||
|
|
||||||
2016-07-01: wsfulton
|
|
||||||
Fix corner case of wrapping std::vector of T pointers where a pointer to a pointer of T
|
|
||||||
also exists in the wrapped code. SF Bug 2359417 (967).
|
|
||||||
|
|
||||||
2016-06-26: wkalinin
|
|
||||||
[Java, C#] Patch #681 Fix seg fault when ignoring nested classes.
|
|
||||||
|
|
||||||
2016-06-25: mromberg
|
|
||||||
[Python] #711 Fix -castmode and conversion of signed and unsigned integer types.
|
|
||||||
See 2015-12-23 CHANGES entry for details of these improvements when they were
|
|
||||||
implemented for the default options (ie not using -castmode).
|
|
||||||
|
|
||||||
2016-06-25: ahnolds
|
|
||||||
Patch #730 - Fix %implicitconv for overloaded functions when using
|
|
||||||
-castmode or -fastdispatch options.
|
|
||||||
|
|
||||||
The result is that in all overload cases where there are multiple possibilities
|
|
||||||
with the same number of arguments, the dispatch function will first check for
|
|
||||||
exact (aka non implicit) matches, and then subsequently check for implicit
|
|
||||||
casting matches. This was already happening in the normal dispatch situation,
|
|
||||||
and in the -fastdispatch case two passes through the candidates were happening,
|
|
||||||
just with SWIG_POINTER_IMPLICIT_CONV always set. After this patch, it is not set
|
|
||||||
on the first pass, and then set on the second pass.
|
|
||||||
|
|
||||||
2016-06-25: liorgold
|
|
||||||
Patch #727 - Add support for C++11 type aliasing.
|
|
||||||
|
|
|
||||||
|
|
@ -1,788 +0,0 @@
|
||||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
|
||||||
<HTML>
|
|
||||||
<HEAD>
|
|
||||||
<META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=utf-8">
|
|
||||||
<TITLE></TITLE>
|
|
||||||
<META NAME="GENERATOR" CONTENT="OpenOffice.org 3.0 (Unix)">
|
|
||||||
<META NAME="CREATED" CONTENT="20090712;16061100">
|
|
||||||
<META NAME="CHANGED" CONTENT="20090817;17311900">
|
|
||||||
<META NAME="Podatek 1" CONTENT="">
|
|
||||||
<META NAME="Podatek 2" CONTENT="">
|
|
||||||
<META NAME="Podatek 3" CONTENT="">
|
|
||||||
<META NAME="Podatek 4" CONTENT="">
|
|
||||||
<STYLE TYPE="text/css">
|
|
||||||
<!--
|
|
||||||
@page { margin: 2cm }
|
|
||||||
H1 { margin-bottom: 0.21cm }
|
|
||||||
H1.western { font-family: "Liberation Serif", serif }
|
|
||||||
H1.cjk { font-family: "DejaVu Sans" }
|
|
||||||
H1.ctl { font-family: "DejaVu Sans" }
|
|
||||||
P { margin-bottom: 0.21cm }
|
|
||||||
H2 { margin-bottom: 0.21cm }
|
|
||||||
A:link { so-language: zxx }
|
|
||||||
-->
|
|
||||||
</STYLE>
|
|
||||||
</HEAD>
|
|
||||||
<BODY LANG="en-US" DIR="LTR">
|
|
||||||
<H1 CLASS="western"><U>C++0x/C++11 support for SWIG</U></H1>
|
|
||||||
<H1 CLASS="western">Summary</H1>
|
|
||||||
<P>This is a technical overview of the C++0x/C++11 support for the Swig.
|
|
||||||
This area of Swig is a work in progress. Initial C++0x/C++11 support for
|
|
||||||
Swig was written during the Google Summer of Code 2009 period by
|
|
||||||
Matevž Jekovec.</P>
|
|
||||||
<H1 CLASS="western">SVN branch</H1>
|
|
||||||
<P>branches/gsoc2009-matevz</P>
|
|
||||||
<H1 CLASS="western">New C++11 features status</H1>
|
|
||||||
<P>Wikipedia article: <A HREF="http://en.wikipedia.org/wiki/C++0x">http://en.wikipedia.org/wiki/C%2B%2B0x</A>
|
|
||||||
</P>
|
|
||||||
<H2>Rvalue reference and move semantics [done]</H2>
|
|
||||||
<P>The Rvalues are used in practice to speed up the move operations
|
|
||||||
on different containers.</P>
|
|
||||||
<P>In the following example, we want to swap the given elements:</P>
|
|
||||||
<PRE>template <class T> swap(T& a, T& b) {
|
|
||||||
T tmp(a); // now we have two copies of a
|
|
||||||
a = b; // now we have two copies of b
|
|
||||||
b = tmp; // now we have two copies of tmp (aka a)
|
|
||||||
}</PRE><P>
|
|
||||||
This can now be solved using the new function std::move():</P>
|
|
||||||
<PRE>template <class T> swap(T& a, T& b) {
|
|
||||||
T tmp(std::move(a));
|
|
||||||
a = std::move(b);
|
|
||||||
b = std::move(tmp);
|
|
||||||
}</PRE><P STYLE="margin-bottom: 0cm">
|
|
||||||
For the move function to take effect, user needs to reimplement the
|
|
||||||
move constructor (taking ClassType&& as an argument) and
|
|
||||||
operator=(ClassType&&):</P>
|
|
||||||
<PRE>class MyClass {
|
|
||||||
MyClass(MyClass&& p) : ptr(p.ptr) {p.ptr = 0;}
|
|
||||||
MyClass& operator=(MyClass&& p) {
|
|
||||||
std::swap(ptr, p.ptr);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
};</PRE><P>
|
|
||||||
In practice, the Rvalues are used for temporaries (when passing the
|
|
||||||
result of one function as an argument to another).</P>
|
|
||||||
<P>Done: Added type&& to Swig parser. Added testcase
|
|
||||||
cpp11_rvalue_reference.i. Operator && is treated the same as
|
|
||||||
operator &. R11450</P>
|
|
||||||
<P STYLE="margin-bottom: 0cm">Article:
|
|
||||||
<A HREF="http://www.artima.com/cppsource/rvalue.html">http://www.artima.com/cppsource/rvalue.html</A></P>
|
|
||||||
<H2>Generalized constant expressions [done]</H2>
|
|
||||||
<P>In C++11 you can define functions as constant expressions.
|
|
||||||
Functions need to return constant value in form "return expr",
|
|
||||||
where expr is a constant expression.
|
|
||||||
</P>
|
|
||||||
<P>A keyword "constexpr" is introduced for this. eg.:
|
|
||||||
constexpr int getNumber() { return 5; } const int MY_CONSTANT =
|
|
||||||
getNumber();
|
|
||||||
</P>
|
|
||||||
<P>Constants are treated as normal variables in interpreted languages
|
|
||||||
because they are not compiled into the executable. Java "final"
|
|
||||||
constants are defined runtime as well. C++ constants need to be
|
|
||||||
declared in the header file and defined in the implementation file,
|
|
||||||
so swig doesn't need to know about the constant values when parsing
|
|
||||||
the header file.
|
|
||||||
</P>
|
|
||||||
<P>Done: Added the “constexpr “ keyword to Swig. Added testcase
|
|
||||||
cpp11_constexpr. R11322</P>
|
|
||||||
<P>Problem: No compilers were known to support constexpr yet, so the
|
|
||||||
testcase was temporarily commented out in common.mk.
|
|
||||||
</P>
|
|
||||||
<H2>Extern template [done]</H2>
|
|
||||||
<P>Extern template forces the GCC compiler to not instantiate the
|
|
||||||
template in the translation unit at that time. It's a feature
|
|
||||||
specifically aimed at compilers to speed up the compilation process.
|
|
||||||
</P>
|
|
||||||
<P>Done: Added support for 'extern template class
|
|
||||||
std::vector<MyClass>;'. Added testcase cpp11_template_explicit.
|
|
||||||
R11385 , R11386</P>
|
|
||||||
<H2>Initializer lists [done]</H2>
|
|
||||||
<P>Initializer list is a new type in standard library:
|
|
||||||
std::initializer_list<T>. New symbols {} are introduced for the
|
|
||||||
initializer lists.
|
|
||||||
</P>
|
|
||||||
<P>One can now use:
|
|
||||||
</P>
|
|
||||||
<PRE> class A {
|
|
||||||
public:
|
|
||||||
A( std::initializer_list<int> );
|
|
||||||
};
|
|
||||||
A a1 = {1,2,3,4};</PRE><P>
|
|
||||||
Languages like Java, C# and Python already support direct creation of
|
|
||||||
lists natively.</P>
|
|
||||||
<P>Problem: initializer_list cannot be treated as an ordinary list.
|
|
||||||
The constructor containing initializer_list can only be accessed by
|
|
||||||
assigning the value using the {} brackets. I also don't think there
|
|
||||||
is a simple way to convert an ordinary list or a vector to the
|
|
||||||
initializer_list.</P>
|
|
||||||
<P>Done: Ignored the constructor having initializer_list as its
|
|
||||||
argument. Show warning to the user. Added testcase
|
|
||||||
cpp11_initializer_list. R11450</P>
|
|
||||||
<P>Article:
|
|
||||||
<A HREF="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1919.pdf">http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1919.pdf</A></P>
|
|
||||||
<H2>Uniform initialization [done]</H2>
|
|
||||||
<P>The new C++11 standard will allow the following:</P>
|
|
||||||
<PRE>struct IdString {
|
|
||||||
std::string name;
|
|
||||||
int identifier;
|
|
||||||
};
|
|
||||||
|
|
||||||
IdString GetString() {
|
|
||||||
return {"SomeName", 4}; //Note the lack of explicit type.
|
|
||||||
}</PRE><P>
|
|
||||||
The feature works exactly as it did now for POD types only (eg. int
|
|
||||||
a[] = {1,2,3};). The following declarations are the same in the new
|
|
||||||
C++11:</P>
|
|
||||||
<PRE>IdString str1 = {„SomeName“, 4};
|
|
||||||
IdString str2{„SomeName“, 4};</PRE><P>
|
|
||||||
The new way of using uniform initialization allows the following:</P>
|
|
||||||
<PRE>struct BasicStruct {
|
|
||||||
int x;
|
|
||||||
double y;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct AltStruct {
|
|
||||||
AltStruct(int x, double y) : x_{x}, y_{y} {}
|
|
||||||
|
|
||||||
private:
|
|
||||||
int x_;
|
|
||||||
double y_;
|
|
||||||
};
|
|
||||||
|
|
||||||
BasicStruct var1{5, 3.2}; // only fills the struct components
|
|
||||||
AltStruct var2{2, 4.3}; // calls the constructor</PRE><P>
|
|
||||||
The new syntax is specific to C++. Java, C# and scripting languages
|
|
||||||
do not support this behaviour, but always need constructors. They
|
|
||||||
support {} brackets for declaration of arrays as C does + they add
|
|
||||||
support for creation of arrays on-the-fly (what C++11 introduced with
|
|
||||||
this feature and more).</P>
|
|
||||||
<P>Done: Added syntax for {} member initialization in class
|
|
||||||
constructor. Added testcase cpp11_uniform_initialization. R11413</P>
|
|
||||||
<H2>Type inference [partially done]</H2>
|
|
||||||
<P>A new keyword 'auto' is introduced in C++11:</P>
|
|
||||||
<PRE>auto a1 = 100;
|
|
||||||
auto a2 = myFunc();</PRE><P>
|
|
||||||
The type of a1 and a2 is automatically determined according to the
|
|
||||||
initialization value during the semantic phase of the compiler.</P>
|
|
||||||
<P>Another macro 'decltype()' is introduced. The macro takes the
|
|
||||||
concrete object as an argument and returns its type. User could use
|
|
||||||
this as:</P>
|
|
||||||
<PRE>int i = 100;
|
|
||||||
decltype(i) j = 200; // decltype(i) = int</PRE><P STYLE="margin-bottom: 0cm">
|
|
||||||
Calling operators are allowed as well:</P>
|
|
||||||
<PRE STYLE="margin-bottom: 0.5cm">decltype(i+j) k = 300;</PRE><P>
|
|
||||||
Done: Added support for decltype() syntax. Test cases for normal
|
|
||||||
decltype members and alternate function members work fine. Currently
|
|
||||||
only syntax in form decltype(variable name) work. No support for
|
|
||||||
custom expresions eg. decltype(i+j) yet. R11525</P>
|
|
||||||
<P>TODO: William proposed to support the hidden variables as well
|
|
||||||
(ones not parsed by Swig and added to symbol table). This also allows
|
|
||||||
Swig to parse custom expressions like decltype(i+j). The idea is to
|
|
||||||
introduce a new SwigType for this.</P>
|
|
||||||
<H2>Range-based for-loop [ignored]</H2>
|
|
||||||
<P>This feature is always present inside the implementation block
|
|
||||||
only.
|
|
||||||
</P>
|
|
||||||
<H2>Lambda functions and expressions [done]</H2>
|
|
||||||
<P>C++11 introduces lambda functions defined as:</P>
|
|
||||||
<PRE STYLE="margin-bottom: 0.5cm">[](int x, int y) -> int { return x + y; }</PRE><P>
|
|
||||||
If the lambda function contains a single return statement only or the
|
|
||||||
function doesn't return any type, the return type '->' can be
|
|
||||||
omitted. Lambda functions are function objects.</P>
|
|
||||||
<P>The following example prints the number of items stored in a list:</P>
|
|
||||||
<PRE>std::vector<int> someList;
|
|
||||||
int total = 0;
|
|
||||||
std::for_each( someList.begin(), someList.end(), [&total](int x) {total += x} );
|
|
||||||
std::cout << total;</PRE><P>
|
|
||||||
Parameters inside the [] are the visible parameters of the lambda
|
|
||||||
functions. These can be & (references), = (copies), variable name
|
|
||||||
(variable copy), &variable name (variable reference) or this
|
|
||||||
(copy of the current object).</P>
|
|
||||||
<P>Lambda functions can be stored using:</P>
|
|
||||||
<PRE STYLE="margin-bottom: 0.5cm">auto myLambdaFunc = [this]() { this->SomePrivateMemberFunction() };</PRE><P>
|
|
||||||
Proposal: Lambda functions are most commonly used inside the function
|
|
||||||
block to quickly define how the sort, find and similar functions
|
|
||||||
should work (the other way would be overriding a class – the Java
|
|
||||||
style). The latest GCC does not support lambda functions yet so it is
|
|
||||||
difficult to test the feature once implemented. I would implement the
|
|
||||||
syntax support for this feature, but produce no wrapper code. Lambda
|
|
||||||
functions still work inside the function block though.</P>
|
|
||||||
<P>Article:
|
|
||||||
<A HREF="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2550.pdf">http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2550.pdf</A></P>
|
|
||||||
<P>Done: Added syntax support for the lambda functions. Added
|
|
||||||
testcase cpp11_lambda_functions.i. R11491, R11492</P>
|
|
||||||
<H2>Alternate function syntax [done]</H2>
|
|
||||||
<P>The problem with decltype() is that the parameters need to be
|
|
||||||
defined before the decltype. The following syntax is not valid,
|
|
||||||
because lhs and rhs hasn't been defined at the time of decltype:</P>
|
|
||||||
<PRE>template< typename LHS, typename RHS>
|
|
||||||
decltype(lhs+rhs) AddingFunc(const LHS &lhs, const RHS &rhs) {return lhs + rhs;} //Not legal C++11</PRE><P>
|
|
||||||
The solution C++11 offers is the combination of the 'auto' keyword
|
|
||||||
before and '-> rettype' after the function declaration:</P>
|
|
||||||
<PRE>template< typename LHS, typename RHS>
|
|
||||||
auto AddingFunc(const LHS &lhs, const RHS &rhs) -> decltype(lhs+rhs) {return lhs + rhs;}</PRE><P>
|
|
||||||
The new syntax only makes the job for the C++ compilers easier when
|
|
||||||
parsing such functions. The new syntax can be used for ordinary
|
|
||||||
functions as well:</P>
|
|
||||||
<PRE>struct SomeStruct {
|
|
||||||
auto FuncName(int x, int y) -> int;
|
|
||||||
};
|
|
||||||
|
|
||||||
auto SomeStruct::FuncName(int x, int y) -> int {
|
|
||||||
return x + y;
|
|
||||||
}</PRE><P>
|
|
||||||
Done: Added support for the 'auto' return type. Added support for the
|
|
||||||
'-> type' after the funtion declaration. Added testcases
|
|
||||||
cpp11_alternate_function_syntax.i and
|
|
||||||
cpp11_alternate_function_syntax_runme.py. R11414</P>
|
|
||||||
<H2>Concepts, Axioms [ignored]</H2>
|
|
||||||
<P>In C++ there is a common problem when you use a template in the
|
|
||||||
class which doesn't support all the operations the functions in the
|
|
||||||
class actually do on the type. Compiler errors are usually very long
|
|
||||||
and unreadable. C++11 adds support for the "concepts". The
|
|
||||||
idea is to define what operations and attributes should the template
|
|
||||||
have. In contrast to class inheritance and polimorphism, all lookups
|
|
||||||
are done in compile-time.
|
|
||||||
</P>
|
|
||||||
<P>Basic syntax (note LessThanComparable<A HREF="http://www.dabeaz.com/cgi-bin/wiki.pl?action=change1&id=LessThanComparable">?</A>
|
|
||||||
instead of "class" or "typename"):
|
|
||||||
</P>
|
|
||||||
<PRE> template<LessThanComparable<A HREF="http://www.dabeaz.com/cgi-bin/wiki.pl?action=change1&id=LessThanComparable">?</A> T>
|
|
||||||
const T& min(const T &x, const T &y) {
|
|
||||||
return y < x ? y : x;
|
|
||||||
}</PRE><P>
|
|
||||||
Extended syntax (requires conditions are separated with &&,
|
|
||||||
|| or !):
|
|
||||||
</P>
|
|
||||||
<PRE> template< typename T> requires LessThanComparable<A HREF="http://www.dabeaz.com/cgi-bin/wiki.pl?action=change1&id=LessThanComparable">?</A><T>
|
|
||||||
const T& min(const T &x, const T &y) {
|
|
||||||
return y < x ? y : x;
|
|
||||||
}</PRE><P>
|
|
||||||
Definition of the concepts:
|
|
||||||
</P>
|
|
||||||
<PRE> concept LessThanComparable<A HREF="http://www.dabeaz.com/cgi-bin/wiki.pl?action=change1&id=LessThanComparable">?</A>< typename T > {
|
|
||||||
bool operator<(T,T);
|
|
||||||
requires GreaterThanComparable<A HREF="http://www.dabeaz.com/cgi-bin/wiki.pl?action=change1&id=GreaterThanComparable">?</A><T>;
|
|
||||||
typename value_type;
|
|
||||||
typename reference;
|
|
||||||
};</PRE><P>
|
|
||||||
Concept maps allow usage of a specific type:
|
|
||||||
</P>
|
|
||||||
<PRE> template< typename T>
|
|
||||||
concept_map InputIterator<A HREF="http://www.dabeaz.com/cgi-bin/wiki.pl?action=change1&id=InputIterator">?</A><T*> {
|
|
||||||
typedef T value_type ;
|
|
||||||
typedef T& reference ;
|
|
||||||
typedef T* pointer ;
|
|
||||||
typedef std::ptrdiff_t difference_type ;
|
|
||||||
};</PRE><P>
|
|
||||||
Concept maps can act as mini-types, with function definitions and
|
|
||||||
other constructs commonly associated with classes:
|
|
||||||
</P>
|
|
||||||
<PRE> concept Stack< typename X> {
|
|
||||||
typename value_type;
|
|
||||||
void push(X&, const value_type&);
|
|
||||||
void pop(X&);
|
|
||||||
value_type top(const X&);
|
|
||||||
bool empty(const X&);
|
|
||||||
};
|
|
||||||
template< typename T>
|
|
||||||
concept_map Stack<std::vector<T> > {
|
|
||||||
typedef T value_type;
|
|
||||||
void push(std::vector<T>& v, const T& x) { v.push_back(x); }
|
|
||||||
void pop(std::vector<T>& v) { v.pop_back(); }
|
|
||||||
T top(const std::vector<T>& v) { return v.back(); }
|
|
||||||
bool empty(const std::vector<T>& v) { return v.empty(); }
|
|
||||||
};</PRE><P>
|
|
||||||
Axioms are a facility pertaining to concepts supplied by C++11 to
|
|
||||||
express the semantic properties of concepts. For example, the concept
|
|
||||||
Semigroup can be defined with an axiom Associativity as:
|
|
||||||
</P>
|
|
||||||
<PRE> concept Semigroup< typename Op, typename T> : CopyConstructible<A HREF="http://www.dabeaz.com/cgi-bin/wiki.pl?action=change1&id=CopyConstructible">?</A><T> {
|
|
||||||
T operator()(Op, T, T);
|
|
||||||
axiom Associativity(Op op, T x, T y, T z) {
|
|
||||||
op(x, op(y, z)) == op(op(x, y), z);
|
|
||||||
}
|
|
||||||
};</PRE><P>
|
|
||||||
Axioms are more like hints to the compiler to speed-up the process of
|
|
||||||
compilation.
|
|
||||||
</P>
|
|
||||||
<P>Ignored: Concepts and axioms were removed from the C++11 standard.
|
|
||||||
</P>
|
|
||||||
<H2>Object construction improvement [done]</H2>
|
|
||||||
<P>This feature allows classes constructors to call other
|
|
||||||
constructors with different arguments (similar to Java and C#
|
|
||||||
behaviour).
|
|
||||||
</P>
|
|
||||||
<P>The syntax is as follows:
|
|
||||||
</P>
|
|
||||||
<PRE> class SomeType {
|
|
||||||
int number;
|
|
||||||
public:
|
|
||||||
SomeType(int newNumber) : number(newNumber) {}
|
|
||||||
SomeType() : SomeType(42) {}
|
|
||||||
};</PRE><P>
|
|
||||||
Also when using the inheritance, the feature introduces inheritance
|
|
||||||
of all superclass constructors without being defined separately in
|
|
||||||
the inherited class:
|
|
||||||
</P>
|
|
||||||
<PRE> class BaseClass {
|
|
||||||
public:
|
|
||||||
BaseClass(int iValue);
|
|
||||||
};
|
|
||||||
class DerivedClass: public BaseClass {
|
|
||||||
public:
|
|
||||||
using BaseClass::BaseClass; // Adds DerivedClass(int) constructor
|
|
||||||
};</PRE><P>
|
|
||||||
Swig already correctly parses and produces the correct wrapper for
|
|
||||||
the “using” keyword.</P>
|
|
||||||
<P>Done: Added testcase cpp11_constructors.i which covers both
|
|
||||||
constructor delegation and constructor inheritance. R11532</P>
|
|
||||||
<P>Problem: Constructor delegation and constructor inheritance is not
|
|
||||||
supported by any compiler yet, so it's impossible to try and test
|
|
||||||
this feature.</P>
|
|
||||||
<H2>Null pointer constant [done]</H2>
|
|
||||||
<P>nullptr is part of the standard library.
|
|
||||||
</P>
|
|
||||||
<P>It's defined as typedef decltype(nullptr) nullptr_t;
|
|
||||||
</P>
|
|
||||||
<P>nullptr_t is defined in <cstddef>.
|
|
||||||
</P>
|
|
||||||
<P>As far as the C++ is compatible with 0 as the pointer value, swig
|
|
||||||
values will work for the C++. And the other way around, nullptr
|
|
||||||
behaves as the ordinary pointer (false, if empty, true, if not
|
|
||||||
empty), so it's ok for swig to compare it.</P>
|
|
||||||
<P>Done: Written a testcase cpp11_null_pointer_constant.i and
|
|
||||||
cpp11_null_pointer_constant_runme.py to prove the nullptr
|
|
||||||
functionality. R11484</P>
|
|
||||||
<H2>Strongly typed enumerations [partially done]</H2>
|
|
||||||
<P>C++11 introduces a new syntax for strongly typed enum declaration:
|
|
||||||
</P>
|
|
||||||
<PRE> enum class Enumeration {
|
|
||||||
Val1,
|
|
||||||
Val2,
|
|
||||||
Val3 = 100,
|
|
||||||
Val4 /* = 101 */
|
|
||||||
};</PRE><P>
|
|
||||||
Typing if (Val4 == 101) will result in compilation error.
|
|
||||||
</P>
|
|
||||||
<P>The enum itself can now be explicitely of type int, long, unsigned
|
|
||||||
int etc.:
|
|
||||||
</P>
|
|
||||||
<PRE STYLE="margin-bottom: 0.5cm"> enum class Enum2 : unsigned int {Val1, Val2};</PRE><P>
|
|
||||||
And it can be forward declared as well:
|
|
||||||
</P>
|
|
||||||
<PRE> enum Enum1; //Illegal in C++ and C++11; no size is explicitly specified.
|
|
||||||
enum Enum2 : unsigned int; //Legal in C++11.
|
|
||||||
enum class Enum3; //Legal in C++11, because enum class declarations have a default type of "int".
|
|
||||||
enum class Enum4: unsigned int; //Legal C++11.
|
|
||||||
enum Enum2 : unsigned short; //Illegal in C++11, because Enum2 was previously declared with a different type.</PRE><P>
|
|
||||||
Done: Added syntax 'enum class Name' and forward declarators 'enum
|
|
||||||
Name : inherited type' or 'enum class Name : inherited type' in
|
|
||||||
R11449.</P>
|
|
||||||
<P>TODO: Add semantic support for enum elements not clashing with
|
|
||||||
enum elements in other enum classes. See cpp11_strongly_typed_enums.i
|
|
||||||
warnings.</P>
|
|
||||||
<P>Problem: Swig currently doesn't support nested classes. This
|
|
||||||
feature should be implemented using a new nested class when using
|
|
||||||
“enum class” with a single anonymous “enum {elements}”
|
|
||||||
element inside. For example:</P>
|
|
||||||
<PRE STYLE="margin-bottom: 0.5cm">class A { enum class EA { a,b,c,d }; };</PRE><P>
|
|
||||||
should be mapped to</P>
|
|
||||||
<PRE STYLE="margin-bottom: 0.5cm">class A { class EA { enum {a,b,c,d}; }; };</PRE><H2>
|
|
||||||
Angle bracket [done]</H2>
|
|
||||||
<P>Support for right angled brackets was implemented using the
|
|
||||||
following article as a base:
|
|
||||||
<A HREF="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1757.html">http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1757.html</A>
|
|
||||||
</P>
|
|
||||||
<P>Done: Added support for angle brackets. Used the preferred
|
|
||||||
"Approach 1". Added a testcase named
|
|
||||||
cpp11_template_double_brackets. R11245</P>
|
|
||||||
<H2>Explicit conversion operators [done]</H2>
|
|
||||||
<P>This is used when converting one type to another (eg. if
|
|
||||||
(myObject) {}, where myObject is your custom class converted to
|
|
||||||
bool).
|
|
||||||
</P>
|
|
||||||
<P>Requires both operator and function overloading which is not
|
|
||||||
supported in any target language (eg. python, php).
|
|
||||||
</P>
|
|
||||||
<P>Done: Swig already supports the keyword "explicit" for
|
|
||||||
function types as well. Added test case
|
|
||||||
cpp11_explicit_conversion_operators. R11323</P>
|
|
||||||
<H2>Template typedefs [partially done]</H2>
|
|
||||||
<P>The new C++11 will allow creation of wrapper around the template.
|
|
||||||
For example, if we want to do this:</P>
|
|
||||||
<PRE>template< typename first, typename second, int third>
|
|
||||||
class SomeType;
|
|
||||||
|
|
||||||
template< typename second>
|
|
||||||
typedef SomeType<OtherType, second, 5> TypedefName; //Illegal in C++</PRE><P>
|
|
||||||
This is still illegal! But we can now use the new syntax for
|
|
||||||
achieving the same effect:</P>
|
|
||||||
<PRE>template< typename first, typename second, int third>
|
|
||||||
class SomeType;
|
|
||||||
|
|
||||||
template< typename second>
|
|
||||||
using TypedefName = SomeType<OtherType, second, 5>;</PRE><P>
|
|
||||||
Here we created a new wrapper TypedefName taking one template
|
|
||||||
argument <second> which creates a type SomeType<OtherType,
|
|
||||||
second, 5>. OtherType and 5 are predefined here and hidden from
|
|
||||||
the user – the user only uses TypedefName type.</P>
|
|
||||||
<P>The same goes for the following example:</P>
|
|
||||||
<PRE>typedef void (*PFD)(double); // Old style
|
|
||||||
using PF = void (*)(double); // New introduced syntax</PRE><P>
|
|
||||||
Swig supports parsing typedefs for templates as well for example:</P>
|
|
||||||
<PRE STYLE="margin-bottom: 0.5cm">typedef List<int> intList;</PRE><P>
|
|
||||||
Done: Expanded support for the new 'using' syntax and template
|
|
||||||
aliasing. Added testcase cpp11_template_typedefs. R11533</P>
|
|
||||||
<P>TODO: Make Swig aware of the newly defined typedef. The TYPEDEF
|
|
||||||
keyword is part of the storage_class rule and type+declarator (see
|
|
||||||
c_decl rule) is the right part of the definition – for example void
|
|
||||||
(*PFD)(double) cannot be transformed to void *(double) easily. To
|
|
||||||
fully support the new 'using' form, we'll probably have to change the
|
|
||||||
type, type_right rules and declarator, direct_declarator,
|
|
||||||
notso_direct_declarator etc., which is PITA.</P>
|
|
||||||
<H2>Unrestricted unions [done]</H2>
|
|
||||||
<P>C++ currently offers usage of unions for types with trivial
|
|
||||||
constructors only. The new C++11 standard allows usage of types with
|
|
||||||
non-trivial constructors as well:</P>
|
|
||||||
<PRE> struct point {
|
|
||||||
point() {}
|
|
||||||
point(int x, int y): x_(x), y_(y) {}
|
|
||||||
int x_, y_;
|
|
||||||
};
|
|
||||||
union P {
|
|
||||||
int z;
|
|
||||||
double w;
|
|
||||||
point p; // Illegal in C++; point has a non-trivial constructor. However, this is legal in C++11.
|
|
||||||
} p1;</PRE><P>
|
|
||||||
Swig already parses the given syntax.</P>
|
|
||||||
<P>Done: Added testcase cpp11_unrestricted_unions. R11435, R11447</P>
|
|
||||||
<P>Problem: GCC doesn't support unrestricted unions yet so there is
|
|
||||||
no way to actually test, if it works.</P>
|
|
||||||
<H2>Variadic templates [partially done]</H2>
|
|
||||||
<P>The new C++11 offers the following syntax:</P>
|
|
||||||
<PRE STYLE="margin-bottom: 0.5cm">template<typename... Values> class tuple;</PRE><P>
|
|
||||||
This can be used for example:</P>
|
|
||||||
<PRE STYLE="margin-bottom: 0.5cm">class tuple<int, std::vector<int>, std::map<std::string, std::vector<int>>> someInstanceName;</PRE><P>
|
|
||||||
The ... is used in two cases. One is in the template header where it
|
|
||||||
marks on the left the keywords 'typename' or 'class' and a type name
|
|
||||||
on the right. The second case is usually in the function block to
|
|
||||||
decompose typename on the left of the ... . For example:</P>
|
|
||||||
<PRE>void printf(const char *s) {
|
|
||||||
while (*s) {
|
|
||||||
if (*s == '%' && *(++s) != '%')
|
|
||||||
throw std::runtime_error("invalid format string: missing arguments");
|
|
||||||
std::cout << *s++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T, typename... Args>
|
|
||||||
void printf(const char* s, T value, Args... args) { // recursive action – split previous args to value + args
|
|
||||||
while (*s) {
|
|
||||||
if (*s == '%' && *(++s) != '%') {
|
|
||||||
std::cout << value;
|
|
||||||
printf(*s ? ++s : s, args...); // call even when *s == 0 to detect extra arguments
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
std::cout << *s++;
|
|
||||||
}
|
|
||||||
throw std::logic_error("extra arguments provided to printf");
|
|
||||||
}</PRE><P>
|
|
||||||
The tricky part is that variadic templates can unpack actually
|
|
||||||
anywhere – including the class inheritance :(</P>
|
|
||||||
<PRE>template <typename... BaseClasses> class ClassName : public BaseClasses... {
|
|
||||||
public:
|
|
||||||
|
|
||||||
ClassName (BaseClasses&&... baseClasses) : BaseClasses(baseClasses)... {}
|
|
||||||
}</PRE><P>
|
|
||||||
A new extension to sizeof is also introduced with this feature. The
|
|
||||||
... after sizeof returns number of arguments:</P>
|
|
||||||
<PRE>template<typename ...Args> struct SomeStruct {
|
|
||||||
static const int size = sizeof...(Args);
|
|
||||||
}
|
|
||||||
// SomeStruct<Type1, Type2>::size is 2 and SomeStruct<>::size is 0</PRE><P>
|
|
||||||
Done: Added syntax support for 'typename' or 'class' + ... + id.
|
|
||||||
Added testcase cpp11_variadic_templates. R11458</P>
|
|
||||||
<P>Done: Added syntax support for BaseClass + ..., type + ... + id in
|
|
||||||
parameters and baseclass + ... for intializers after constructor.
|
|
||||||
Extended Swig syntax to support sizeof...(Args). R11467</P>
|
|
||||||
<P>Done: Fixed %template to support variadic number of templates.</P>
|
|
||||||
<P>TODO: Only (if present) first variadically defined argument is
|
|
||||||
currently used in %template directive. The next ones are ignored.</P>
|
|
||||||
<H2>New string literals [partially done]</H2>
|
|
||||||
<P>Beside the implementation, the new C++11 Unicode and custom
|
|
||||||
delimeter constants can occur in templates in the header file.
|
|
||||||
</P>
|
|
||||||
<P>Done: Added symbols 'u', 'u8' and 'U' to mark the beginning of the
|
|
||||||
UTF string. Also added test case cpp11_raw_string_literals. R11327</P>
|
|
||||||
<P>Done: Added R"DELIMITER[, ]DELIMITER" for a custom
|
|
||||||
delimiter for the beginning/end of the string. R11328</P>
|
|
||||||
<P>TODO: Fix the Swig's C++ preprocessor bug when parsing an odd
|
|
||||||
number of “ inside the string brackets. See
|
|
||||||
Source/Preprocessor/cpp.c.</P>
|
|
||||||
<H2>User-defined literals [partially done]</H2>
|
|
||||||
<P>C++ has different suffix literals. eg. 12.5f marks the number 12.5
|
|
||||||
as float.
|
|
||||||
</P>
|
|
||||||
<P>C++11 allows user to define his own suffix for the strings always
|
|
||||||
starting with the underscore (_). eg. int a = "hello"_mySuffix;
|
|
||||||
</P>
|
|
||||||
<P>The syntax is similar to other operator overloading functions:
|
|
||||||
</P>
|
|
||||||
<PRE STYLE="margin-bottom: 0.5cm"> OutputType operator "" _mySuffix(const char * string_values);</PRE><P>
|
|
||||||
The null terminated const char* is the string between the "".
|
|
||||||
The _mySuffix is the name of the suffix operator. And the OutputType
|
|
||||||
is the outputType the operator returns.
|
|
||||||
</P>
|
|
||||||
<P>Other forms are:
|
|
||||||
</P>
|
|
||||||
<PRE> OutputType operator "" _mySuffix(const char * string_values, size_t num_chars);
|
|
||||||
OutputType operator "" _mySuffix(const wchar_t * string_values, size_t num_chars);
|
|
||||||
OutputType operator "" _mySuffix(const char16_t * string_values, size_t num_chars);
|
|
||||||
OutputType operator "" _mySuffix(const char32_t * string_values, size_t num_chars);
|
|
||||||
OutputType operator "" _mySuffix(int value); /* cooked version - ie. atoi() of string */</PRE><P>
|
|
||||||
Another possibility is to use variadic templates:
|
|
||||||
</P>
|
|
||||||
<PRE> template<char...> OutputType operator "" _mySuffix();
|
|
||||||
OutputType someVariable = "1234"_mySuffix;</PRE><P>
|
|
||||||
This instantiates the literal processing function as
|
|
||||||
operator""_Suffix<'1', '2', '3', '4'>. In this form,
|
|
||||||
there is no terminating null character to the string. The main
|
|
||||||
purpose to doing this is to use C++11's constexpr keyword and the
|
|
||||||
compiler to allow the literal to be transformed entirely at compile
|
|
||||||
time, assuming OutputType is a constexpr-constructable and copyable
|
|
||||||
type, and the literal processing function is a constexpr function.</P>
|
|
||||||
<P>Article:
|
|
||||||
<A HREF="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2765.pdf">http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2765.pdf</A></P>
|
|
||||||
<P>Done: Added syntax support for userdefined literals. Added
|
|
||||||
testcase cpp11_userdefined_literals.i. R11494</P>
|
|
||||||
<P>TODO: %rename doesn't parse operator”” yet.</P>
|
|
||||||
<H2>Thread-local storage [done]
|
|
||||||
</H2>
|
|
||||||
<P>New C++11 introduces keyword "thread_local" which marks
|
|
||||||
the following variable dynamically located depending on the current
|
|
||||||
thread when using the address-of (&) operator.
|
|
||||||
</P>
|
|
||||||
<P>Syntax:
|
|
||||||
</P>
|
|
||||||
<PRE> struct A {
|
|
||||||
thread_local int val;
|
|
||||||
};</PRE><P>
|
|
||||||
Done: Add "thread_local" keyword to Swig. Added testcase
|
|
||||||
cpp11_thread_local. R11393</P>
|
|
||||||
<H2>Defaulting/deleting of standard functions on C++ objects [done]</H2>
|
|
||||||
<P>C++ automatically creates default constructor with empty
|
|
||||||
parameters, copy constructor, operator= and destructor for any class.
|
|
||||||
Sometimes user wants to explicitly remove one of them or enable them
|
|
||||||
(eg. default constructor with empty parameters doesn't work any more,
|
|
||||||
if any other constructor is defined).
|
|
||||||
</P>
|
|
||||||
<P>Words "default" and "delete" are introduced.
|
|
||||||
The syntax is similar to declaration of pure virtual function:
|
|
||||||
</P>
|
|
||||||
<PRE> struct NonCopyable {
|
|
||||||
NonCopyable & operator=(const NonCopyable&) = delete; /* Removes operator= */
|
|
||||||
NonCopyable(const NonCopyable&) = delete; /* Removed copy constructor */
|
|
||||||
NonCopyable() = default; /* Explicitly allows the empty constructor */
|
|
||||||
void *operator new(std::size_t) = delete; /* Removes new NonCopyable */
|
|
||||||
};</PRE><P>
|
|
||||||
User has the ability by using keyword delete to disallow calling of
|
|
||||||
the standard functions brought by C++ itself.
|
|
||||||
</P>
|
|
||||||
<PRE> struct A1 {
|
|
||||||
void f(int i);
|
|
||||||
void f(double i) = delete; /* Don't cast double to int. Compiler returns an error */
|
|
||||||
};
|
|
||||||
struct A2 {
|
|
||||||
void f(int i);
|
|
||||||
template<class T> void f(T) = delete; /* Only accept int */
|
|
||||||
};</PRE><P>
|
|
||||||
Ignored: Swig already parses the keywords "= delete" and "=
|
|
||||||
default". These keywords are used for built-in functions (copy
|
|
||||||
constructor, operator= etc.), which are ignored by Swig anyway.</P>
|
|
||||||
<P>Done: Added testcase cpp11_default_delete. R11535</P>
|
|
||||||
<H2>Type long long int [done]</H2>
|
|
||||||
<P>Type long long int is an integer type that has at least 64 useful
|
|
||||||
bits. C99 added it to its standard, but the C++ didn't adopt it until
|
|
||||||
C++11. Most C++ compilers supported it though.
|
|
||||||
</P>
|
|
||||||
<P>Done: Swig already parses the C code including the long long type.
|
|
||||||
</P>
|
|
||||||
<H2>Static assertions [done]</H2>
|
|
||||||
<P>static_assert() can be used at class scope as well eg.:
|
|
||||||
</P>
|
|
||||||
<PRE> template <typename T>
|
|
||||||
struct Check {
|
|
||||||
static_assert(sizeof(int) <= sizeof(T), "not big enough");
|
|
||||||
};</PRE><P>
|
|
||||||
Done: Added syntax support for "static_assert()". Added
|
|
||||||
test case cpp11_static_assert. R11369</P>
|
|
||||||
<H2>Allow sizeof to work on members of classes without an explicit
|
|
||||||
object [done]</H2>
|
|
||||||
<P>C++11 allows calls of sizeof to concrete objects as well:
|
|
||||||
</P>
|
|
||||||
<PRE> struct A { int member; };
|
|
||||||
sizeof(A::member); //Does not work with C++03. Okay with C++11</PRE><P>
|
|
||||||
This kind of syntax is already supported by Swig.</P>
|
|
||||||
<P>Done: Added testcase cpp11_sizeof_objects. R11538
|
|
||||||
</P>
|
|
||||||
<H2>Threading facilities [ignored]</H2>
|
|
||||||
<P>C++11 will add the following classes to the standard library:
|
|
||||||
</P>
|
|
||||||
<PRE> * std::thread
|
|
||||||
* std::mutex, std::recursive_mutex
|
|
||||||
* std::condition_variable, std::condition_variable_any
|
|
||||||
* std::lock_guard, std::unique_lock
|
|
||||||
* std::packaged_task</PRE><P>
|
|
||||||
Ignored: No changes to the language itself is made.
|
|
||||||
</P>
|
|
||||||
<H2>Tuple types [TODO]</H2>
|
|
||||||
<P>Tuple is array of various types. C++11 introduced this feature
|
|
||||||
using variadic templates. Tuple is defined as:</P>
|
|
||||||
<PRE STYLE="margin-bottom: 0.5cm">template <class ...Types> class tuple;</PRE><P>
|
|
||||||
Constructor is automatically generated filling the tuple elements.
|
|
||||||
get<X> function is introduced to get the Xth element in the
|
|
||||||
tuple.</P>
|
|
||||||
<PRE>typedef tuple< int, double, long &, const char * > test_tuple ;
|
|
||||||
long lengthy = 12 ;
|
|
||||||
test_tuple proof( 18, 6.5, lengthy, "Ciao!" ) ;
|
|
||||||
lengthy = get<0>(proof) ; // Assign to 'lengthy' the value 18.
|
|
||||||
get<3>(proof) = " Beautiful!" ; // Modify the tuple’s fourth element.</PRE><P>
|
|
||||||
Tuples can be copied to each other, if all the elements are copiable:</P>
|
|
||||||
<PRE>typedef tuple< int , double, string > tuple_1 t1 ;
|
|
||||||
typedef tuple< char, short , const char * > tuple_2 t2( 'X', 2, "Hola!" ) ;
|
|
||||||
t1 = t2 ; // Ok, first two elements can be converted,
|
|
||||||
// the third one can be constructed from a 'const char *'.</PRE><P>
|
|
||||||
TODO: Implement wrappers for the tuplet<> class.</P>
|
|
||||||
<H2>Hash tables [TODO]</H2>
|
|
||||||
<P>C++11 introduces the "unordered" version of existing
|
|
||||||
types, which in practice work faster than the linear types:
|
|
||||||
</P>
|
|
||||||
<PRE> - unordered set
|
|
||||||
- unordered multiset
|
|
||||||
- unordered map
|
|
||||||
- unordered multimap</PRE><P>
|
|
||||||
Swig should use the "unordered" types exactly the same as
|
|
||||||
the original linear types.</P>
|
|
||||||
<P>Problem: Unordered types do not contain exactly same members as
|
|
||||||
ordered ones (eg. _Hashtable_iterator does not offer operator--() and
|
|
||||||
constructor with compare function which is required). So simply
|
|
||||||
aliasing unordered classes to ordered ones doesn't work.</P>
|
|
||||||
<P>TODO: Implement wrappers for unordered_ types. Initial work is
|
|
||||||
already done in Lib/std/unordered_*.i files.</P>
|
|
||||||
<H2>Regular expressions [ignored]</H2>
|
|
||||||
<P>Two new classes are introduced in C++11: basic_regex and
|
|
||||||
match_results. Both are defined in regex header file.
|
|
||||||
</P>
|
|
||||||
<P>Ignored: The new feature extends the standardy library only. No
|
|
||||||
changes to Swig needed.
|
|
||||||
</P>
|
|
||||||
<H2>General-purpose smart pointers [done]</H2>
|
|
||||||
<P>This feature deprecates auto_ptr and adds shared_ptr, weak_ptr and
|
|
||||||
unique_ptr to the standard library.
|
|
||||||
</P>
|
|
||||||
<P>This feature only adds the smart pointers to the standard library
|
|
||||||
and doesn't effect the C++ syntax.</P>
|
|
||||||
<P>Done: Added test case which uses all three smart pointers in the
|
|
||||||
class. R11394</P>
|
|
||||||
<P>Problem: GCC standard library doesn't contain the new smart
|
|
||||||
pointers yet.
|
|
||||||
</P>
|
|
||||||
<H2>Extensible random number facility [ignored]</H2>
|
|
||||||
<P>This feature standardize the pseudo random number algorithm
|
|
||||||
(currently, the random number generator was dependent on the
|
|
||||||
platform/compiler). It adds functions linear_congruential,
|
|
||||||
subtract_with_carry and mersenne_twister and symbols
|
|
||||||
uniform_int_distribution, bernoulli_distribution,
|
|
||||||
geometric_distribution, poisson_distribution, binomial_distribution,
|
|
||||||
uniform_real_distribution, exponential_distribution,
|
|
||||||
normal_distribution and gamma_distribution to the standard library.
|
|
||||||
</P>
|
|
||||||
<P>Ignored: The new feature extends the standardy library only. No
|
|
||||||
changes to Swig needed.
|
|
||||||
</P>
|
|
||||||
<H2>Wrapper reference [ignored]</H2>
|
|
||||||
<P>This feature adds ref and cref classes to the standard library
|
|
||||||
(#include <utility>) usually used in tempalte functions.
|
|
||||||
</P>
|
|
||||||
<P>Ignored: The new feature extends the standardy library only. No
|
|
||||||
changes to Swig needed.
|
|
||||||
</P>
|
|
||||||
<H2>Polymorphous wrappers for function objects [done]</H2>
|
|
||||||
<P>Two features are introduced:
|
|
||||||
</P>
|
|
||||||
<UL>
|
|
||||||
<LI><P>The function template wrapper:
|
|
||||||
</P>
|
|
||||||
</UL>
|
|
||||||
<PRE STYLE="margin-bottom: 0.5cm"> function<int ( int, int )> pF;</PRE>
|
|
||||||
<UL>
|
|
||||||
<LI><P>and the function object:
|
|
||||||
</P>
|
|
||||||
</UL>
|
|
||||||
<PRE> struct Test {
|
|
||||||
bool operator()( short x, short y );
|
|
||||||
};</PRE><P>
|
|
||||||
Swig already supports the two.</P>
|
|
||||||
<P>Done: Added a runtime testcase for function objects
|
|
||||||
cpp11_function_objects. R11419.</P>
|
|
||||||
<H2>Type traits for metaprogramming [ignored]</H2>
|
|
||||||
<P>C++11 adds a new header file <type_traits> which includes
|
|
||||||
helper functions to determine the template type while initializing
|
|
||||||
the object at compile time.
|
|
||||||
</P>
|
|
||||||
<P>Swig already supports the following code:
|
|
||||||
</P>
|
|
||||||
<PRE> template< int B, int N >
|
|
||||||
struct Pow {
|
|
||||||
// recursive call and recombination.
|
|
||||||
enum{ value = B*Pow< B, N-1 >::value };
|
|
||||||
};
|
|
||||||
template< int B > struct Pow< B, 0 > // <EM>N == 0</EM> condition of termination.
|
|
||||||
{
|
|
||||||
enum{ value = 1 };
|
|
||||||
};
|
|
||||||
int quartic_of_three = Pow< 3, 4 >::value ;</PRE><P>
|
|
||||||
Functions is_convertible, is_integral, is_integral_const etc. are
|
|
||||||
part of the new header:
|
|
||||||
</P>
|
|
||||||
<PRE>// First way of operating.
|
|
||||||
template< bool B > struct algorithm {
|
|
||||||
template< class T1, class T2 > int do_it( T1 &, T2 & ) { /*...*/ }
|
|
||||||
};
|
|
||||||
// Second way of operating.
|
|
||||||
template<> struct algorithm<true> {
|
|
||||||
template< class T1, class T2 > int do_it( T1, T2 ) { /*...*/ }
|
|
||||||
};
|
|
||||||
// Instantiating 'elaborate' will automatically instantiate the correct way to operate.
|
|
||||||
template< class T1, class T2 > int elaborate( T1 A, T2 B ) {
|
|
||||||
// Use the second way only if 'T1' is an integer and if 'T2' is
|
|
||||||
// in floating point, otherwise use the first way.
|
|
||||||
return algorithm< is_integral<T1>::value && is_floating_point<T2>::value >::do_it( A, B );
|
|
||||||
}</PRE><P>
|
|
||||||
Swig correctly parses the syntax for template<bool>,
|
|
||||||
template<class T> and template<>.
|
|
||||||
</P>
|
|
||||||
<P>Ignored: Swig requires explicitly defined template class
|
|
||||||
(%template directive) to export it to the target language.</P>
|
|
||||||
<H2>Uniform method for computing return type of function objects
|
|
||||||
[partially done]</H2>
|
|
||||||
<P>The template function is introduced: std::result_of() which
|
|
||||||
depends on decltype:
|
|
||||||
</P>
|
|
||||||
<PRE>template< class Obj >
|
|
||||||
class calculus_ver2 {
|
|
||||||
public:
|
|
||||||
template< class Arg >
|
|
||||||
typename std::result_of<Obj(Arg)>::type operator()( Arg& a ) const {
|
|
||||||
return member(a);
|
|
||||||
}
|
|
||||||
private:
|
|
||||||
Obj member;
|
|
||||||
};</PRE><P>
|
|
||||||
Swig correctly parses the result_of class.</P>
|
|
||||||
<P>TODO: The return type (the result_of::type member) is not
|
|
||||||
calculated by Swig. This needs a much more complex semantic parser.</P>
|
|
||||||
<P>Done: Added testcase cpp11_result_of. R11534</P>
|
|
||||||
</BODY>
|
|
||||||
</HTML>
|
|
||||||
|
|
@ -622,20 +622,15 @@ which is equivalent to the old style typedef:
|
||||||
typedef void (*PFD)(double); // The old style
|
typedef void (*PFD)(double); // The old style
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<p>
|
|
||||||
SWIG supports type aliasing.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
The following is an example of an alias template:
|
The following is an example of an alias template:
|
||||||
|
|
||||||
<div class="code"><pre>
|
<div class="code"><pre>
|
||||||
template< typename T1, typename T2, int >
|
template< typename T1, typename T2, int N >
|
||||||
class SomeType {
|
class SomeType {
|
||||||
public:
|
public:
|
||||||
T1 a;
|
T1 a;
|
||||||
T2 b;
|
T2 b;
|
||||||
int c;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template< typename T2 >
|
template< typename T2 >
|
||||||
|
|
@ -643,14 +638,19 @@ using TypedefName = SomeType<char*, T2, 5>;
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
These are partially supported as SWIG will parse these and identify them, however, they are ignored as they are not added to the type system. A warning such as the following is issued:
|
SWIG supports both type aliasing and alias templates.
|
||||||
|
However, in order to use an alias template, two <tt>%template</tt> directives must be used:
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<div class="shell">
|
<div class="code"><pre>
|
||||||
<pre>
|
%template(SomeTypeBool) SomeType<char*, bool, 5>;
|
||||||
example.i:13: Warning 342: The 'using' keyword in template aliasing is not fully supported yet.
|
%template() TypedefName<bool>;
|
||||||
</pre>
|
</pre></div>
|
||||||
</div>
|
|
||||||
|
<p>Firstly, the actual template is instantiated with a name to be used by the target language, as per any template being wrapped.
|
||||||
|
Secondly, the empty template instantiation, <tt>%template()</tt>, is required for the alias template.
|
||||||
|
This second requirement is necessary to add the appropriate instantiated template type into the type system as SWIG does not automatically instantiate templates.
|
||||||
|
See the <a href="SWIGPlus.html#SWIGPlus_nn30">Templates</a> section for more general information on wrapping templates.
|
||||||
|
|
||||||
<H3><a name="CPlusPlus11_unrestricted_unions">7.2.17 Unrestricted unions</a></H3>
|
<H3><a name="CPlusPlus11_unrestricted_unions">7.2.17 Unrestricted unions</a></H3>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -544,12 +544,16 @@ unless the imclassname attribute is specified in the <a href="CSharp.html#CSharp
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
The directory <tt>Examples/csharp</tt> has a number of simple examples.
|
The directory <tt>Examples/csharp</tt> has a number of simple examples.
|
||||||
Visual Studio .NET 2003 solution and project files are available for compiling with the Microsoft .NET C# compiler on Windows.
|
Visual Studio .NET 2003 solution and project files are available for compiling with the Microsoft .NET C#
|
||||||
If your SWIG installation went well on a Unix environment and your C# compiler was detected, you should be able to type <tt>make</tt> in each example directory,
|
compiler on Windows. This also works with newer versions of Visual Studio if you allow
|
||||||
then <tt>ilrun runme.exe</tt> (Portable.NET C# compiler) or <tt>mono runme.exe</tt> (Mono C# compiler) to run the examples.
|
it to convert the solution to the latest version.
|
||||||
|
If your SWIG installation went well on a Unix environment and your C# compiler was detected, you should be able to type <tt>make</tt> in each example directory.
|
||||||
|
After SWIG has run and both the C# and C/C++ compilers have finished building,
|
||||||
|
the examples will be run, by either running <tt>runme.exe</tt> or by running
|
||||||
|
<tt>mono runme.exe</tt> (Mono C# compiler).
|
||||||
Windows users can also get the examples working using a
|
Windows users can also get the examples working using a
|
||||||
<a href="http://www.cygwin.com">Cygwin</a> or <a href="http://www.mingw.org">MinGW</a> environment for automatic configuration of the example makefiles.
|
<a href="http://www.cygwin.com">Cygwin</a> or <a href="http://www.mingw.org">MinGW</a> environment for automatic configuration of the example makefiles.
|
||||||
Any one of the three C# compilers (Portable.NET, Mono or Microsoft) can be detected from within a Cygwin or Mingw environment if installed in your path.
|
Any one of the C# compilers (Mono or Microsoft) can be detected from within a Cygwin or Mingw environment if installed in your path.
|
||||||
|
|
||||||
<H2><a name="CSharp_void_pointers">20.3 Void pointers</a></H2>
|
<H2><a name="CSharp_void_pointers">20.3 Void pointers</a></H2>
|
||||||
|
|
||||||
|
|
@ -1590,8 +1594,8 @@ public class Base : global::System.IDisposable {
|
||||||
BaseBoolMethod(new Base(b, false), flag);
|
BaseBoolMethod(new Base(b, false), flag);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal delegate uint SwigDelegateBase_0(uint x);
|
public delegate uint SwigDelegateBase_0(uint x);
|
||||||
internal delegate void SwigDelegateBase_1(global::System.IntPtr b, bool flag);
|
public delegate void SwigDelegateBase_1(global::System.IntPtr b, bool flag);
|
||||||
|
|
||||||
private SwigDelegateBase_0 swigDelegate0;
|
private SwigDelegateBase_0 swigDelegate0;
|
||||||
private SwigDelegateBase_1 swigDelegate1;
|
private SwigDelegateBase_1 swigDelegate1;
|
||||||
|
|
@ -1691,6 +1695,31 @@ void SwigDirector_Base::BaseBoolMethod(Base const &b, bool flag) {
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
The delegates from the above example are <tt>public</tt> by default:
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div class="code">
|
||||||
|
<pre>
|
||||||
|
public delegate uint SwigDelegateBase_0(uint x);
|
||||||
|
public delegate void SwigDelegateBase_1(global::System.IntPtr b, bool flag);
|
||||||
|
</pre>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
These can be changed if desired via the <tt>csdirectordelegatemodifiers</tt>
|
||||||
|
<a href="Customization.html#Customization_features">%feature directive</a>.
|
||||||
|
For example, using <tt>%feature("csdirectordelegatemodifiers") "internal"</tt>
|
||||||
|
before SWIG parses the Base class will change all the delegates to <tt>internal</tt>:
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div class="code">
|
||||||
|
<pre>
|
||||||
|
internal delegate uint SwigDelegateBase_0(uint x);
|
||||||
|
internal delegate void SwigDelegateBase_1(global::System.IntPtr b, bool flag);
|
||||||
|
</pre>
|
||||||
|
</div>
|
||||||
|
|
||||||
<H3><a name="CSharp_director_caveats">20.6.3 Director caveats</a></H3>
|
<H3><a name="CSharp_director_caveats">20.6.3 Director caveats</a></H3>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -295,9 +295,9 @@
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
The author of TinyCLOS, Gregor Kiczales, describes TinyCLOS as:
|
The author of TinyCLOS, Gregor Kiczales, describes TinyCLOS as:
|
||||||
"Tiny CLOS is a Scheme implementation of a `kernelized' CLOS, with a
|
"Tiny CLOS is a Scheme implementation of a 'kernelized' CLOS, with a
|
||||||
metaobject protocol. The implementation is even simpler than
|
metaobject protocol. The implementation is even simpler than
|
||||||
the simple CLOS found in `The Art of the Metaobject Protocol,'
|
the simple CLOS found in 'The Art of the Metaobject Protocol',
|
||||||
weighing in at around 850 lines of code, including (some)
|
weighing in at around 850 lines of code, including (some)
|
||||||
comments and documentation."
|
comments and documentation."
|
||||||
</p>
|
</p>
|
||||||
|
|
|
||||||
|
|
@ -908,13 +908,14 @@
|
||||||
<li><a href="Guile.html#Guile_nn14">Smobs</a>
|
<li><a href="Guile.html#Guile_nn14">Smobs</a>
|
||||||
<li><a href="Guile.html#Guile_nn15">Garbage Collection</a>
|
<li><a href="Guile.html#Guile_nn15">Garbage Collection</a>
|
||||||
</ul>
|
</ul>
|
||||||
<li><a href="Guile.html#Guile_nn16">Exception Handling</a>
|
<li><a href="Guile.html#Guile_nn16">Native Guile pointers</a>
|
||||||
<li><a href="Guile.html#Guile_nn17">Procedure documentation</a>
|
<li><a href="Guile.html#Guile_nn17">Exception Handling</a>
|
||||||
<li><a href="Guile.html#Guile_nn18">Procedures with setters</a>
|
<li><a href="Guile.html#Guile_nn18">Procedure documentation</a>
|
||||||
<li><a href="Guile.html#Guile_nn19">GOOPS Proxy Classes</a>
|
<li><a href="Guile.html#Guile_nn19">Procedures with setters</a>
|
||||||
|
<li><a href="Guile.html#Guile_nn20">GOOPS Proxy Classes</a>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="Guile.html#Guile_nn20">Naming Issues</a>
|
<li><a href="Guile.html#Guile_nn21">Naming Issues</a>
|
||||||
<li><a href="Guile.html#Guile_nn21">Linking</a>
|
<li><a href="Guile.html#Guile_nn22">Linking</a>
|
||||||
</ul>
|
</ul>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -1015,6 +1016,7 @@
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="Java.html#Java_helper_functions">C/C++ helper functions</a>
|
<li><a href="Java.html#Java_helper_functions">C/C++ helper functions</a>
|
||||||
<li><a href="Java.html#Java_class_extension">Class extension with %extend</a>
|
<li><a href="Java.html#Java_class_extension">Class extension with %extend</a>
|
||||||
|
<li><a href="Java.html#Java_proxycode">Class extension with %proxycode</a>
|
||||||
<li><a href="Java.html#Java_exception_handling">Exception handling with %exception and %javaexception</a>
|
<li><a href="Java.html#Java_exception_handling">Exception handling with %exception and %javaexception</a>
|
||||||
<li><a href="Java.html#Java_method_access">Method access with %javamethodmodifiers</a>
|
<li><a href="Java.html#Java_method_access">Method access with %javamethodmodifiers</a>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
|
||||||
|
|
@ -174,6 +174,9 @@
|
||||||
|
|
||||||
<p><a name="D_class_code_typemaps"></a><tt>dconstructor</tt>, <tt>ddestructor</tt>, <tt>ddispose</tt> and <tt>ddispose_derived</tt> are used to generate the class constructor, destructor and <tt>dispose()</tt> method, respectively. The auxiliary code for handling the pointer to the C++ object is stored in <tt>dbody</tt> and <tt>dbody_derived</tt>. You can override them for specific types.</p>
|
<p><a name="D_class_code_typemaps"></a><tt>dconstructor</tt>, <tt>ddestructor</tt>, <tt>ddispose</tt> and <tt>ddispose_derived</tt> are used to generate the class constructor, destructor and <tt>dispose()</tt> method, respectively. The auxiliary code for handling the pointer to the C++ object is stored in <tt>dbody</tt> and <tt>dbody_derived</tt>. You can override them for specific types.</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Code can also be injected into the D proxy class using <tt>%proxycode</tt>.
|
||||||
|
</p>
|
||||||
|
|
||||||
<H3><a name="D_special_variables">22.3.7 Special variable macros</a></H3>
|
<H3><a name="D_special_variables">22.3.7 Special variable macros</a></H3>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2537,7 +2537,7 @@ also return a pointer to the base class (<tt>Language</tt>) so that only the int
|
||||||
Save the code for your language module in a file named "<tt>python.cxx</tt>" and
|
Save the code for your language module in a file named "<tt>python.cxx</tt>" and
|
||||||
place this file in the <tt>Source/Modules</tt> directory of the SWIG distribution.
|
place this file in the <tt>Source/Modules</tt> directory of the SWIG distribution.
|
||||||
To ensure that your module is compiled into SWIG along with the other language modules,
|
To ensure that your module is compiled into SWIG along with the other language modules,
|
||||||
modify the file <tt>Source/Modules/Makefile.am</tt> to include the additional source
|
modify the file <tt>Source/Makefile.am</tt> to include the additional source
|
||||||
files. In addition, modify the file <tt>Source/Modules/swigmain.cxx</tt>
|
files. In addition, modify the file <tt>Source/Modules/swigmain.cxx</tt>
|
||||||
with an additional command line option that activates the module. Read the source---it's straightforward.
|
with an additional command line option that activates the module. Read the source---it's straightforward.
|
||||||
</p>
|
</p>
|
||||||
|
|
|
||||||
|
|
@ -30,13 +30,14 @@
|
||||||
<li><a href="#Guile_nn14">Smobs</a>
|
<li><a href="#Guile_nn14">Smobs</a>
|
||||||
<li><a href="#Guile_nn15">Garbage Collection</a>
|
<li><a href="#Guile_nn15">Garbage Collection</a>
|
||||||
</ul>
|
</ul>
|
||||||
<li><a href="#Guile_nn16">Exception Handling</a>
|
<li><a href="#Guile_nn16">Native Guile pointers</a>
|
||||||
<li><a href="#Guile_nn17">Procedure documentation</a>
|
<li><a href="#Guile_nn17">Exception Handling</a>
|
||||||
<li><a href="#Guile_nn18">Procedures with setters</a>
|
<li><a href="#Guile_nn18">Procedure documentation</a>
|
||||||
<li><a href="#Guile_nn19">GOOPS Proxy Classes</a>
|
<li><a href="#Guile_nn19">Procedures with setters</a>
|
||||||
|
<li><a href="#Guile_nn20">GOOPS Proxy Classes</a>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="#Guile_nn20">Naming Issues</a>
|
<li><a href="#Guile_nn21">Naming Issues</a>
|
||||||
<li><a href="#Guile_nn21">Linking</a>
|
<li><a href="#Guile_nn22">Linking</a>
|
||||||
</ul>
|
</ul>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -453,7 +454,14 @@ is exactly like described in <a href="Customization.html#Customization_ownership
|
||||||
Object ownership and %newobject</a> in the SWIG manual. All typemaps use an $owner var, and
|
Object ownership and %newobject</a> in the SWIG manual. All typemaps use an $owner var, and
|
||||||
the guile module replaces $owner with 0 or 1 depending on feature:new.</p>
|
the guile module replaces $owner with 0 or 1 depending on feature:new.</p>
|
||||||
|
|
||||||
<H2><a name="Guile_nn16">24.8 Exception Handling</a></H2>
|
<H2><a name="Guile_nn16">24.8 Native Guile pointers</a></H2>
|
||||||
|
|
||||||
|
|
||||||
|
<p>
|
||||||
|
In addition to SWIG smob pointers, <a href="https://www.gnu.org/software/guile/manual/html_node/Foreign-Pointers.html">Guile's native pointer type</a> are accepted as arguments to wrapped SWIG functions. This can be useful for passing <a href="https://www.gnu.org/software/guile/manual/html_node/Void-Pointers-and-Byte-Access.html#">pointers to bytevector data</a> to wrapped functions.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<H2><a name="Guile_nn17">24.9 Exception Handling</a></H2>
|
||||||
|
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
|
|
@ -479,7 +487,7 @@ mapping:
|
||||||
The default when not specified here is to use "swig-error".
|
The default when not specified here is to use "swig-error".
|
||||||
See Lib/exception.i for details.
|
See Lib/exception.i for details.
|
||||||
|
|
||||||
<H2><a name="Guile_nn17">24.9 Procedure documentation</a></H2>
|
<H2><a name="Guile_nn18">24.10 Procedure documentation</a></H2>
|
||||||
|
|
||||||
|
|
||||||
<p>If invoked with the command-line option <code>-procdoc
|
<p>If invoked with the command-line option <code>-procdoc
|
||||||
|
|
@ -514,7 +522,7 @@ like this:
|
||||||
typemap argument <code>doc</code>. See <code>Lib/guile/typemaps.i</code> for
|
typemap argument <code>doc</code>. See <code>Lib/guile/typemaps.i</code> for
|
||||||
details.
|
details.
|
||||||
|
|
||||||
<H2><a name="Guile_nn18">24.10 Procedures with setters</a></H2>
|
<H2><a name="Guile_nn19">24.11 Procedures with setters</a></H2>
|
||||||
|
|
||||||
|
|
||||||
<p>For global variables, SWIG creates a single wrapper procedure
|
<p>For global variables, SWIG creates a single wrapper procedure
|
||||||
|
|
@ -542,7 +550,7 @@ struct members, the procedures <code>(<var>struct</var>-<var>member</var>-get
|
||||||
pointer)</code> and <code>(<var>struct-member</var>-set pointer
|
pointer)</code> and <code>(<var>struct-member</var>-set pointer
|
||||||
value)</code> are <em>not</em> generated.
|
value)</code> are <em>not</em> generated.
|
||||||
|
|
||||||
<H2><a name="Guile_nn19">24.11 GOOPS Proxy Classes</a></H2>
|
<H2><a name="Guile_nn20">24.12 GOOPS Proxy Classes</a></H2>
|
||||||
|
|
||||||
|
|
||||||
<p>SWIG can also generate classes and generic functions for use with
|
<p>SWIG can also generate classes and generic functions for use with
|
||||||
|
|
@ -688,7 +696,7 @@ Notice that <Foo> is used before it is defined. The fix is to just put th
|
||||||
<code>%import "foo.h"</code> before the <code>%inline</code> block.
|
<code>%import "foo.h"</code> before the <code>%inline</code> block.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<H3><a name="Guile_nn20">24.11.1 Naming Issues</a></H3>
|
<H3><a name="Guile_nn21">24.12.1 Naming Issues</a></H3>
|
||||||
|
|
||||||
|
|
||||||
<p>As you can see in the example above, there are potential naming conflicts. The default exported
|
<p>As you can see in the example above, there are potential naming conflicts. The default exported
|
||||||
|
|
@ -725,7 +733,7 @@ guile-modules. For example,</p>
|
||||||
(use-modules ((Test) #:renamer (symbol-prefix-proc 'goops:)))
|
(use-modules ((Test) #:renamer (symbol-prefix-proc 'goops:)))
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<H3><a name="Guile_nn21">24.11.2 Linking</a></H3>
|
<H3><a name="Guile_nn22">24.12.2 Linking</a></H3>
|
||||||
|
|
||||||
|
|
||||||
<p>The guile-modules generated above all need to be linked together. GOOPS support requires
|
<p>The guile-modules generated above all need to be linked together. GOOPS support requires
|
||||||
|
|
|
||||||
|
|
@ -100,6 +100,7 @@
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="#Java_helper_functions">C/C++ helper functions</a>
|
<li><a href="#Java_helper_functions">C/C++ helper functions</a>
|
||||||
<li><a href="#Java_class_extension">Class extension with %extend</a>
|
<li><a href="#Java_class_extension">Class extension with %extend</a>
|
||||||
|
<li><a href="#Java_proxycode">Class extension with %proxycode</a>
|
||||||
<li><a href="#Java_exception_handling">Exception handling with %exception and %javaexception</a>
|
<li><a href="#Java_exception_handling">Exception handling with %exception and %javaexception</a>
|
||||||
<li><a href="#Java_method_access">Method access with %javamethodmodifiers</a>
|
<li><a href="#Java_method_access">Method access with %javamethodmodifiers</a>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
@ -281,7 +282,7 @@ compiling and using the generated files.
|
||||||
|
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
The following table list the additional commandline options available for the Java module. They can also be seen by using:
|
The following table lists the additional commandline options available for the Java module. They can also be seen by using:
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<div class="code"><pre>
|
<div class="code"><pre>
|
||||||
|
|
@ -349,7 +350,7 @@ However, SWIG tries to guess the right options when it is installed. Therefore,
|
||||||
you may want to start with one of the examples in the <tt>Examples/java</tt>
|
you may want to start with one of the examples in the <tt>Examples/java</tt>
|
||||||
directory. If that doesn't work, you will need to read the man-pages for
|
directory. If that doesn't work, you will need to read the man-pages for
|
||||||
your compiler and linker to get the right set of options. You might also
|
your compiler and linker to get the right set of options. You might also
|
||||||
check the <a href="http://www.dabeaz.com/cgi-bin/wiki.pl">SWIG Wiki</a> for
|
check the <a href="https://github.com/swig/swig/wiki">SWIG Wiki</a> for
|
||||||
additional information.
|
additional information.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
|
@ -481,7 +482,7 @@ One last piece of advice is to beware of the common faux pas of having more than
|
||||||
In summary, ensure that you are using the correct C/C++ compiler and linker combination and options for successful native library loading.
|
In summary, ensure that you are using the correct C/C++ compiler and linker combination and options for successful native library loading.
|
||||||
If you are using the examples that ship with SWIG, then the Examples/Makefile must have these set up correctly for your system.
|
If you are using the examples that ship with SWIG, then the Examples/Makefile must have these set up correctly for your system.
|
||||||
The SWIG installation package makes a best attempt at getting these correct but does not get it right 100% of the time.
|
The SWIG installation package makes a best attempt at getting these correct but does not get it right 100% of the time.
|
||||||
The <a href="http://www.dabeaz.com/cgi-bin/wiki.pl">SWIG Wiki</a> also has some settings for commonly used compiler and operating system combinations.
|
The <a href="https://github.com/swig/swig/wiki">SWIG Wiki</a> also has some settings for commonly used compiler and operating system combinations.
|
||||||
The following section also contains some C++ specific linking problems and solutions.
|
The following section also contains some C++ specific linking problems and solutions.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
|
@ -4363,7 +4364,144 @@ Vector(2,3,4)
|
||||||
in any way---the extensions only show up in the Java interface.
|
in any way---the extensions only show up in the Java interface.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<H3><a name="Java_exception_handling">25.7.3 Exception handling with %exception and %javaexception</a></H3>
|
<H3><a name="Java_proxycode">25.7.3 Class extension with %proxycode</a></H3>
|
||||||
|
|
||||||
|
|
||||||
|
<p>
|
||||||
|
The previous section described how to extend a wrapped class with C or C++ code.
|
||||||
|
This section describes how to extend a wrapped class with Java code instead of C/C++ code.
|
||||||
|
The <tt>%proxycode</tt> directive is used and is just a macro for <tt>%insert("proxycode")</tt>.
|
||||||
|
The <a href="SWIG.html#SWIG_nn42">Code insertion block</a> section describes the <tt>%insert</tt> directive.
|
||||||
|
The section of code for insertion is "proxycode", that is, the Java proxy class.
|
||||||
|
This directive must hence only be used within the scope of a class, otherwise it is silently ignored.
|
||||||
|
There are two common ways to get the scope correct.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
The first is to use <tt>%proxycode</tt> inside a class that SWIG parses, for example a <tt>toString()</tt> method can be added to a C++ class using pure Java code.
|
||||||
|
A C++ header file can mix C++ and Java code inside the C++ class as follows:
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div class="code">
|
||||||
|
<pre>
|
||||||
|
// flag.h header file
|
||||||
|
class Flag {
|
||||||
|
bool flag;
|
||||||
|
public:
|
||||||
|
Flag(bool flag) : flag(flag) {}
|
||||||
|
bool FetchFlag() { return flag; }
|
||||||
|
#if defined(SWIG)
|
||||||
|
%proxycode %{
|
||||||
|
public String toString() {
|
||||||
|
boolean flag = FetchFlag();
|
||||||
|
return Boolean.toString(flag);
|
||||||
|
}
|
||||||
|
%}
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
</pre>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
and wrapped using:
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div class="code">
|
||||||
|
<pre>
|
||||||
|
%{
|
||||||
|
#include "flag.h"
|
||||||
|
%}
|
||||||
|
%include "flag.h"
|
||||||
|
</pre>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
The second is to use <tt>%proxycode</tt> within <tt>%extend</tt> as everything within a <tt>%extend</tt> block is effectively within the scope of the class, for example:
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div class="code">
|
||||||
|
<pre>
|
||||||
|
// flag.h header file
|
||||||
|
class Flag {
|
||||||
|
bool flag;
|
||||||
|
public:
|
||||||
|
Flag(bool flag) : flag(flag) {}
|
||||||
|
bool FetchFlag() { return flag; }
|
||||||
|
};
|
||||||
|
</pre>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
and wrapped using:
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div class="code">
|
||||||
|
<pre>
|
||||||
|
%{
|
||||||
|
#include "flag.h"
|
||||||
|
%}
|
||||||
|
%include "flag.h"
|
||||||
|
|
||||||
|
%extend Flag {
|
||||||
|
#if defined(SWIG)
|
||||||
|
%proxycode %{
|
||||||
|
public String toString() {
|
||||||
|
boolean flag = FetchFlag();
|
||||||
|
return Boolean.toString(flag);
|
||||||
|
}
|
||||||
|
%}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
</pre>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
There is some very limited support of typemaps within a <tt>%proxycode</tt> block.
|
||||||
|
A useful trick is to obtain the Java type for a given C/C++ type using the <a href="Typemaps.html#Typemaps_special_macro_typemap">$typemap</a> special macro.
|
||||||
|
The following C++ template demonstrates this:
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div class="code">
|
||||||
|
<pre>
|
||||||
|
%inline %{
|
||||||
|
template<typename T> struct Value {
|
||||||
|
T value;
|
||||||
|
Value(const T& val) : value(val) {}
|
||||||
|
};
|
||||||
|
%}
|
||||||
|
|
||||||
|
%extend Value {
|
||||||
|
%proxycode %{
|
||||||
|
public String toString() {
|
||||||
|
// Note template type expansion is supported, so T is expanded to 'unsigned int' in this example
|
||||||
|
// and $typemap(jstype, unsigned int) in turn is expanded to 'long'
|
||||||
|
$typemap(jstype, T) val = getValue();
|
||||||
|
return "$javaclassname value: " + val + " Java type: $typemap(jstype, T) JNI type: $typemap(jni, T)";
|
||||||
|
}
|
||||||
|
%}
|
||||||
|
}
|
||||||
|
%template(ValueUnsignedInt) Value<unsigned int>;
|
||||||
|
</pre>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
The generated Java contains the expanded special variable and macro resulting in Java proxy code:
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div class="code">
|
||||||
|
<pre>
|
||||||
|
public class ValueUnsignedInt {
|
||||||
|
...
|
||||||
|
public String toString() {
|
||||||
|
long val = getValue();
|
||||||
|
return "ValueUnsignedInt value: " + val + " Java type: long JNI type: jlong";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
</pre>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<H3><a name="Java_exception_handling">25.7.4 Exception handling with %exception and %javaexception</a></H3>
|
||||||
|
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
|
|
@ -4522,7 +4660,7 @@ to raise exceptions. See the <a href="Library.html#Library">SWIG Library</a> ch
|
||||||
The typemap example <a href="#Java_exception_typemap">Handling C++ exception specifications as Java exceptions</a> provides further exception handling capabilities.
|
The typemap example <a href="#Java_exception_typemap">Handling C++ exception specifications as Java exceptions</a> provides further exception handling capabilities.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<H3><a name="Java_method_access">25.7.4 Method access with %javamethodmodifiers</a></H3>
|
<H3><a name="Java_method_access">25.7.5 Method access with %javamethodmodifiers</a></H3>
|
||||||
|
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
|
|
@ -6070,6 +6208,9 @@ class modifiers for the Java class: default is "public class"
|
||||||
<p><tt>%typemap(javacode)</tt></p>
|
<p><tt>%typemap(javacode)</tt></p>
|
||||||
<div class="indent">
|
<div class="indent">
|
||||||
Java code is copied verbatim to the Java class: empty default
|
Java code is copied verbatim to the Java class: empty default
|
||||||
|
As there can only be one "javacode" typemap per class, also consider using the
|
||||||
|
<a href="Java.html#Java_proxycode">%proxycode</a> directive which can be used multiple times per class
|
||||||
|
and offers nearly identical functionality.
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<p><tt>%typemap(javadestruct, methodname="delete", methodmodifiers="public synchronized")</tt> <br></p>
|
<p><tt>%typemap(javadestruct, methodname="delete", methodmodifiers="public synchronized")</tt> <br></p>
|
||||||
|
|
@ -6350,11 +6491,24 @@ A typemap for C character strings is:
|
||||||
|
|
||||||
<div class="code">
|
<div class="code">
|
||||||
<pre>
|
<pre>
|
||||||
%typemap(directorin,descriptor="Ljava/lang/String;") char *
|
%typemap(directorin, descriptor="Ljava/lang/String;", noblock=1) char * {
|
||||||
%{ $input = jenv->NewStringUTF($1); %}
|
$input = 0;
|
||||||
|
if ($1) {
|
||||||
|
$input = JCALL1(NewStringUTF, jenv, (const char *)$1);
|
||||||
|
if (!$input) return $null;
|
||||||
|
}
|
||||||
|
Swig::LocalRefGuard $1_refguard(jenv, $input);
|
||||||
|
}
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
The <tt>Swig::LocalRefGuard</tt> class should be used in directorin typemaps for newly allocated objects.
|
||||||
|
It is used to control local reference counts ensuring the count is decremented after the call up into Java has completed.
|
||||||
|
Its destructor simply calls <tt>jenv->DeleteLocalRef(obj)</tt> on the <tt>obj</tt>
|
||||||
|
passed in during construction.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
User-defined types have the default "descriptor" attribute "<code>L$packagepath/$javaclassname;</code>" where <code>$packagepath</code>
|
User-defined types have the default "descriptor" attribute "<code>L$packagepath/$javaclassname;</code>" where <code>$packagepath</code>
|
||||||
|
|
|
||||||
|
|
@ -1903,7 +1903,7 @@ Adding the missing <tt>%shared_ptr</tt> macros will fix this:
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<b>Note:</b> There is somewhat limited support for <tt>%shared_ptr</tt> and the director feature
|
<b>Note:</b> There is somewhat limited support for <tt>%shared_ptr</tt> and the director feature
|
||||||
and the degress of success varies among the different target languages.
|
and the degrees of success varies among the different target languages.
|
||||||
Please help to improve this support by providing patches with improvements.
|
Please help to improve this support by providing patches with improvements.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,12 @@
|
||||||
# Makefile for generating the SWIG documentation
|
# Makefile for generating the SWIG documentation
|
||||||
#
|
#
|
||||||
# Note that the htmldoc package needs to be installed, but requires patching (using the
|
# Note that the htmldoc package needs to be installed. wkhtmltopdf patched with qt is also required
|
||||||
# margin-left.patch file from this directory) in order to correctly generate the pdf docs.
|
# and can be installed from http://wkhtmltopdf.org/downloads.html.
|
||||||
|
#
|
||||||
# The .html files are first processed and updated with chapter numbering and anchor names
|
# The .html files are first processed and updated with chapter numbering and anchor names
|
||||||
# are added to the HTML headings using the python scripts. The htmldoc program is then
|
# are added to the HTML headings using the python scripts. The htmldoc program is then
|
||||||
# used to generate the PDF document and single page HTML version of the documentation.
|
# used to generate the single page HTML version of the documentation.
|
||||||
|
# wkhtmltopdf is used to generate the pdf document from the single page html file.
|
||||||
# HTML TIDY (package also known as tidy) is also required and is used as an aid to HTML
|
# HTML TIDY (package also known as tidy) is also required and is used as an aid to HTML
|
||||||
# validation.
|
# validation.
|
||||||
#
|
#
|
||||||
|
|
|
||||||
|
|
@ -197,7 +197,7 @@ SWIG tries to guess the right options when it is installed. Therefore,
|
||||||
you may want to start with one of the examples in the <tt>SWIG/Examples/perl5</tt>
|
you may want to start with one of the examples in the <tt>SWIG/Examples/perl5</tt>
|
||||||
directory. If that doesn't work, you will need to read the man-pages for
|
directory. If that doesn't work, you will need to read the man-pages for
|
||||||
your compiler and linker to get the right set of options. You might also
|
your compiler and linker to get the right set of options. You might also
|
||||||
check the <a href="http://www.dabeaz.com/cgi-bin/wiki.pl">SWIG Wiki</a> for
|
check the <a href="https://github.com/swig/swig/wiki">SWIG Wiki</a> for
|
||||||
additional information.
|
additional information.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -49,19 +49,6 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<p>
|
|
||||||
SWIG supports generating wrappers for PHP5. Support for PHP4 was removed
|
|
||||||
in SWIG 1.3.37. The PHP developers are no longer making new PHP4 releases,
|
|
||||||
and won't even be patching critical security issues after 2008-08-08, so it
|
|
||||||
doesn't make much sense for SWIG to continue to support PHP4 now. If you
|
|
||||||
really need to continue to use PHP4, just stick with SWIG 1.3.36.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
Currently any PHP5 release should work, but we don't regularly test with
|
|
||||||
PHP < 5.3.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
In this chapter, we discuss SWIG's support of PHP. The PHP module
|
In this chapter, we discuss SWIG's support of PHP. The PHP module
|
||||||
was extensively rewritten in release 1.3.26, and support for generating
|
was extensively rewritten in release 1.3.26, and support for generating
|
||||||
|
|
@ -70,7 +57,17 @@ of the features available in some of the other languages.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
In order to use this module, you will need to have a copy of the PHP5
|
SWIG supports generating wrappers for PHP5 and PHP7. Support for PHP4 was removed
|
||||||
|
in SWIG 1.3.37.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Currently any PHP5 or PHP7 release should work, but we don't regularly test with
|
||||||
|
PHP < 5.3.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
In order to use this module, you will need to have a copy of the PHP
|
||||||
include files to compile the SWIG generated files. If you installed
|
include files to compile the SWIG generated files. If you installed
|
||||||
PHP from a binary package, you may need to install a "php-dev" or "php-devel"
|
PHP from a binary package, you may need to install a "php-dev" or "php-devel"
|
||||||
package for these to be installed. You can find out where these files are
|
package for these to be installed. You can find out where these files are
|
||||||
|
|
@ -84,12 +81,13 @@ available.
|
||||||
|
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
To build a PHP extension, run swig using the <tt>-php</tt> option as
|
To build a PHP extension, run swig using the <tt>-php5</tt> or
|
||||||
follows:
|
<tt>-php7</tt> option as follows (<tt>-php</tt> is also supported
|
||||||
|
and currently is an alias for <tt>-php5</tt>):
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<div class="code"><pre>
|
<div class="code"><pre>
|
||||||
swig -php example.i
|
swig -php7 example.i
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
|
|
@ -102,13 +100,18 @@ The third file,
|
||||||
<tt>example.php</tt> can be included by PHP scripts. It attempts to
|
<tt>example.php</tt> can be included by PHP scripts. It attempts to
|
||||||
dynamically load the extension and contains extra php code specified
|
dynamically load the extension and contains extra php code specified
|
||||||
in the interface file. If wrapping C++ code with PHP classes, it will
|
in the interface file. If wrapping C++ code with PHP classes, it will
|
||||||
also contain PHP5 class wrappers.
|
also contain PHP class wrappers.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
SWIG can generate PHP extensions from C++ libraries as well when
|
SWIG can generate PHP extensions from C++ libraries as well when
|
||||||
given the <tt>-c++</tt> option. The support for C++ is discussed in
|
given the <tt>-c++</tt> option. The support for C++ is discussed in
|
||||||
more detail in <a href="#Php_nn2_6">section 27.2.6</a>.
|
more detail in <a href="#Php_nn2_6">section 27.2.6</a>. The generated
|
||||||
|
C++ wrapper will be called example_wrap.cpp (for PHP5) or
|
||||||
|
example_wrap.cxx (for PHP7 where the default has been changed to align
|
||||||
|
with SWIG's default for every other language). You can specify a
|
||||||
|
different extension for the C++ wrapper using <tt>-cppext</tt> -
|
||||||
|
e.g. if you want example_wrap.cc use <tt>-cppext cc</tt>.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
|
|
@ -273,7 +276,8 @@ if(EASY_TO_MISPEL) {
|
||||||
<p>
|
<p>
|
||||||
The mis-spelled constant will become the string 'EASY_TO_MISPEL', which
|
The mis-spelled constant will become the string 'EASY_TO_MISPEL', which
|
||||||
is treated as true by the if test, when the value of the intended constant
|
is treated as true by the if test, when the value of the intended constant
|
||||||
would be treated as false!
|
would be treated as false! Modern versions of PHP will at least issue
|
||||||
|
a PHP notice by default when this happens.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<H3><a name="Php_nn2_2">34.2.2 Global Variables</a></H3>
|
<H3><a name="Php_nn2_2">34.2.2 Global Variables</a></H3>
|
||||||
|
|
@ -611,7 +615,7 @@ struct Complex {
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
Would be used in the following way from PHP5:
|
Would be used in the following way from PHP:
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<div class="code"><pre>
|
<div class="code"><pre>
|
||||||
|
|
@ -646,7 +650,7 @@ Member variables and methods are accessed using the <tt>-></tt> operator.
|
||||||
<p>
|
<p>
|
||||||
The <tt>-noproxy</tt> option flattens the object structure and
|
The <tt>-noproxy</tt> option flattens the object structure and
|
||||||
generates collections of named functions (these are the functions
|
generates collections of named functions (these are the functions
|
||||||
which the PHP5 class wrappers call). The above example results
|
which the PHP class wrappers call). The above example results
|
||||||
in the following PHP functions:
|
in the following PHP functions:
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
|
@ -1143,12 +1147,20 @@ deleting all the Foo pointers it contains at some point.
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
With directors routing method calls to PHP, and proxies routing them
|
With directors routing method calls to PHP, and proxies routing them
|
||||||
to C++, the handling of exceptions is an important concern. By default, the
|
to C++, the handling of exceptions is an important concern. By default, an
|
||||||
directors ignore exceptions that occur during method calls that are
|
exception thrown in PHP code called from C++ causes the PHP interpreter
|
||||||
resolved in PHP. To handle such exceptions correctly, it is necessary
|
to flag that an exception is thrown, then return passes to C++ as if
|
||||||
to temporarily translate them into C++ exceptions. This can be done with
|
the PHP function had returned <code>Null</code>. Assuming the directorout
|
||||||
the %feature("director:except") directive. The following code should
|
typemaps handle this (those SWIG defines by default should) then once
|
||||||
suffice in most cases:
|
control returns to PHP code again, the PHP exception will actually propagate.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Sometimes this control flow is problematic, and you want to skip any
|
||||||
|
handling in the C++ code. To achieve this, it is necessary
|
||||||
|
to temporarily translate the PHP exception into a C++ exception. This can be
|
||||||
|
achieved using the %feature("director:except") directive. The following code
|
||||||
|
should suffice in most cases:
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<div class="code">
|
<div class="code">
|
||||||
|
|
|
||||||
|
|
@ -125,7 +125,9 @@ SWIGMZSCHEME Defined when using Mzscheme
|
||||||
SWIGOCAML Defined when using Ocaml
|
SWIGOCAML Defined when using Ocaml
|
||||||
SWIGOCTAVE Defined when using Octave
|
SWIGOCTAVE Defined when using Octave
|
||||||
SWIGPERL Defined when using Perl
|
SWIGPERL Defined when using Perl
|
||||||
SWIGPHP Defined when using PHP
|
SWIGPHP Defined when using PHP5 or PHP7
|
||||||
|
SWIGPHP5 Defined when using PHP5
|
||||||
|
SWIGPHP7 Defined when using PHP7
|
||||||
SWIGPIKE Defined when using Pike
|
SWIGPIKE Defined when using Pike
|
||||||
SWIGPYTHON Defined when using Python
|
SWIGPYTHON Defined when using Python
|
||||||
SWIGR Defined when using R
|
SWIGR Defined when using R
|
||||||
|
|
|
||||||
|
|
@ -400,7 +400,7 @@ However, SWIG tries to guess the right options when it is installed. Therefore,
|
||||||
you may want to start with one of the examples in the <tt>SWIG/Examples/python</tt>
|
you may want to start with one of the examples in the <tt>SWIG/Examples/python</tt>
|
||||||
directory. If that doesn't work, you will need to read the man-pages for
|
directory. If that doesn't work, you will need to read the man-pages for
|
||||||
your compiler and linker to get the right set of options. You might also
|
your compiler and linker to get the right set of options. You might also
|
||||||
check the <a href="http://www.dabeaz.com/cgi-bin/wiki.pl">SWIG Wiki</a> for
|
check the <a href="https://github.com/swig/swig/wiki">SWIG Wiki</a> for
|
||||||
additional information.
|
additional information.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
|
@ -509,7 +509,7 @@ If using static linking, you might want to rely on a different approach
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
To use your module, simply use the Python <tt>import</tt> statement. If
|
To use your module, simply use the Python <tt>import</tt> statement. If
|
||||||
all goes well, you will be able to this:
|
all goes well, you will be able to run this:
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<div class="targetlang"><pre>
|
<div class="targetlang"><pre>
|
||||||
|
|
@ -914,7 +914,7 @@ only used by the Visual Studio compiler:
|
||||||
Some users have reported success in building extension modules using Cygwin
|
Some users have reported success in building extension modules using Cygwin
|
||||||
and other compilers. However, the problem of building usable DLLs with these
|
and other compilers. However, the problem of building usable DLLs with these
|
||||||
compilers tends to be rather problematic. For the latest information,
|
compilers tends to be rather problematic. For the latest information,
|
||||||
you may want to consult the <a href="http://www.dabeaz.com/cgi-bin/wiki.pl">
|
you may want to consult the <a href="https://github.com/swig/swig/wiki">
|
||||||
SWIG Wiki</a>.
|
SWIG Wiki</a>.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
|
@ -6037,7 +6037,7 @@ zipimporter requires python-3.5.1 or newer to work with subpackages.
|
||||||
<p>
|
<p>
|
||||||
When SWIG creates wrappers from an interface file, say foo.i, two Python modules are
|
When SWIG creates wrappers from an interface file, say foo.i, two Python modules are
|
||||||
created. There is a pure Python module module (foo.py) and C/C++ code which is
|
created. There is a pure Python module module (foo.py) and C/C++ code which is
|
||||||
built and linked into a dynamically (or statically) loaded module _foo
|
built and linked into a dynamically (or statically) loaded low-level module _foo
|
||||||
(see the <a href="Python.html#Python_nn3">Preliminaries section</a> for details). So, the interface
|
(see the <a href="Python.html#Python_nn3">Preliminaries section</a> for details). So, the interface
|
||||||
file really defines two Python modules. How these two modules are loaded is
|
file really defines two Python modules. How these two modules are loaded is
|
||||||
covered next.
|
covered next.
|
||||||
|
|
@ -6064,7 +6064,43 @@ pure Python module uses to find the C/C++ module is as follows:
|
||||||
</ol>
|
</ol>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
As an example suppose foo.i is compiled into foo.py and _foo.so. Assuming
|
The Python code implementing the loading logic described above is quite complex to handle multiple
|
||||||
|
versions of Python, but it can be replaced with custom code.
|
||||||
|
This is not recommended unless you understand the full intricacies of importing Python modules.
|
||||||
|
The custom code can be specified by setting the <tt>moduleimport</tt> option of the <tt>%module</tt> directive with the appropriate import code. For example:
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div class="code">
|
||||||
|
<pre>
|
||||||
|
%module(moduleimport="import _foo") foo
|
||||||
|
</pre>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
The special variable <tt>$module</tt> will also be expanded into the low-level C/C++ module name, <tt>_foo</tt> in the case above.
|
||||||
|
When you have more than just a line or so then you can retain the easy
|
||||||
|
readability of the <tt>%module</tt> directive by using a macro. For
|
||||||
|
example:
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div class="code">
|
||||||
|
<pre>
|
||||||
|
%define MODULEIMPORT
|
||||||
|
"
|
||||||
|
print 'Loading low-level module $module'
|
||||||
|
import $module
|
||||||
|
print 'Module has loaded'
|
||||||
|
"
|
||||||
|
%enddef
|
||||||
|
|
||||||
|
%module(moduleimport=MODULEIMPORT) foo
|
||||||
|
</pre>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Now let's consider an example using the SWIG default loading logic.
|
||||||
|
Suppose foo.i is compiled into foo.py and _foo.so. Assuming
|
||||||
/dir is on PYTHONPATH, then the two modules can be installed and used in the
|
/dir is on PYTHONPATH, then the two modules can be installed and used in the
|
||||||
following ways:
|
following ways:
|
||||||
</p>
|
</p>
|
||||||
|
|
|
||||||
|
|
@ -192,28 +192,13 @@ to compile this file and link it with the rest of your program. </p>
|
||||||
|
|
||||||
|
|
||||||
<p> In order to compile the wrapper code, the compiler needs the <tt>ruby.h</tt>
|
<p> In order to compile the wrapper code, the compiler needs the <tt>ruby.h</tt>
|
||||||
header file. This file is usually contained in a directory such as </p>
|
header file and its dependencies, notably <tt>ruby/config.h</tt> which is
|
||||||
|
found in a different, architecture-dependent, directory. The best way to find
|
||||||
<div class="code shell diagram">
|
the compiler options needed to compile the code is to ask Ruby itself:</p>
|
||||||
<pre>/usr/lib/ruby/1.8/x86_64-linux-gnu/ruby.h
|
|
||||||
/usr/include/ruby-2.1.0/ruby.h
|
|
||||||
</pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<p> The exact location may vary on your machine, but the above
|
|
||||||
location is typical. If you are not entirely sure where Ruby is
|
|
||||||
installed, you can run Ruby to find out. For example: </p>
|
|
||||||
|
|
||||||
<div class="code shell">
|
<div class="code shell">
|
||||||
<pre>$ ruby -e 'puts $:.join("\n")'
|
<pre>$ ruby -rrbconfig -e 'puts "-I#{RbConfig::CONFIG[%q{rubyhdrdir}]} -I#{RbConfig::CONFIG[%q{rubyarchhdrdir}]}"'
|
||||||
/usr/local/lib/site_ruby/2.1.0
|
-I/usr/include/ruby-2.1.0 -I/usr/include/x86_64-linux-gnu/ruby-2.1.0
|
||||||
/usr/local/lib/x86_64-linux-gnu/site_ruby
|
|
||||||
/usr/local/lib/site_ruby
|
|
||||||
/usr/lib/ruby/vendor_ruby/2.1.0
|
|
||||||
/usr/lib/x86_64-linux-gnu/ruby/vendor_ruby/2.1.0
|
|
||||||
/usr/lib/ruby/vendor_ruby
|
|
||||||
/usr/lib/ruby/2.1.0
|
|
||||||
/usr/lib/x86_64-linux-gnu/ruby/2.1.0
|
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
@ -287,7 +272,7 @@ processes). Other compilers may need a different option specified instead of
|
||||||
<p>
|
<p>
|
||||||
If in doubt, consult the
|
If in doubt, consult the
|
||||||
manual pages for your compiler and linker to determine the correct set
|
manual pages for your compiler and linker to determine the correct set
|
||||||
of options. You might also check the <a href="http://www.dabeaz.com/cgi-bin/wiki.pl">SWIG Wiki</a>
|
of options. You might also check the <a href="https://github.com/swig/swig/wiki">SWIG Wiki</a>
|
||||||
for additional information. </p>
|
for additional information. </p>
|
||||||
|
|
||||||
<H3><a name="Ruby_nn6">38.1.4 Using your module</a></H3>
|
<H3><a name="Ruby_nn6">38.1.4 Using your module</a></H3>
|
||||||
|
|
|
||||||
|
|
@ -131,7 +131,8 @@ can be obtained by typing <tt>swig -help</tt> or <tt>swig
|
||||||
-ocaml Generate Ocaml wrappers
|
-ocaml Generate Ocaml wrappers
|
||||||
-octave Generate Octave wrappers
|
-octave Generate Octave wrappers
|
||||||
-perl Generate Perl wrappers
|
-perl Generate Perl wrappers
|
||||||
-php Generate PHP wrappers
|
-php5 Generate PHP5 wrappers
|
||||||
|
-php7 Generate PHP7 wrappers
|
||||||
-pike Generate Pike wrappers
|
-pike Generate Pike wrappers
|
||||||
-python Generate Python wrappers
|
-python Generate Python wrappers
|
||||||
-r Generate R (aka GNU S) wrappers
|
-r Generate R (aka GNU S) wrappers
|
||||||
|
|
@ -142,23 +143,23 @@ can be obtained by typing <tt>swig -help</tt> or <tt>swig
|
||||||
-uffi Generate Common Lisp / UFFI wrappers
|
-uffi Generate Common Lisp / UFFI wrappers
|
||||||
-xml Generate XML wrappers
|
-xml Generate XML wrappers
|
||||||
|
|
||||||
-c++ Enable C++ parsing
|
-c++ Enable C++ processing
|
||||||
-cppext <em>ext</em> Change file extension of C++ generated files to <em>ext</em>
|
-cppext <em>ext</em> Change file extension of C++ generated files to <em>ext</em>
|
||||||
(default is cxx, except for PHP which uses cpp)
|
(default is cxx, except for PHP5 which uses cpp)
|
||||||
-D<em>symbol</em> Define a preprocessor symbol
|
-D<em>symbol</em> Define a preprocessor symbol
|
||||||
-Fstandard Display error/warning messages in commonly used format
|
|
||||||
-Fmicrosoft Display error/warning messages in Microsoft format
|
-Fmicrosoft Display error/warning messages in Microsoft format
|
||||||
|
-Fstandard Display error/warning messages in commonly used format
|
||||||
-help Display all options
|
-help Display all options
|
||||||
-I<em>dir</em> Add a directory to the file include path
|
-I<em>dir</em> Add a directory to the file include path
|
||||||
-l<em>file</em> Include a SWIG library file.
|
-l<em>ifile</em> Include SWIG library file <ifile>
|
||||||
-module <em>name</em> Set the name of the SWIG module
|
-module <em>name</em> Set the name of the SWIG module
|
||||||
-o <em>outfile</em> Set name of C/C++ output file to <outfile>
|
-o <em>outfile</em> Set name of C/C++ output file to <outfile>
|
||||||
-oh <em>headfile</em> Set name of C++ output header file for directors to <headfile>
|
-oh <em>headfile</em> Set name of C++ output header file for directors to <headfile>
|
||||||
-outcurrentdir Set default output dir to current dir instead of input file's path
|
-outcurrentdir Set default output dir to current dir instead of input file's path
|
||||||
-outdir <em>dir</em> Set language specific files output directory
|
-outdir <em>dir</em> Set language specific files output directory
|
||||||
-pcreversion Display PCRE version information
|
-pcreversion Display PCRE version information
|
||||||
-swiglib Show location of SWIG library
|
-swiglib Report location of SWIG library and exit
|
||||||
-version Show SWIG version number
|
-version Display SWIG version number
|
||||||
|
|
||||||
</pre></div>
|
</pre></div>
|
||||||
|
|
||||||
|
|
@ -749,7 +750,7 @@ form of type-checking however).</p>
|
||||||
<p>
|
<p>
|
||||||
For enumerations, it is critical that the original enum definition be
|
For enumerations, it is critical that the original enum definition be
|
||||||
included somewhere in the interface file (either in a header file or
|
included somewhere in the interface file (either in a header file or
|
||||||
in the <tt>%{,%}</tt> block). SWIG only translates the enumeration
|
in the <tt>%{ %}</tt> block). SWIG only translates the enumeration
|
||||||
into code needed to add the constants to a scripting language. It
|
into code needed to add the constants to a scripting language. It
|
||||||
needs the original enumeration declaration in order to get the correct
|
needs the original enumeration declaration in order to get the correct
|
||||||
enum values as assigned by the C compiler.
|
enum values as assigned by the C compiler.
|
||||||
|
|
@ -3139,7 +3140,7 @@ output of SWIG is structured first.</p>
|
||||||
|
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
When SWIG creates its output file, it is broken up into five sections
|
When SWIG creates its output C/C++ file, it is broken up into five sections
|
||||||
corresponding to runtime code, headers, wrapper functions, and module
|
corresponding to runtime code, headers, wrapper functions, and module
|
||||||
initialization code (in that order).
|
initialization code (in that order).
|
||||||
</p>
|
</p>
|
||||||
|
|
@ -3175,9 +3176,37 @@ the module upon loading.
|
||||||
|
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
Code is inserted into the appropriate code section by using one
|
The <tt>%insert</tt> directive enables inserting blocks of code into a given section of the generated code.
|
||||||
of the code insertion directives listed below. The order of the sections in
|
It can be used in one of two ways:
|
||||||
the wrapper file is as shown:
|
</p>
|
||||||
|
|
||||||
|
<div class="code">
|
||||||
|
<pre>
|
||||||
|
%insert("section") "filename"
|
||||||
|
%insert("section") %{ ... %}
|
||||||
|
</pre>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
The first will dump the contents of the file in the given <tt>filename</tt> into the named <tt>section</tt>.
|
||||||
|
The second inserts the code between the braces into the named <tt>section</tt>.
|
||||||
|
For example, the following adds code into the runtime section:
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div class="code">
|
||||||
|
<pre>
|
||||||
|
%insert("runtime") %{
|
||||||
|
... code in runtime section ...
|
||||||
|
%}
|
||||||
|
</pre>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
There are the 5 sections, however, some target languages add in additional sections and some of these result in code being generated into a target language file instead of the C/C++ wrapper file.
|
||||||
|
These are documented when available in the target language chapters.
|
||||||
|
Macros named after the code sections are available as additional directives and these macro directives are normally used instead of <tt>%insert</tt>.
|
||||||
|
For example, <tt>%runtime</tt> is used instead of <tt>%insert("runtime")</tt>.
|
||||||
|
The valid sections and order of the sections in the generated C/C++ wrapper file is as shown:
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<div class="code">
|
<div class="code">
|
||||||
|
|
@ -3441,7 +3470,7 @@ header files.
|
||||||
<p>
|
<p>
|
||||||
Sometimes, it is necessary to use certain header files in order for
|
Sometimes, it is necessary to use certain header files in order for
|
||||||
the code generated by SWIG to compile properly. Make sure you
|
the code generated by SWIG to compile properly. Make sure you
|
||||||
include certain header files by using a <tt>%{,%}</tt> block like this:
|
include certain header files by using a <tt>%{ %}</tt> block like this:
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<div class="code"><pre>
|
<div class="code"><pre>
|
||||||
|
|
|
||||||
|
|
@ -2766,7 +2766,6 @@ have to handle it like a normal function. For example:
|
||||||
are ignored as well as conversion and index operators. A warning such as the one below is shown:
|
are ignored as well as conversion and index operators. A warning such as the one below is shown:
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
|
||||||
<div class="shell">
|
<div class="shell">
|
||||||
<pre>
|
<pre>
|
||||||
example.i:12: Warning 503: Can't wrap 'operator []' unless renamed to a valid identifier.
|
example.i:12: Warning 503: Can't wrap 'operator []' unless renamed to a valid identifier.
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
<H1><a name="Sections">SWIG-3.0 Documentation</a></H1>
|
<H1><a name="Sections">SWIG-3.0 Documentation</a></H1>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
Last update : SWIG-3.0.11 (in progress)
|
Last update : SWIG-3.0.12 (in progress)
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<H2><a name="Sections_Sections">Sections</a></H2>
|
<H2><a name="Sections_Sections">Sections</a></H2>
|
||||||
|
|
|
||||||
|
|
@ -151,7 +151,7 @@ SWIG tries to guess the right options when it is installed. Therefore,
|
||||||
you may want to start with one of the examples in the <tt>SWIG/Examples/tcl</tt>
|
you may want to start with one of the examples in the <tt>SWIG/Examples/tcl</tt>
|
||||||
directory. If that doesn't work, you will need to read the man-pages for
|
directory. If that doesn't work, you will need to read the man-pages for
|
||||||
your compiler and linker to get the right set of options. You might also
|
your compiler and linker to get the right set of options. You might also
|
||||||
check the <a href="http://www.dabeaz.com/cgi-bin/wiki.pl">SWIG Wiki</a> for
|
check the <a href="https://github.com/swig/swig/wiki">SWIG Wiki</a> for
|
||||||
additional information.
|
additional information.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1116,7 +1116,57 @@ ruby_clean:
|
||||||
rm -f *.@OBJEXT@ *$(RUBY_SO)
|
rm -f *.@OBJEXT@ *$(RUBY_SO)
|
||||||
|
|
||||||
##################################################################
|
##################################################################
|
||||||
##### PHP ######
|
##### PHP5 ######
|
||||||
|
##################################################################
|
||||||
|
|
||||||
|
PHP5 = @PHP5@
|
||||||
|
PHP5_INCLUDE = @PHP5INC@
|
||||||
|
PHP5_SO = @PHP5_SO@
|
||||||
|
PHP5_SCRIPT = $(SRCDIR)$(RUNME).php
|
||||||
|
|
||||||
|
# -------------------------------------------------------------------
|
||||||
|
# Build a PHP5 dynamically loadable module (C)
|
||||||
|
# -------------------------------------------------------------------
|
||||||
|
|
||||||
|
php5: $(SRCDIR_SRCS)
|
||||||
|
$(SWIG) -php5 $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH)
|
||||||
|
$(CC) -c $(CCSHARED) $(CPPFLAGS) $(CFLAGS) $(SRCDIR_SRCS) $(ISRCS) $(INCLUDES) $(PHP5_INCLUDE)
|
||||||
|
$(LDSHARED) $(CFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(PHP5_SO)
|
||||||
|
|
||||||
|
# --------------------------------------------------------------------
|
||||||
|
# Build a PHP5 dynamically loadable module (C++)
|
||||||
|
# --------------------------------------------------------------------
|
||||||
|
|
||||||
|
php5_cpp: $(SRCDIR_SRCS)
|
||||||
|
$(SWIG) -php5 -cppext cxx -c++ $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH)
|
||||||
|
$(CXX) -c $(CCSHARED) $(CPPFLAGS) $(CXXFLAGS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(ICXXSRCS) $(INCLUDES) $(PHP5_INCLUDE)
|
||||||
|
$(CXXSHARED) $(CXXFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(PHP5_SO)
|
||||||
|
|
||||||
|
# -----------------------------------------------------------------
|
||||||
|
# Running a PHP5 example
|
||||||
|
# -----------------------------------------------------------------
|
||||||
|
|
||||||
|
php5_run:
|
||||||
|
$(RUNTOOL) $(PHP5) -n -q -d extension_dir=. -d safe_mode=Off $(PHP5_SCRIPT) $(RUNPIPE)
|
||||||
|
|
||||||
|
# -----------------------------------------------------------------
|
||||||
|
# Version display
|
||||||
|
# -----------------------------------------------------------------
|
||||||
|
|
||||||
|
php5_version:
|
||||||
|
$(PHP5) -v | head -n 1
|
||||||
|
|
||||||
|
# -----------------------------------------------------------------
|
||||||
|
# Cleaning the PHP5 examples
|
||||||
|
# -----------------------------------------------------------------
|
||||||
|
|
||||||
|
php5_clean:
|
||||||
|
rm -f *_wrap* *~ .~* example.php php_example.h
|
||||||
|
rm -f core @EXTRA_CLEAN@
|
||||||
|
rm -f *.@OBJEXT@ *$(PHP5_SO)
|
||||||
|
|
||||||
|
##################################################################
|
||||||
|
##### PHP7 ######
|
||||||
##################################################################
|
##################################################################
|
||||||
|
|
||||||
PHP = @PHP@
|
PHP = @PHP@
|
||||||
|
|
@ -1129,7 +1179,7 @@ PHP_SCRIPT = $(SRCDIR)$(RUNME).php
|
||||||
# -------------------------------------------------------------------
|
# -------------------------------------------------------------------
|
||||||
|
|
||||||
php: $(SRCDIR_SRCS)
|
php: $(SRCDIR_SRCS)
|
||||||
$(SWIG) -php $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH)
|
$(SWIG) -php7 $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH)
|
||||||
$(CC) -c $(CCSHARED) $(CPPFLAGS) $(CFLAGS) $(SRCDIR_SRCS) $(ISRCS) $(INCLUDES) $(PHP_INCLUDE)
|
$(CC) -c $(CCSHARED) $(CPPFLAGS) $(CFLAGS) $(SRCDIR_SRCS) $(ISRCS) $(INCLUDES) $(PHP_INCLUDE)
|
||||||
$(LDSHARED) $(CFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(PHP_SO)
|
$(LDSHARED) $(CFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(PHP_SO)
|
||||||
|
|
||||||
|
|
@ -1138,7 +1188,7 @@ php: $(SRCDIR_SRCS)
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
|
|
||||||
php_cpp: $(SRCDIR_SRCS)
|
php_cpp: $(SRCDIR_SRCS)
|
||||||
$(SWIG) -php -cppext cxx -c++ $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH)
|
$(SWIG) -php7 -c++ $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH)
|
||||||
$(CXX) -c $(CCSHARED) $(CPPFLAGS) $(CXXFLAGS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(ICXXSRCS) $(INCLUDES) $(PHP_INCLUDE)
|
$(CXX) -c $(CCSHARED) $(CPPFLAGS) $(CXXFLAGS) $(SRCDIR_SRCS) $(SRCDIR_CXXSRCS) $(ICXXSRCS) $(INCLUDES) $(PHP_INCLUDE)
|
||||||
$(CXXSHARED) $(CXXFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(PHP_SO)
|
$(CXXSHARED) $(CXXFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) $(CPP_DLLIBS) -o $(LIBPREFIX)$(TARGET)$(PHP_SO)
|
||||||
|
|
||||||
|
|
@ -1147,7 +1197,7 @@ php_cpp: $(SRCDIR_SRCS)
|
||||||
# -----------------------------------------------------------------
|
# -----------------------------------------------------------------
|
||||||
|
|
||||||
php_run:
|
php_run:
|
||||||
$(RUNTOOL) $(PHP) -n -q -d extension_dir=. -d safe_mode=Off $(PHP_SCRIPT) $(RUNPIPE)
|
$(RUNTOOL) $(PHP) -n -q -d extension_dir=. -d safe_mode=Off -d display_errors=stderr $(PHP_SCRIPT) $(RUNPIPE)
|
||||||
|
|
||||||
# -----------------------------------------------------------------
|
# -----------------------------------------------------------------
|
||||||
# Version display
|
# Version display
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,7 @@
|
||||||
# file: runme.m
|
# do not dump Octave core
|
||||||
|
if exist("crash_dumps_octave_core", "builtin")
|
||||||
|
crash_dumps_octave_core(0);
|
||||||
|
endif
|
||||||
|
|
||||||
# This file illustrates the cross language polymorphism using directors.
|
# This file illustrates the cross language polymorphism using directors.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,7 @@
|
||||||
# file: runme.m
|
# do not dump Octave core
|
||||||
|
if exist("crash_dumps_octave_core", "builtin")
|
||||||
|
crash_dumps_octave_core(0);
|
||||||
|
endif
|
||||||
|
|
||||||
# This file illustrates the proxy class C++ interface generated
|
# This file illustrates the proxy class C++ interface generated
|
||||||
# by SWIG.
|
# by SWIG.
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,7 @@
|
||||||
# file: runme.m
|
# do not dump Octave core
|
||||||
|
if exist("crash_dumps_octave_core", "builtin")
|
||||||
|
crash_dumps_octave_core(0);
|
||||||
|
endif
|
||||||
|
|
||||||
swigexample
|
swigexample
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,7 @@
|
||||||
# file: runme.m
|
# do not dump Octave core
|
||||||
|
if exist("crash_dumps_octave_core", "builtin")
|
||||||
|
crash_dumps_octave_core(0);
|
||||||
|
endif
|
||||||
|
|
||||||
swigexample
|
swigexample
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,7 @@
|
||||||
# file: runme.m
|
# do not dump Octave core
|
||||||
|
if exist("crash_dumps_octave_core", "builtin")
|
||||||
|
crash_dumps_octave_core(0);
|
||||||
|
endif
|
||||||
|
|
||||||
swigexample
|
swigexample
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,7 @@
|
||||||
# file: runme.m
|
# do not dump Octave core
|
||||||
|
if exist("crash_dumps_octave_core", "builtin")
|
||||||
|
crash_dumps_octave_core(0);
|
||||||
|
endif
|
||||||
|
|
||||||
# This file illustrates the cross language polymorphism using directors.
|
# This file illustrates the cross language polymorphism using directors.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,7 @@
|
||||||
# file: runme.m
|
# do not dump Octave core
|
||||||
|
if exist("crash_dumps_octave_core", "builtin")
|
||||||
|
crash_dumps_octave_core(0);
|
||||||
|
endif
|
||||||
|
|
||||||
swigexample
|
swigexample
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,7 @@
|
||||||
# file: runme.m
|
# do not dump Octave core
|
||||||
|
if exist("crash_dumps_octave_core", "builtin")
|
||||||
|
crash_dumps_octave_core(0);
|
||||||
|
endif
|
||||||
|
|
||||||
swigexample
|
swigexample
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,8 @@
|
||||||
|
# do not dump Octave core
|
||||||
|
if exist("crash_dumps_octave_core", "builtin")
|
||||||
|
crash_dumps_octave_core(0);
|
||||||
|
endif
|
||||||
|
|
||||||
# Operator overloading example
|
# Operator overloading example
|
||||||
swigexample
|
swigexample
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,7 @@
|
||||||
# file: runme_args.m
|
# do not dump Octave core
|
||||||
|
if exist("crash_dumps_octave_core", "builtin")
|
||||||
|
crash_dumps_octave_core(0);
|
||||||
|
endif
|
||||||
|
|
||||||
# load module
|
# load module
|
||||||
clear all;
|
clear all;
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,8 @@
|
||||||
|
# do not dump Octave core
|
||||||
|
if exist("crash_dumps_octave_core", "builtin")
|
||||||
|
crash_dumps_octave_core(0);
|
||||||
|
endif
|
||||||
|
|
||||||
# Operator overloading example
|
# Operator overloading example
|
||||||
swigexample
|
swigexample
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,7 @@
|
||||||
# file: runme.m
|
# do not dump Octave core
|
||||||
|
if exist("crash_dumps_octave_core", "builtin")
|
||||||
|
crash_dumps_octave_core(0);
|
||||||
|
endif
|
||||||
|
|
||||||
swigexample;
|
swigexample;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,7 @@
|
||||||
# file: runme.m
|
# do not dump Octave core
|
||||||
|
if exist("crash_dumps_octave_core", "builtin")
|
||||||
|
crash_dumps_octave_core(0);
|
||||||
|
endif
|
||||||
|
|
||||||
# This file illustrates the manipulation of C++ references in Octave
|
# This file illustrates the manipulation of C++ references in Octave
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,7 @@
|
||||||
# file: runme.m
|
# do not dump Octave core
|
||||||
|
if exist("crash_dumps_octave_core", "builtin")
|
||||||
|
crash_dumps_octave_core(0);
|
||||||
|
endif
|
||||||
|
|
||||||
swigexample
|
swigexample
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,7 @@
|
||||||
# file: runme.m
|
# do not dump Octave core
|
||||||
|
if exist("crash_dumps_octave_core", "builtin")
|
||||||
|
crash_dumps_octave_core(0);
|
||||||
|
endif
|
||||||
|
|
||||||
swigexample
|
swigexample
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,7 @@
|
||||||
# file: runme.m
|
# do not dump Octave core
|
||||||
|
if exist("crash_dumps_octave_core", "builtin")
|
||||||
|
crash_dumps_octave_core(0);
|
||||||
|
endif
|
||||||
|
|
||||||
swigexample
|
swigexample
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,10 +15,5 @@ build:
|
||||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||||
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' php_cpp
|
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' php_cpp
|
||||||
|
|
||||||
static:
|
|
||||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' $(SWIGLIB) CXXSRCS='$(CXXSRCS)' \
|
|
||||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
|
||||||
SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' php_cpp_static
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean
|
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean
|
||||||
|
|
|
||||||
|
|
@ -16,11 +16,5 @@ build:
|
||||||
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
|
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
|
||||||
php_cpp
|
php_cpp
|
||||||
|
|
||||||
static:
|
|
||||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \
|
|
||||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
|
||||||
SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \
|
|
||||||
php_cpp_static
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean
|
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean
|
||||||
|
|
|
||||||
|
|
@ -16,11 +16,5 @@ build:
|
||||||
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
|
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
|
||||||
php
|
php
|
||||||
|
|
||||||
static:
|
|
||||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \
|
|
||||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
|
||||||
SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \
|
|
||||||
php_static
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean
|
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean
|
||||||
|
|
|
||||||
|
|
@ -16,11 +16,5 @@ build:
|
||||||
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
|
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
|
||||||
php
|
php
|
||||||
|
|
||||||
static:
|
|
||||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \
|
|
||||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
|
||||||
SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \
|
|
||||||
php_static
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean
|
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean
|
||||||
|
|
|
||||||
|
|
@ -16,11 +16,5 @@ build:
|
||||||
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
|
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
|
||||||
php_cpp
|
php_cpp
|
||||||
|
|
||||||
static:
|
|
||||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \
|
|
||||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
|
||||||
SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \
|
|
||||||
php_cpp_static
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean
|
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean
|
||||||
|
|
|
||||||
|
|
@ -16,11 +16,5 @@ build:
|
||||||
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
|
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
|
||||||
php_cpp
|
php_cpp
|
||||||
|
|
||||||
static:
|
|
||||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \
|
|
||||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
|
||||||
SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \
|
|
||||||
php_cpp_static
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean
|
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean
|
||||||
|
|
|
||||||
|
|
@ -15,10 +15,5 @@ build:
|
||||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||||
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' php_cpp
|
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' php_cpp
|
||||||
|
|
||||||
static:
|
|
||||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' $(SWIGLIB) CXXSRCS='$(CXXSRCS)' \
|
|
||||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
|
||||||
SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' php_cpp_static
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean
|
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean
|
||||||
|
|
|
||||||
|
|
@ -16,11 +16,5 @@ build:
|
||||||
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
|
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
|
||||||
php
|
php
|
||||||
|
|
||||||
static:
|
|
||||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \
|
|
||||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
|
||||||
SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \
|
|
||||||
php_static
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean
|
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean
|
||||||
|
|
|
||||||
|
|
@ -16,11 +16,5 @@ build:
|
||||||
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
|
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
|
||||||
php_cpp
|
php_cpp
|
||||||
|
|
||||||
static:
|
|
||||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \
|
|
||||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
|
||||||
SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \
|
|
||||||
php_cpp_static
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean
|
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean
|
||||||
|
|
|
||||||
|
|
@ -16,11 +16,5 @@ build:
|
||||||
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
|
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
|
||||||
php
|
php
|
||||||
|
|
||||||
static:
|
|
||||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \
|
|
||||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
|
||||||
SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \
|
|
||||||
php_static
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean
|
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean
|
||||||
|
|
|
||||||
|
|
@ -16,11 +16,5 @@ build:
|
||||||
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
|
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
|
||||||
php
|
php
|
||||||
|
|
||||||
static:
|
|
||||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \
|
|
||||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
|
||||||
SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \
|
|
||||||
php_static
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean
|
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean
|
||||||
|
|
|
||||||
|
|
@ -16,11 +16,5 @@ build:
|
||||||
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
|
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
|
||||||
php_cpp
|
php_cpp
|
||||||
|
|
||||||
static:
|
|
||||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \
|
|
||||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
|
||||||
SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \
|
|
||||||
php_cpp_static
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean
|
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean
|
||||||
|
|
|
||||||
|
|
@ -16,11 +16,5 @@ build:
|
||||||
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
|
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
|
||||||
php_cpp
|
php_cpp
|
||||||
|
|
||||||
static:
|
|
||||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \
|
|
||||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
|
||||||
SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \
|
|
||||||
php_cpp_static
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean
|
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean
|
||||||
|
|
|
||||||
|
|
@ -16,11 +16,5 @@ build:
|
||||||
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
|
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
|
||||||
php
|
php
|
||||||
|
|
||||||
static:
|
|
||||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \
|
|
||||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
|
||||||
SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \
|
|
||||||
php_static
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean
|
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean
|
||||||
|
|
|
||||||
|
|
@ -16,11 +16,5 @@ build:
|
||||||
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
|
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
|
||||||
php_cpp
|
php_cpp
|
||||||
|
|
||||||
static:
|
|
||||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \
|
|
||||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
|
||||||
SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \
|
|
||||||
php_cpp_static
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean
|
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean
|
||||||
|
|
|
||||||
|
|
@ -16,11 +16,5 @@ build:
|
||||||
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
|
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
|
||||||
php
|
php
|
||||||
|
|
||||||
static:
|
|
||||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \
|
|
||||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
|
||||||
SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \
|
|
||||||
php_static
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean
|
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean
|
||||||
|
|
|
||||||
|
|
@ -16,11 +16,5 @@ build:
|
||||||
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
|
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
|
||||||
php
|
php
|
||||||
|
|
||||||
static:
|
|
||||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \
|
|
||||||
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
|
||||||
SWIGOPT='$(SWIGOPT)' TARGET='myphp' INTERFACE='$(INTERFACE)' \
|
|
||||||
php_static
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean
|
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php_clean
|
||||||
|
|
|
||||||
19
Examples/php5/callback/Makefile
Normal file
19
Examples/php5/callback/Makefile
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
TOP = ../..
|
||||||
|
SWIGEXE = $(TOP)/../swig
|
||||||
|
SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
|
||||||
|
CXXSRCS = example.cxx
|
||||||
|
TARGET = example
|
||||||
|
INTERFACE = example.i
|
||||||
|
LIBS = -lm
|
||||||
|
SWIGOPT =
|
||||||
|
|
||||||
|
check: build
|
||||||
|
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php5_run
|
||||||
|
|
||||||
|
build:
|
||||||
|
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' $(SWIGLIB) CXXSRCS='$(CXXSRCS)' \
|
||||||
|
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||||
|
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' php5_cpp
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php5_clean
|
||||||
4
Examples/php5/callback/example.cxx
Normal file
4
Examples/php5/callback/example.cxx
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
/* File : example.cxx */
|
||||||
|
|
||||||
|
#include "example.h"
|
||||||
|
|
||||||
22
Examples/php5/callback/example.h
Normal file
22
Examples/php5/callback/example.h
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
/* File : example.h */
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
class Callback {
|
||||||
|
public:
|
||||||
|
virtual ~Callback() { std::cout << "Callback::~Callback()" << std:: endl; }
|
||||||
|
virtual void run() { std::cout << "Callback::run()" << std::endl; }
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class Caller {
|
||||||
|
private:
|
||||||
|
Callback *_callback;
|
||||||
|
public:
|
||||||
|
Caller(): _callback(0) {}
|
||||||
|
~Caller() { delCallback(); }
|
||||||
|
void delCallback() { delete _callback; _callback = 0; }
|
||||||
|
void setCallback(Callback *cb) { delCallback(); _callback = cb; }
|
||||||
|
void call() { if (_callback) _callback->run(); }
|
||||||
|
};
|
||||||
|
|
||||||
11
Examples/php5/callback/example.i
Normal file
11
Examples/php5/callback/example.i
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
/* File : example.i */
|
||||||
|
%module(directors="1") example
|
||||||
|
%{
|
||||||
|
#include "example.h"
|
||||||
|
%}
|
||||||
|
|
||||||
|
/* turn on director wrapping Callback */
|
||||||
|
%feature("director") Callback;
|
||||||
|
|
||||||
|
%include "example.h"
|
||||||
|
|
||||||
19
Examples/php5/callback/index.html
Normal file
19
Examples/php5/callback/index.html
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>SWIG:Examples:php5:callback</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body bgcolor="#ffffff">
|
||||||
|
|
||||||
|
|
||||||
|
<tt>SWIG/Examples/php5/callback/</tt>
|
||||||
|
<hr>
|
||||||
|
|
||||||
|
<H2>Implementing C++ callbacks in PHP5</H2>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
This example illustrates how to use directors to implement C++ callbacks in PHP5.
|
||||||
|
|
||||||
|
<hr>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
47
Examples/php5/callback/runme.php
Normal file
47
Examples/php5/callback/runme.php
Normal file
|
|
@ -0,0 +1,47 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
# This file illustrates the cross language polymorphism using directors.
|
||||||
|
|
||||||
|
require("example.php");
|
||||||
|
|
||||||
|
# Class, which overwrites Callback::run().
|
||||||
|
|
||||||
|
class PhpCallback extends Callback {
|
||||||
|
function run() {
|
||||||
|
print "PhpCallback.run()\n";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
# Create an Caller instance
|
||||||
|
|
||||||
|
$caller = new Caller();
|
||||||
|
|
||||||
|
# Add a simple C++ callback (caller owns the callback, so
|
||||||
|
# we disown it first by clearing the .thisown flag).
|
||||||
|
|
||||||
|
print "Adding and calling a normal C++ callback\n";
|
||||||
|
print "----------------------------------------\n";
|
||||||
|
|
||||||
|
$callback = new Callback();
|
||||||
|
$callback->thisown = 0;
|
||||||
|
$caller->setCallback($callback);
|
||||||
|
$caller->call();
|
||||||
|
$caller->delCallback();
|
||||||
|
|
||||||
|
print "\n";
|
||||||
|
print "Adding and calling a PHP callback\n";
|
||||||
|
print "------------------------------------\n";
|
||||||
|
|
||||||
|
# Add a PHP callback.
|
||||||
|
|
||||||
|
$callback = new PhpCallback();
|
||||||
|
$callback->thisown = 0;
|
||||||
|
$caller->setCallback($callback);
|
||||||
|
$caller->call();
|
||||||
|
$caller->delCallback();
|
||||||
|
|
||||||
|
# All done.
|
||||||
|
|
||||||
|
print "php exit\n";
|
||||||
|
|
||||||
|
?>
|
||||||
19
Examples/php5/check.list
Normal file
19
Examples/php5/check.list
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
# see top-level Makefile.in
|
||||||
|
# (see also top-level configure.ac kludge)
|
||||||
|
callback
|
||||||
|
class
|
||||||
|
constants
|
||||||
|
cpointer
|
||||||
|
disown
|
||||||
|
enum
|
||||||
|
extend
|
||||||
|
funcptr
|
||||||
|
overloading
|
||||||
|
pointer
|
||||||
|
pragmas
|
||||||
|
proxy
|
||||||
|
reference
|
||||||
|
simple
|
||||||
|
sync
|
||||||
|
value
|
||||||
|
variables
|
||||||
20
Examples/php5/class/Makefile
Normal file
20
Examples/php5/class/Makefile
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
TOP = ../..
|
||||||
|
SWIGEXE = $(TOP)/../swig
|
||||||
|
SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
|
||||||
|
CXXSRCS = example.cxx
|
||||||
|
TARGET = example
|
||||||
|
INTERFACE = example.i
|
||||||
|
LIBS =
|
||||||
|
SWIGOPT =
|
||||||
|
|
||||||
|
check: build
|
||||||
|
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php5_run
|
||||||
|
|
||||||
|
build:
|
||||||
|
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \
|
||||||
|
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||||
|
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
|
||||||
|
php5_cpp
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php5_clean
|
||||||
28
Examples/php5/class/example.cxx
Normal file
28
Examples/php5/class/example.cxx
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
/* File : example.cxx */
|
||||||
|
|
||||||
|
#include "example.h"
|
||||||
|
#define M_PI 3.14159265358979323846
|
||||||
|
|
||||||
|
/* Move the shape to a new location */
|
||||||
|
void Shape::move(double dx, double dy) {
|
||||||
|
x += dx;
|
||||||
|
y += dy;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Shape::nshapes = 0;
|
||||||
|
|
||||||
|
double Circle::area() {
|
||||||
|
return M_PI*radius*radius;
|
||||||
|
}
|
||||||
|
|
||||||
|
double Circle::perimeter() {
|
||||||
|
return 2*M_PI*radius;
|
||||||
|
}
|
||||||
|
|
||||||
|
double Square::area() {
|
||||||
|
return width*width;
|
||||||
|
}
|
||||||
|
|
||||||
|
double Square::perimeter() {
|
||||||
|
return 4*width;
|
||||||
|
}
|
||||||
34
Examples/php5/class/example.h
Normal file
34
Examples/php5/class/example.h
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
/* File : example.h */
|
||||||
|
|
||||||
|
class Shape {
|
||||||
|
public:
|
||||||
|
Shape() {
|
||||||
|
nshapes++;
|
||||||
|
}
|
||||||
|
virtual ~Shape() {
|
||||||
|
nshapes--;
|
||||||
|
}
|
||||||
|
double x, y;
|
||||||
|
void move(double dx, double dy);
|
||||||
|
virtual double area() = 0;
|
||||||
|
virtual double perimeter() = 0;
|
||||||
|
static int nshapes;
|
||||||
|
};
|
||||||
|
|
||||||
|
class Circle : public Shape {
|
||||||
|
private:
|
||||||
|
double radius;
|
||||||
|
public:
|
||||||
|
Circle(double r) : radius(r) { }
|
||||||
|
virtual double area();
|
||||||
|
virtual double perimeter();
|
||||||
|
};
|
||||||
|
|
||||||
|
class Square : public Shape {
|
||||||
|
private:
|
||||||
|
double width;
|
||||||
|
public:
|
||||||
|
Square(double w) : width(w) { }
|
||||||
|
virtual double area();
|
||||||
|
virtual double perimeter();
|
||||||
|
};
|
||||||
9
Examples/php5/class/example.i
Normal file
9
Examples/php5/class/example.i
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
/* File : example.i */
|
||||||
|
%module example
|
||||||
|
|
||||||
|
%{
|
||||||
|
#include "example.h"
|
||||||
|
%}
|
||||||
|
|
||||||
|
/* Let's just grab the original header file here */
|
||||||
|
%include "example.h"
|
||||||
60
Examples/php5/class/runme.php
Normal file
60
Examples/php5/class/runme.php
Normal file
|
|
@ -0,0 +1,60 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
# This example illustrates how member variables are wrapped.
|
||||||
|
|
||||||
|
require("example.php");
|
||||||
|
|
||||||
|
# ----- Object creation -----
|
||||||
|
|
||||||
|
print "Creating some objects:\n";
|
||||||
|
$c = new Circle(10);
|
||||||
|
print " Created circle\n";
|
||||||
|
$s = new Square(10);
|
||||||
|
print " Created square\n";
|
||||||
|
|
||||||
|
# ----- Access a static member -----
|
||||||
|
|
||||||
|
print "\nA total of " . Shape::nshapes() . " shapes were created\n";
|
||||||
|
|
||||||
|
# ----- Member data access -----
|
||||||
|
|
||||||
|
# Set the location of the object.
|
||||||
|
# Note: methods in the base class Shape are used since
|
||||||
|
# x and y are defined there.
|
||||||
|
|
||||||
|
$c->x = 20;
|
||||||
|
$c->y = 30;
|
||||||
|
$s->x = -10;
|
||||||
|
$s->y = 5;
|
||||||
|
|
||||||
|
print "\nHere is their current position:\n";
|
||||||
|
print " Circle = ({$c->x},{$c->y})\n";
|
||||||
|
print " Square = ({$s->x},{$s->y})\n";
|
||||||
|
|
||||||
|
# ----- Call some methods -----
|
||||||
|
|
||||||
|
# Notice how the Shape_area() and Shape_perimeter() functions really
|
||||||
|
# invoke the appropriate virtual method on each object.
|
||||||
|
print "\nHere are some properties of the shapes:\n";
|
||||||
|
foreach (array($c,$s) as $o) {
|
||||||
|
print " ". get_class($o) . "\n";
|
||||||
|
print " area = {$o->area()}\n";
|
||||||
|
print " perimeter = {$o->perimeter()}\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
# ----- Delete everything -----
|
||||||
|
|
||||||
|
print "\nGuess I'll clean up now\n";
|
||||||
|
|
||||||
|
# Note: this invokes the virtual destructor
|
||||||
|
$c = NULL;
|
||||||
|
$s = NULL;
|
||||||
|
|
||||||
|
# and don't forget the $o from the for loop above. It still refers to
|
||||||
|
# the square.
|
||||||
|
$o = NULL;
|
||||||
|
|
||||||
|
print Shape::nshapes() . " shapes remain\n";
|
||||||
|
print "Goodbye\n";
|
||||||
|
|
||||||
|
?>
|
||||||
20
Examples/php5/constants/Makefile
Normal file
20
Examples/php5/constants/Makefile
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
TOP = ../..
|
||||||
|
SWIGEXE = $(TOP)/../swig
|
||||||
|
SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
|
||||||
|
SRCS =
|
||||||
|
TARGET = example
|
||||||
|
INTERFACE = example.i
|
||||||
|
LIBS =
|
||||||
|
SWIGOPT =
|
||||||
|
|
||||||
|
check: build
|
||||||
|
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php5_run
|
||||||
|
|
||||||
|
build:
|
||||||
|
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \
|
||||||
|
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||||
|
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
|
||||||
|
php5
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php5_clean
|
||||||
26
Examples/php5/constants/example.i
Normal file
26
Examples/php5/constants/example.i
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
/* File : example.i */
|
||||||
|
%module example
|
||||||
|
|
||||||
|
/* A few preprocessor macros */
|
||||||
|
|
||||||
|
#define ICONST 42
|
||||||
|
#define FCONST 2.1828
|
||||||
|
#define CCONST 'x'
|
||||||
|
#define CCONST2 '\n'
|
||||||
|
#define SCONST "Hello World"
|
||||||
|
#define SCONST2 "\"Hello World\""
|
||||||
|
|
||||||
|
/* This should work just fine */
|
||||||
|
#define EXPR ICONST + 3*(FCONST)
|
||||||
|
|
||||||
|
/* This shouldn't do anything */
|
||||||
|
#define EXTERN extern
|
||||||
|
|
||||||
|
/* Neither should this (BAR isn't defined) */
|
||||||
|
#define FOO (ICONST + BAR)
|
||||||
|
|
||||||
|
/* The following statements also produce constants */
|
||||||
|
%constant int iconst = 37;
|
||||||
|
%constant double fconst = 3.14;
|
||||||
|
|
||||||
|
|
||||||
28
Examples/php5/constants/runme.php
Normal file
28
Examples/php5/constants/runme.php
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
require "example.php";
|
||||||
|
|
||||||
|
print "ICONST = " . ICONST . " (should be 42)\n";
|
||||||
|
print "FCONST = " . FCONST . " (should be 2.1828)\n";
|
||||||
|
print "CCONST = " . CCONST . " (should be 'x')\n";
|
||||||
|
print "CCONST2 = " . CCONST2 . " (this should be on a new line)\n";
|
||||||
|
print "SCONST = " . SCONST . " (should be 'Hello World')\n";
|
||||||
|
print "SCONST2 = " . SCONST2 . " (should be '\"Hello World\"')\n";
|
||||||
|
print "EXPR = " . EXPR . " (should be 48.5484)\n";
|
||||||
|
print "iconst = " . iconst . " (should be 37)\n";
|
||||||
|
print "fconst = " . fconst . " (should be 3.14)\n";
|
||||||
|
|
||||||
|
if (EXTERN!="EXTERN") {
|
||||||
|
print "EXTERN = " . EXTERN . " (Arg! This shouldn't print anything)\n";
|
||||||
|
} else {
|
||||||
|
print "EXTERN defaults to 'EXTERN', it probably isn't defined (good)\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (FOO!="FOO") {
|
||||||
|
print "FOO = " . FOO . "(Arg! This shouldn't print anything)\n";
|
||||||
|
} else {
|
||||||
|
print "FOO defaults to 'FOO', it probably isn't defined (good)\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
20
Examples/php5/cpointer/Makefile
Normal file
20
Examples/php5/cpointer/Makefile
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
TOP = ../..
|
||||||
|
SWIGEXE = $(TOP)/../swig
|
||||||
|
SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
|
||||||
|
SRCS = example.c
|
||||||
|
TARGET = example
|
||||||
|
INTERFACE = example.i
|
||||||
|
LIBS =
|
||||||
|
SWIGOPT =
|
||||||
|
|
||||||
|
check: build
|
||||||
|
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php5_run
|
||||||
|
|
||||||
|
build:
|
||||||
|
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \
|
||||||
|
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||||
|
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
|
||||||
|
php5
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php5_clean
|
||||||
16
Examples/php5/cpointer/example.c
Normal file
16
Examples/php5/cpointer/example.c
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
/* File : example.c */
|
||||||
|
|
||||||
|
void add(int *x, int *y, int *result) {
|
||||||
|
*result = *x + *y;
|
||||||
|
}
|
||||||
|
|
||||||
|
void sub(int *x, int *y, int *result) {
|
||||||
|
*result = *x - *y;
|
||||||
|
}
|
||||||
|
|
||||||
|
int divide(int n, int d, int *r) {
|
||||||
|
int q;
|
||||||
|
q = n/d;
|
||||||
|
*r = n - q*d;
|
||||||
|
return q;
|
||||||
|
}
|
||||||
31
Examples/php5/cpointer/example.i
Normal file
31
Examples/php5/cpointer/example.i
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
/* File : example.i */
|
||||||
|
%module example
|
||||||
|
|
||||||
|
%{
|
||||||
|
extern void add(int *, int *, int *);
|
||||||
|
extern void sub(int *, int *, int *);
|
||||||
|
%}
|
||||||
|
|
||||||
|
/* This example illustrates a couple of different techniques
|
||||||
|
for manipulating C pointers */
|
||||||
|
|
||||||
|
/* First we'll use the pointer library */
|
||||||
|
extern void add(int *x, int *y, int *result);
|
||||||
|
|
||||||
|
%include cpointer.i
|
||||||
|
%pointer_functions(int, intp);
|
||||||
|
|
||||||
|
/* Next we'll use some typemaps */
|
||||||
|
|
||||||
|
%include typemaps.i
|
||||||
|
extern void sub(int *INPUT, int *INPUT, int *OUTPUT);
|
||||||
|
|
||||||
|
/* Next we'll use typemaps and the %apply directive */
|
||||||
|
|
||||||
|
//%apply int *OUTPUT { int *r };
|
||||||
|
//extern int divide(int n, int d, int *r);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
47
Examples/php5/cpointer/runme.php
Normal file
47
Examples/php5/cpointer/runme.php
Normal file
|
|
@ -0,0 +1,47 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
require "example.php";
|
||||||
|
|
||||||
|
# First create some objects using the pointer library.
|
||||||
|
|
||||||
|
print "Testing the pointer library\n";
|
||||||
|
|
||||||
|
$a = example::new_intp();
|
||||||
|
$b = example::new_intp();
|
||||||
|
$c = example::new_intp();
|
||||||
|
example::intp_assign($a,37);
|
||||||
|
example::intp_assign($b,42);
|
||||||
|
|
||||||
|
print " a = $a\n";
|
||||||
|
print " b = $b\n";
|
||||||
|
print " c = $c\n";
|
||||||
|
|
||||||
|
# Call the add() function wuth some pointers
|
||||||
|
example::add($a,$b,$c);
|
||||||
|
|
||||||
|
# Now get the result
|
||||||
|
$r = example::intp_value($c);
|
||||||
|
|
||||||
|
print " 37 + 42 = $r\n";
|
||||||
|
|
||||||
|
# Clean up the pointers
|
||||||
|
example::delete_intp($a);
|
||||||
|
example::delete_intp($b);
|
||||||
|
example::delete_intp($c);
|
||||||
|
|
||||||
|
# Now try the typemap library
|
||||||
|
# This should be much easier. Now how it is no longer
|
||||||
|
# necessary to manufacture pointers.
|
||||||
|
|
||||||
|
print "Trying the typemap library\n";
|
||||||
|
$r = example::sub(37,42);
|
||||||
|
print " 37 - 42 = $r\n";
|
||||||
|
|
||||||
|
# Now try the version with multiple return values
|
||||||
|
# print "Testing multiple return values\n";
|
||||||
|
# $a = example::divide(42,37);
|
||||||
|
# $q = $a[0]
|
||||||
|
# $r = $a[1]
|
||||||
|
# print " 42/37 = $q remainder $r\n";
|
||||||
|
|
||||||
|
?>
|
||||||
20
Examples/php5/disown/Makefile
Normal file
20
Examples/php5/disown/Makefile
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
TOP = ../..
|
||||||
|
SWIGEXE = $(TOP)/../swig
|
||||||
|
SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
|
||||||
|
CXXSRCS = example.cxx
|
||||||
|
TARGET = example
|
||||||
|
INTERFACE = example.i
|
||||||
|
LIBS =
|
||||||
|
SWIGOPT =
|
||||||
|
|
||||||
|
check: build
|
||||||
|
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php5_run
|
||||||
|
|
||||||
|
build:
|
||||||
|
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \
|
||||||
|
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||||
|
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
|
||||||
|
php5_cpp
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php5_clean
|
||||||
51
Examples/php5/disown/example.cxx
Normal file
51
Examples/php5/disown/example.cxx
Normal file
|
|
@ -0,0 +1,51 @@
|
||||||
|
/* File : example.c */
|
||||||
|
|
||||||
|
#include "example.h"
|
||||||
|
#include <math.h>
|
||||||
|
#ifndef M_PI
|
||||||
|
# define M_PI 3.14159265358979323846
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int Shape::get_nshapes() {
|
||||||
|
return nshapes;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Move the shape to a new location */
|
||||||
|
void Shape::move(double dx, double dy) {
|
||||||
|
x += dx;
|
||||||
|
y += dy;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Shape::nshapes = 0;
|
||||||
|
|
||||||
|
void Circle::set_radius( double r ) {
|
||||||
|
radius = r;
|
||||||
|
}
|
||||||
|
|
||||||
|
double Circle::area(void) {
|
||||||
|
return M_PI*radius*radius;
|
||||||
|
}
|
||||||
|
|
||||||
|
double Circle::perimeter(void) {
|
||||||
|
return 2*M_PI*radius;
|
||||||
|
}
|
||||||
|
|
||||||
|
double Square::area(void) {
|
||||||
|
return width*width;
|
||||||
|
}
|
||||||
|
|
||||||
|
double Square::perimeter(void) {
|
||||||
|
return 4*width;
|
||||||
|
}
|
||||||
|
|
||||||
|
ShapeContainer::~ShapeContainer() {
|
||||||
|
iterator i=shapes.begin();
|
||||||
|
for( iterator i = shapes.begin(); i != shapes.end(); ++i ) {
|
||||||
|
delete *i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ShapeContainer::addShape( Shape *s ) {
|
||||||
|
shapes.push_back( s );
|
||||||
|
}
|
||||||
50
Examples/php5/disown/example.h
Normal file
50
Examples/php5/disown/example.h
Normal file
|
|
@ -0,0 +1,50 @@
|
||||||
|
/* File : example.h */
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
class Shape {
|
||||||
|
public:
|
||||||
|
Shape() {
|
||||||
|
nshapes++;
|
||||||
|
}
|
||||||
|
virtual ~Shape() {
|
||||||
|
nshapes--;
|
||||||
|
}
|
||||||
|
double x, y;
|
||||||
|
void move(double dx, double dy);
|
||||||
|
virtual double area(void) = 0;
|
||||||
|
virtual double perimeter(void) = 0;
|
||||||
|
static int nshapes;
|
||||||
|
static int get_nshapes();
|
||||||
|
};
|
||||||
|
|
||||||
|
class Circle : public Shape {
|
||||||
|
private:
|
||||||
|
double radius;
|
||||||
|
public:
|
||||||
|
Circle(double r) : radius(r) { }
|
||||||
|
~Circle() { }
|
||||||
|
void set_radius( double r );
|
||||||
|
virtual double area(void);
|
||||||
|
virtual double perimeter(void);
|
||||||
|
};
|
||||||
|
|
||||||
|
class Square : public Shape {
|
||||||
|
private:
|
||||||
|
double width;
|
||||||
|
public:
|
||||||
|
Square(double w) : width(w) { }
|
||||||
|
~Square() { }
|
||||||
|
virtual double area(void);
|
||||||
|
virtual double perimeter(void);
|
||||||
|
};
|
||||||
|
|
||||||
|
class ShapeContainer {
|
||||||
|
private:
|
||||||
|
typedef std::vector<Shape*>::iterator iterator;
|
||||||
|
std::vector<Shape*> shapes;
|
||||||
|
public:
|
||||||
|
ShapeContainer() : shapes() {}
|
||||||
|
~ShapeContainer();
|
||||||
|
void addShape( Shape *s );
|
||||||
|
};
|
||||||
12
Examples/php5/disown/example.i
Normal file
12
Examples/php5/disown/example.i
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
/* File : example.i */
|
||||||
|
%module example
|
||||||
|
|
||||||
|
%{
|
||||||
|
#include "example.h"
|
||||||
|
%}
|
||||||
|
|
||||||
|
%apply SWIGTYPE *DISOWN {(Shape *s)};
|
||||||
|
|
||||||
|
/* Let's just grab the original header file here */
|
||||||
|
%include "example.h"
|
||||||
|
|
||||||
49
Examples/php5/disown/runme.php
Normal file
49
Examples/php5/disown/runme.php
Normal file
|
|
@ -0,0 +1,49 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
# This file illustrates the low-level C++ interface
|
||||||
|
# created by SWIG. In this case, all of our C++ classes
|
||||||
|
# get converted into function calls.
|
||||||
|
|
||||||
|
require("example.php");
|
||||||
|
|
||||||
|
# ----- Object creation -----
|
||||||
|
|
||||||
|
print "Creating some objects:\n";
|
||||||
|
$c = new Circle(10);
|
||||||
|
print " Created circle \$c\n";
|
||||||
|
$s = new Square(10);
|
||||||
|
print " Created square \$s\n";
|
||||||
|
|
||||||
|
# ----- Create the ShapeContainer ----
|
||||||
|
|
||||||
|
$container = new ShapeContainer();
|
||||||
|
|
||||||
|
$container->addShape($c);
|
||||||
|
$container->addShape($s);
|
||||||
|
|
||||||
|
# ----- Access a static member -----
|
||||||
|
|
||||||
|
print "\nA total of " . Shape::nshapes() . " shapes were created\n";
|
||||||
|
|
||||||
|
# ----- Delete by the old references -----
|
||||||
|
# This should not truely delete the shapes because they are now owned
|
||||||
|
# by the ShapeContainer.
|
||||||
|
|
||||||
|
print "Delete the old references.";
|
||||||
|
|
||||||
|
# Note: this invokes the virtual destructor
|
||||||
|
$c = NULL;
|
||||||
|
$s = NULL;
|
||||||
|
|
||||||
|
print "\nA total of " . Shape::nshapes() . " shapes remain\n";
|
||||||
|
|
||||||
|
# ----- Delete by the container -----
|
||||||
|
# This should truely delete the shapes
|
||||||
|
|
||||||
|
print "Delete the container.";
|
||||||
|
$container = NULL;
|
||||||
|
print "\nA total of " . Shape::nshapes() . " shapes remain\n";
|
||||||
|
|
||||||
|
print "Goodbye\n";
|
||||||
|
|
||||||
|
?>
|
||||||
20
Examples/php5/enum/Makefile
Normal file
20
Examples/php5/enum/Makefile
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
TOP = ../..
|
||||||
|
SWIGEXE = $(TOP)/../swig
|
||||||
|
SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
|
||||||
|
CXXSRCS = example.cxx
|
||||||
|
TARGET = example
|
||||||
|
INTERFACE = example.i
|
||||||
|
LIBS =
|
||||||
|
SWIGOPT = -noproxy
|
||||||
|
|
||||||
|
check: build
|
||||||
|
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php5_run
|
||||||
|
|
||||||
|
build:
|
||||||
|
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \
|
||||||
|
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||||
|
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
|
||||||
|
php5_cpp
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php5_clean
|
||||||
37
Examples/php5/enum/example.cxx
Normal file
37
Examples/php5/enum/example.cxx
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
/* File : example.cxx */
|
||||||
|
|
||||||
|
#include "example.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
void Foo::enum_test(speed s) {
|
||||||
|
if (s == IMPULSE) {
|
||||||
|
printf("IMPULSE speed\n");
|
||||||
|
} else if (s == WARP) {
|
||||||
|
printf("WARP speed\n");
|
||||||
|
} else if (s == LUDICROUS) {
|
||||||
|
printf("LUDICROUS speed\n");
|
||||||
|
} else {
|
||||||
|
printf("Unknown speed\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void enum_test(color c, Foo::speed s) {
|
||||||
|
if (c == RED) {
|
||||||
|
printf("color = RED, ");
|
||||||
|
} else if (c == BLUE) {
|
||||||
|
printf("color = BLUE, ");
|
||||||
|
} else if (c == GREEN) {
|
||||||
|
printf("color = GREEN, ");
|
||||||
|
} else {
|
||||||
|
printf("color = Unknown color!, ");
|
||||||
|
}
|
||||||
|
if (s == Foo::IMPULSE) {
|
||||||
|
printf("speed = IMPULSE speed\n");
|
||||||
|
} else if (s == Foo::WARP) {
|
||||||
|
printf("speed = WARP speed\n");
|
||||||
|
} else if (s == Foo::LUDICROUS) {
|
||||||
|
printf("speed = LUDICROUS speed\n");
|
||||||
|
} else {
|
||||||
|
printf("speed = Unknown speed!\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
13
Examples/php5/enum/example.h
Normal file
13
Examples/php5/enum/example.h
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
/* File : example.h */
|
||||||
|
|
||||||
|
enum color { RED, BLUE, GREEN };
|
||||||
|
|
||||||
|
class Foo {
|
||||||
|
public:
|
||||||
|
Foo() { }
|
||||||
|
enum speed { IMPULSE, WARP, LUDICROUS };
|
||||||
|
void enum_test(speed s);
|
||||||
|
};
|
||||||
|
|
||||||
|
void enum_test(color c, Foo::speed s);
|
||||||
|
|
||||||
12
Examples/php5/enum/example.i
Normal file
12
Examples/php5/enum/example.i
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
/* File : example.i */
|
||||||
|
%module example
|
||||||
|
|
||||||
|
%{
|
||||||
|
#include "example.h"
|
||||||
|
%}
|
||||||
|
|
||||||
|
|
||||||
|
/* Let's just grab the original header file here */
|
||||||
|
|
||||||
|
%include "example.h"
|
||||||
|
|
||||||
32
Examples/php5/enum/runme.php
Normal file
32
Examples/php5/enum/runme.php
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
require "example.php";
|
||||||
|
|
||||||
|
# ----- Object creation -----
|
||||||
|
|
||||||
|
# Print out the value of some enums
|
||||||
|
print "*** color ***";
|
||||||
|
print " RED =" . RED;
|
||||||
|
print " BLUE =" . BLUE;
|
||||||
|
print " GREEN =" . GREEN;
|
||||||
|
|
||||||
|
print "\n*** Foo::speed ***";
|
||||||
|
print " Foo_IMPULSE =" . Foo_IMPULSE;
|
||||||
|
print " Foo_WARP =" . Foo_WARP;
|
||||||
|
print " Foo_LUDICROUS =" . Foo_LUDICROUS;
|
||||||
|
|
||||||
|
print "\nTesting use of enums with functions\n";
|
||||||
|
|
||||||
|
enum_test(RED, Foo_IMPULSE);
|
||||||
|
enum_test(BLUE, Foo_WARP);
|
||||||
|
enum_test(GREEN, Foo_LUDICROUS);
|
||||||
|
enum_test(1234,5678);
|
||||||
|
|
||||||
|
print "\nTesting use of enum with class method\n";
|
||||||
|
$f = new_Foo();
|
||||||
|
|
||||||
|
Foo_enum_test($f,Foo_IMPULSE);
|
||||||
|
Foo_enum_test($f,Foo_WARP);
|
||||||
|
Foo_enum_test($f,Foo_LUDICROUS);
|
||||||
|
|
||||||
|
?>
|
||||||
19
Examples/php5/extend/Makefile
Normal file
19
Examples/php5/extend/Makefile
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
TOP = ../..
|
||||||
|
SWIGEXE = $(TOP)/../swig
|
||||||
|
SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
|
||||||
|
CXXSRCS = example.cxx
|
||||||
|
TARGET = example
|
||||||
|
INTERFACE = example.i
|
||||||
|
LIBS = -lm
|
||||||
|
SWIGOPT =
|
||||||
|
|
||||||
|
check: build
|
||||||
|
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php5_run
|
||||||
|
|
||||||
|
build:
|
||||||
|
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' $(SWIGLIB) CXXSRCS='$(CXXSRCS)' \
|
||||||
|
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||||
|
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' php5_cpp
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php5_clean
|
||||||
4
Examples/php5/extend/example.cxx
Normal file
4
Examples/php5/extend/example.cxx
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
/* File : example.cxx */
|
||||||
|
|
||||||
|
#include "example.h"
|
||||||
|
|
||||||
56
Examples/php5/extend/example.h
Normal file
56
Examples/php5/extend/example.h
Normal file
|
|
@ -0,0 +1,56 @@
|
||||||
|
/* File : example.h */
|
||||||
|
|
||||||
|
#include <cstdio>
|
||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
|
class Employee {
|
||||||
|
private:
|
||||||
|
std::string name;
|
||||||
|
public:
|
||||||
|
Employee(const char* n): name(n) {}
|
||||||
|
virtual std::string getTitle() { return getPosition() + " " + getName(); }
|
||||||
|
virtual std::string getName() { return name; }
|
||||||
|
virtual std::string getPosition() const { return "Employee"; }
|
||||||
|
virtual ~Employee() { printf("~Employee() @ %p\n", (void *)this); }
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class Manager: public Employee {
|
||||||
|
public:
|
||||||
|
Manager(const char* n): Employee(n) {}
|
||||||
|
virtual std::string getPosition() const { return "Manager"; }
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class EmployeeList {
|
||||||
|
std::vector<Employee*> list;
|
||||||
|
public:
|
||||||
|
EmployeeList() {
|
||||||
|
list.push_back(new Employee("Bob"));
|
||||||
|
list.push_back(new Employee("Jane"));
|
||||||
|
list.push_back(new Manager("Ted"));
|
||||||
|
}
|
||||||
|
void addEmployee(Employee *p) {
|
||||||
|
list.push_back(p);
|
||||||
|
std::cout << "New employee added. Current employees are:" << std::endl;
|
||||||
|
std::vector<Employee*>::iterator i;
|
||||||
|
for (i=list.begin(); i!=list.end(); i++) {
|
||||||
|
std::cout << " " << (*i)->getTitle() << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const Employee *get_item(int i) {
|
||||||
|
return list[i];
|
||||||
|
}
|
||||||
|
~EmployeeList() {
|
||||||
|
std::vector<Employee*>::iterator i;
|
||||||
|
std::cout << "~EmployeeList, deleting " << list.size() << " employees." << std::endl;
|
||||||
|
for (i=list.begin(); i!=list.end(); i++) {
|
||||||
|
delete *i;
|
||||||
|
}
|
||||||
|
std::cout << "~EmployeeList empty." << std::endl;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
15
Examples/php5/extend/example.i
Normal file
15
Examples/php5/extend/example.i
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
/* File : example.i */
|
||||||
|
%module(directors="1") example
|
||||||
|
%{
|
||||||
|
#include "example.h"
|
||||||
|
%}
|
||||||
|
|
||||||
|
%include "std_vector.i"
|
||||||
|
%include "std_string.i"
|
||||||
|
|
||||||
|
/* turn on director wrapping for Manager */
|
||||||
|
%feature("director") Employee;
|
||||||
|
%feature("director") Manager;
|
||||||
|
|
||||||
|
%include "example.h"
|
||||||
|
|
||||||
19
Examples/php5/extend/index.html
Normal file
19
Examples/php5/extend/index.html
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>SWIG:Examples:php:extend</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body bgcolor="#ffffff">
|
||||||
|
|
||||||
|
|
||||||
|
<tt>SWIG/Examples/php/extend/</tt>
|
||||||
|
<hr>
|
||||||
|
|
||||||
|
<H2>Extending a simple C++ class in PHP</H2>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
This example illustrates the extending of a C++ class with cross language polymorphism.
|
||||||
|
|
||||||
|
<hr>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
76
Examples/php5/extend/runme.php
Normal file
76
Examples/php5/extend/runme.php
Normal file
|
|
@ -0,0 +1,76 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
# This file illustrates the cross language polymorphism using directors.
|
||||||
|
|
||||||
|
require("example.php");
|
||||||
|
|
||||||
|
# CEO class, which overrides Employee::getPosition().
|
||||||
|
|
||||||
|
class CEO extends Manager {
|
||||||
|
function getPosition() {
|
||||||
|
return "CEO";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Create an instance of our employee extension class, CEO. The calls to
|
||||||
|
# getName() and getPosition() are standard, the call to getTitle() uses
|
||||||
|
# the director wrappers to call CEO.getPosition.
|
||||||
|
|
||||||
|
$e = new CEO("Alice");
|
||||||
|
print $e->getName() . " is a " . $e->getPosition() . "\n";
|
||||||
|
printf("Just call her \"%s\"\n", $e->getTitle());
|
||||||
|
print "----------------------\n";
|
||||||
|
|
||||||
|
# Create a new EmployeeList instance. This class does not have a C++
|
||||||
|
# director wrapper, but can be used freely with other classes that do.
|
||||||
|
|
||||||
|
$list = new EmployeeList();
|
||||||
|
|
||||||
|
# EmployeeList owns its items, so we must surrender ownership of objects
|
||||||
|
# we add. This involves first clearing the ->disown member to tell the
|
||||||
|
# C++ director to start reference counting.
|
||||||
|
|
||||||
|
$e->thisown = 0;
|
||||||
|
$list->addEmployee($e);
|
||||||
|
print "----------------------\n";
|
||||||
|
|
||||||
|
# Now we access the first four items in list (three are C++ objects that
|
||||||
|
# EmployeeList's constructor adds, the last is our CEO). The virtual
|
||||||
|
# methods of all these instances are treated the same. For items 0, 1, and
|
||||||
|
# 2, both all methods resolve in C++. For item 3, our CEO, getTitle calls
|
||||||
|
# getPosition which resolves in PHP. The call to getPosition is
|
||||||
|
# slightly different, however, from the e.getPosition() call above, since
|
||||||
|
# now the object reference has been "laundered" by passing through
|
||||||
|
# EmployeeList as an Employee*. Previously, PHP resolved the call
|
||||||
|
# immediately in CEO, but now PHP thinks the object is an instance of
|
||||||
|
# class Employee (actually EmployeePtr). So the call passes through the
|
||||||
|
# Employee proxy class and on to the C wrappers and C++ director,
|
||||||
|
# eventually ending up back at the CEO implementation of getPosition().
|
||||||
|
# The call to getTitle() for item 3 runs the C++ Employee::getTitle()
|
||||||
|
# method, which in turn calls getPosition(). This virtual method call
|
||||||
|
# passes down through the C++ director class to the PHP implementation
|
||||||
|
# in CEO. All this routing takes place transparently.
|
||||||
|
|
||||||
|
print "(position, title) for items 0-3:\n";
|
||||||
|
|
||||||
|
printf(" %s, \"%s\"\n", $list->get_item(0)->getPosition(), $list->get_item(0)->getTitle());
|
||||||
|
printf(" %s, \"%s\"\n", $list->get_item(1)->getPosition(), $list->get_item(1)->getTitle());
|
||||||
|
printf(" %s, \"%s\"\n", $list->get_item(2)->getPosition(), $list->get_item(2)->getTitle());
|
||||||
|
printf(" %s, \"%s\"\n", $list->get_item(3)->getPosition(), $list->get_item(3)->getTitle());
|
||||||
|
print "----------------------\n";
|
||||||
|
|
||||||
|
# Time to delete the EmployeeList, which will delete all the Employee*
|
||||||
|
# items it contains. The last item is our CEO, which gets destroyed as its
|
||||||
|
# reference count goes to zero. The PHP destructor runs, and is still
|
||||||
|
# able to call the getName() method since the underlying C++ object still
|
||||||
|
# exists. After this destructor runs the remaining C++ destructors run as
|
||||||
|
# usual to destroy the object.
|
||||||
|
|
||||||
|
unset($list);
|
||||||
|
print "----------------------\n";
|
||||||
|
|
||||||
|
# All done.
|
||||||
|
|
||||||
|
print "php exit\n";
|
||||||
|
|
||||||
|
?>
|
||||||
20
Examples/php5/funcptr/Makefile
Normal file
20
Examples/php5/funcptr/Makefile
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
TOP = ../..
|
||||||
|
SWIGEXE = $(TOP)/../swig
|
||||||
|
SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
|
||||||
|
SRCS = example.c
|
||||||
|
TARGET = example
|
||||||
|
INTERFACE = example.i
|
||||||
|
LIBS =
|
||||||
|
SWIGOPT =
|
||||||
|
|
||||||
|
check: build
|
||||||
|
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php5_run
|
||||||
|
|
||||||
|
build:
|
||||||
|
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' SRCS='$(SRCS)' \
|
||||||
|
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||||
|
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
|
||||||
|
php5
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php5_clean
|
||||||
17
Examples/php5/funcptr/example.c
Normal file
17
Examples/php5/funcptr/example.c
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
/* File : example.c */
|
||||||
|
|
||||||
|
int do_op(int a, int b, int (*op)(int,int)) {
|
||||||
|
return (*op)(a,b);
|
||||||
|
}
|
||||||
|
|
||||||
|
int add(int a, int b) {
|
||||||
|
return a+b;
|
||||||
|
}
|
||||||
|
|
||||||
|
int sub(int a, int b) {
|
||||||
|
return a-b;
|
||||||
|
}
|
||||||
|
|
||||||
|
int mul(int a, int b) {
|
||||||
|
return a*b;
|
||||||
|
}
|
||||||
7
Examples/php5/funcptr/example.h
Normal file
7
Examples/php5/funcptr/example.h
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
/* file: example.h */
|
||||||
|
|
||||||
|
extern int do_op(int,int, int (*op)(int,int));
|
||||||
|
extern int add(int,int);
|
||||||
|
extern int sub(int,int);
|
||||||
|
extern int mul(int,int);
|
||||||
|
|
||||||
15
Examples/php5/funcptr/example.i
Normal file
15
Examples/php5/funcptr/example.i
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
/* File : example.i */
|
||||||
|
%module example
|
||||||
|
%{
|
||||||
|
#include "example.h"
|
||||||
|
%}
|
||||||
|
|
||||||
|
/* Wrap a function taking a pointer to a function */
|
||||||
|
extern int do_op(int a, int b, int (*op)(int, int));
|
||||||
|
|
||||||
|
/* Now install a bunch of "ops" as constants */
|
||||||
|
%constant int (*ADD)(int,int) = add;
|
||||||
|
%constant int (*SUB)(int,int) = sub;
|
||||||
|
%constant int (*MUL)(int,int) = mul;
|
||||||
|
|
||||||
|
|
||||||
24
Examples/php5/funcptr/runme.php
Normal file
24
Examples/php5/funcptr/runme.php
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
require "example.php";
|
||||||
|
|
||||||
|
$a = 37;
|
||||||
|
$b = 42;
|
||||||
|
|
||||||
|
# Now call our C function with a bunch of callbacks
|
||||||
|
|
||||||
|
print "Trying some C callback functions\n";
|
||||||
|
print " a = $a\n";
|
||||||
|
print " b = $b\n";
|
||||||
|
print " ADD(a,b) = ". do_op($a,$b,ADD)."\n";
|
||||||
|
print " SUB(a,b) = ". do_op($a,$b,SUB)."\n";
|
||||||
|
print " MUL(a,b) = ". do_op($a,$b,MUL)."\n";
|
||||||
|
|
||||||
|
print "Here is what the C callback function objects look like in php\n";
|
||||||
|
print "Using swig style string pointers as we need them registered as constants\n";
|
||||||
|
print " ADD = " . ADD . "\n";
|
||||||
|
print " SUB = " . SUB . "\n";
|
||||||
|
print " MUL = " . MUL . "\n";
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
||||||
20
Examples/php5/overloading/Makefile
Normal file
20
Examples/php5/overloading/Makefile
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
TOP = ../..
|
||||||
|
SWIGEXE = $(TOP)/../swig
|
||||||
|
SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
|
||||||
|
CXXSRCS = example.cxx
|
||||||
|
TARGET = example
|
||||||
|
INTERFACE = example.i
|
||||||
|
LIBS =
|
||||||
|
SWIGOPT =
|
||||||
|
|
||||||
|
check: build
|
||||||
|
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php5_run
|
||||||
|
|
||||||
|
build:
|
||||||
|
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \
|
||||||
|
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
|
||||||
|
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' \
|
||||||
|
php5_cpp
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' php5_clean
|
||||||
55
Examples/php5/overloading/example.cxx
Normal file
55
Examples/php5/overloading/example.cxx
Normal file
|
|
@ -0,0 +1,55 @@
|
||||||
|
/* File : example.c */
|
||||||
|
|
||||||
|
#include "example.h"
|
||||||
|
#include <math.h>
|
||||||
|
#ifndef M_PI
|
||||||
|
# define M_PI 3.14159265358979323846
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int Shape::get_nshapes() {
|
||||||
|
return nshapes;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Move the shape to a new location */
|
||||||
|
void Shape::move(double dx, double dy) {
|
||||||
|
x += dx;
|
||||||
|
y += dy;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Shape::nshapes = 0;
|
||||||
|
|
||||||
|
double Circle::area(void) {
|
||||||
|
return M_PI*radius*radius;
|
||||||
|
}
|
||||||
|
|
||||||
|
double Circle::perimeter(void) {
|
||||||
|
return 2*M_PI*radius;
|
||||||
|
}
|
||||||
|
|
||||||
|
double Square::area(void) {
|
||||||
|
return width*width;
|
||||||
|
}
|
||||||
|
|
||||||
|
double Square::perimeter(void) {
|
||||||
|
return 4*width;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *overloaded(int i) {
|
||||||
|
return "Overloaded with int";
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *overloaded(double d) {
|
||||||
|
return "Overloaded with double";
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *overloaded(const char * str) {
|
||||||
|
return "Overloaded with char *";
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *overloaded( const Circle& ) {
|
||||||
|
return "Overloaded with Circle";
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *overloaded( const Shape& ) {
|
||||||
|
return "Overloaded with Shape";
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue