merge from trunk

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-sploving@11292 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Baozeng Ding 2009-06-21 01:26:44 +00:00
commit 0eb0740556
56 changed files with 1756 additions and 402 deletions

View file

@ -1,6 +1,43 @@
Version 1.3.40 (in progress)
============================
2009-06-16: wsfulton
[Java,C#] Fix enum marshalling when %ignore is used on one of the enum items.
Incorrect enum values were being passed to the C++ layer or compilation errors resulted.
2009-06-02: talby
[Perl] Resolved reference.i overload support problem
identfied by John Potowsky.
2009-05-26: wsfulton
[C#] Improved std::map wrappers based on patch from Yuval Baror. The C# proxy
now implements System.Collections.Generic.IDictionary<>.
These std:map wrappers have a non-backwards compatible overhaul to make them
like a .NET IDictionary. Some method names have changed as following:
set -> setitem (use this[] property now)
get -> getitem (use this[] property now)
has_key -> ContainsKey
del -> Remove
clear -> Clear
The following macros used for std::map wrappers are deprecated and will no longer work:
specialize_std_map_on_key
specialize_std_map_on_value
specialize_std_map_on_both
*** POTENTIAL INCOMPATIBILITY ***
2009-05-14: bhy
[Python] Fix the wrong pointer value returned by SwigPyObject_repr().
2009-05-13: mutandiz (Mikel Bancroft)
[allegrocl] Minor tweak when wrapping in -nocwrap mode.
2009-05-11: wsfulton
[C#] Improved std::vector wrappers on the C# proxy side from Yuval Baror. These
implement IList<> instead of IEnumerable<> where possible.
2009-04-29: wsfulton
[Java, C#] Add the 'notderived' attribute to the javabase and csbase typemaps.
When this attribute is set, the typemap will not apply to classes that are derived

View file

@ -351,7 +351,7 @@ function like this in an interface file :</p>
<div class="code"><pre>
%module example
%include typemaps.i
%include "typemaps.i"
...
%{
extern void negate(double *);

View file

@ -99,6 +99,7 @@ namespace com.bloggs.widget {
...
}
</pre></div>
Note that by default, the generated C# classes have no namespace and the module name is unrelated to namespaces. The module name is just like in Java and is merely used to name some of the generated classes.
</li>
<li>
@ -131,7 +132,7 @@ If it was used, it would generate an illegal runtime initialisation via a PInvok
C# doesn't support the notion of throws clauses.
Therefore there is no 'throws' typemap attribute support for adding exception classes to a throws clause.
Likewise there is no need for an equivalent to <tt>%javaexception</tt>.
In fact, throwing C# exceptions works quite differently, see <a href="CSharp.html#csharp_exceptions">C# Exceptions></a> below.
In fact, throwing C# exceptions works quite differently, see <a href="CSharp.html#csharp_exceptions">C# Exceptions</a> below.
</li>
<li>
@ -212,7 +213,7 @@ The "csin" typemap supports additional optional attributes called 'cshin' and 't
The 'cshin' attribute should contain the parameter type and name whenever a <a href="Java.html#java_constructor_helper_function">constructor helper function</a> is generated due to the 'pre' or 'post' attributes.
The 'terminator' attribute normally just contains a closing brace for when the 'pre' attribute contains an opening brace, such as when a C# <tt>using</tt> or <tt>fixed</tt> block is started.
Note that 'pre', 'post', 'terminator' and 'cshin' attributes are not used for marshalling the property set.
Please see the <a href="#csharp_date_marshalling">Date marshalling example</a> and <a href="#CSharp.html#csharp_date_properties">Date marshalling of properties example</a> for further understanding of these "csin" applicable attributes.
Please see the <a href="#csharp_date_marshalling">Date marshalling example</a> and <a href="#csharp_date_properties">Date marshalling of properties example</a> for further understanding of these "csin" applicable attributes.
</p>
</li>

View file

@ -488,6 +488,7 @@
<!-- INDEX -->
<div class="sectiontoc">
<ul>
<li><a href="Modules.html#Modules_introduction">Modules Introduction</a>
<li><a href="Modules.html#Modules_nn1">Basics</a>
<li><a href="Modules.html#Modules_nn2">The SWIG runtime code</a>
<li><a href="Modules.html#external_run_time">External access to the runtime</a>

View file

@ -253,6 +253,12 @@ To change this, you can use the <tt>-o</tt> option.
It is also possible to change the <a href="SWIG.html#output">output directory </a> that the Java files are generated into using <tt>-outdir</tt>.
</p>
<p>
The module name, specified with <tt>%module</tt>, determines the name of various generated classes as discussed <a href=#module_packages_classes>later</a>.
Note that the module name does not define a Java package and by default, the generated Java classes do not have a Java package.
The <tt>-package</tt> option described below can specify a Java package name to use.
</p>
<p>
The following sections have further practical examples and details on how you might go about
compiling and using the generated files.

View file

@ -10,6 +10,7 @@
<!-- INDEX -->
<div class="sectiontoc">
<ul>
<li><a href="#Modules_introduction">Modules Introduction</a>
<li><a href="#Modules_nn1">Basics</a>
<li><a href="#Modules_nn2">The SWIG runtime code</a>
<li><a href="#external_run_time">External access to the runtime</a>
@ -22,11 +23,49 @@
<H2><a name="Modules_introduction"></a>15.1 Modules Introduction</H2>
<p>
Each invocation of SWIG requires a module name to be specified.
The module name is used to name the resulting target language extension module.
Exactly what this means and and what the name is used for
depends on the target language, for example the name can define
a target language namespace or merely be a useful name for naming files or helper classes.
Essentially, a module comprises target language wrappers for a chosen collection of global variables/functions, structs/classes and other C/C++ types.
</p>
<p>
The module name can be supplied in one of two ways.
The first is to specify it with the special <tt>%module</tt>
directive. This directive must appear at the beginning of the interface file.
The general form of this directive is:
</p>
<div class="code"><pre>
<tt>%module(option1="value1",option2="value2",...) modulename</tt>
</pre></div>
<p>
where the modulename is mandatory and the options add one or more optional additional features.
Typically no options are specified, for example:
</p>
<div class="code"><pre>
<tt>%module mymodule</tt>
</pre></div>
<p>
The second way to specify the module name is with the <tt>-module</tt> command line option, for example <tt>-module mymodule</tt>.
If the module name is supplied on the command line, it overrides the name specified by the
<tt>%module</tt> directive.
</p>
<p>
When first working with SWIG, users commonly start by creating a
single module. That is, you might define a single SWIG interface that
wraps some set of C/C++ code. You then compile all of the generated
wrapper code into a module and use it. For large applications, however,
wrapper code together and use it. For large applications, however,
this approach is problematic---the size of the generated wrapper code
can be rather large. Moreover, it is probably easier to manage the
target language interface when it is broken up into smaller pieces.
@ -34,10 +73,11 @@ target language interface when it is broken up into smaller pieces.
<p>
This chapter describes the problem of using SWIG in programs
where you want to create a collection of modules.
where you want to create a collection of modules.
Each module in the collection is created via separate invocations of SWIG.
</p>
<H2><a name="Modules_nn1"></a>15.1 Basics</H2>
<H2><a name="Modules_nn1"></a>15.2 Basics</H2>
<p>
@ -135,7 +175,7 @@ in parallel from multiple threads as SWIG provides no locking - for more on that
issue, read on.
</p>
<H2><a name="Modules_nn2"></a>15.2 The SWIG runtime code</H2>
<H2><a name="Modules_nn2"></a>15.3 The SWIG runtime code</H2>
<p>
@ -201,7 +241,7 @@ can peacefully coexist. So the type structures are separated by the
is empty. Only modules compiled with the same pair will share type information.
</p>
<H2><a name="external_run_time"></a>15.3 External access to the runtime</H2>
<H2><a name="external_run_time"></a>15.4 External access to the runtime</H2>
<p>As described in <a href="Typemaps.html#runtime_type_checker">The run-time type checker</a>,
@ -238,7 +278,7 @@ SWIG_TYPE_TABLE to be the same as the module whose types you are trying to
access.
</p>
<H2><a name="Modules_nn4"></a>15.4 A word of caution about static libraries</H2>
<H2><a name="Modules_nn4"></a>15.5 A word of caution about static libraries</H2>
<p>
@ -249,7 +289,7 @@ into it. This is very often <b>NOT</b> what you want and it can lead to unexpect
behavior. When working with dynamically loadable modules, you should try to work exclusively with shared libraries.
</p>
<H2><a name="Modules_nn5"></a>15.5 References</H2>
<H2><a name="Modules_nn5"></a>15.6 References</H2>
<p>
@ -257,7 +297,7 @@ Due to the complexity of working with shared libraries and multiple modules, it
an outside reference. John Levine's "Linkers and Loaders" is highly recommended.
</p>
<H2><a name="Modules_nn6"></a>15.6 Reducing the wrapper file size</H2>
<H2><a name="Modules_nn6"></a>15.7 Reducing the wrapper file size</H2>
<p>

View file

@ -634,13 +634,13 @@ length. Instead, use multiple returns, as in the argout_ref example.
#include "example.h"
%}
%include stl.i
%include &lt;stl.i&gt;
namespace std {
%template(StringVector) std::vector &lt; string &gt;;
};
%include example.h
%include "example.h"
</pre></td></tr>
<tr><td><font size="-1"><i>This example is in Examples/ocaml/stl
</i></font></td></tr>

View file

@ -264,7 +264,7 @@ extern int fact(int);
%}
// Include code for rebuilding Perl
%include perlmain.i
%include &lt;perlmain.i&gt;
</pre></div>
<p>
@ -1543,7 +1543,7 @@ example:
<div class="code">
<pre>
%module example
%include typemaps.i
%include "typemaps.i"
void add(int x, int y, int *REFERENCE);
</pre>

View file

@ -479,7 +479,7 @@ One can include <b>cpointer.i</b> to generate PHP wrappers to <tt>int
<div class="code"><pre>
%module example
%include cpointer.i
%include "cpointer.i"
%pointer_functions(int,intp)
void add( int *in1, int *in2, int *result);
@ -513,7 +513,7 @@ parameter names as appropriate.
<div class="code"><pre>
%module example
%include typemaps.i
%include "typemaps.i"
void add( int *INPUT, int *INPUT, int *OUTPUT);
@ -545,7 +545,7 @@ named typemap REFERENCE.
<div class="code"><pre>
%module example
%include phppointers.i
%include "phppointers.i"
void add( int *REF, int *REF, int *REF);
@ -781,12 +781,6 @@ Ko::threats();
<H3><a name="Php_nn2_7"></a>29.2.7 PHP Pragmas, Startup and Shutdown code</H3>
<p>
Note: Currently pragmas for PHP need to be specified using
<tt>%pragma(php)</tt> but also apply for PHP5! This is just a historical
oddity because SWIG's PHP support predates PHP5.
</p>
<p>
To place PHP code in the generated "example.php" file one can use the
<b>code</b> pragma. The code is inserted after loading the shared

View file

@ -433,7 +433,7 @@ extern int mod(int, int);
extern double My_variable;
%}
%include embed.i // Include code for a static version of Python
%include "embed.i" // Include code for a static version of Python
</pre></div>

View file

@ -2393,7 +2393,7 @@ intset;<br>
%include std_set.i<br>
%include &lt;std_set.i&gt;<br>

View file

@ -174,13 +174,8 @@ int bar(int x);
...
</pre></div>
<p>
The name of the module is supplied using the special <tt>%module</tt>
directive (or the <tt>-module</tt> command line option). This
directive must appear at the beginning of the file and is used to name
the resulting extension module (in addition, this name often defines
a namespace in the target language). If the module name is supplied on the
command line, it overrides the name specified with the
<tt>%module</tt> directive.
The module name is supplied using the special <tt>%module</tt>
directive. Modules are described further in the <a href="Modules.html#Modules_introduction">Modules Introduction</a> section.
</p>
<p>
@ -2361,7 +2356,7 @@ You can make a <tt>Vector</tt> look a lot like a class by writing a SWIG interfa
#include "vector.h"
%}
%include vector.h // Just grab original C header file
%include "vector.h" // Just grab original C header file
%extend Vector { // Attach these functions to struct Vector
Vector(double x, double y, double z) {
Vector *v;
@ -2883,10 +2878,16 @@ interface to your program.
SWIG's <tt>%include</tt> directive to process an entire C
source/header file.
<li>Make sure everything in the interface file uses ANSI C/C++syntax.
<li>Make sure everything in the interface file uses ANSI C/C++ syntax.
<li>Make sure all necessary `<tt>typedef</tt>' declarations and
type-information is available in the interface file.
type-information is available in the interface file.
In particular, ensure that the type information is specified in the correct order as required by a C/C++ compiler.
Most importantly, define a type before it is used! A C compiler will tell you
if the full type information is not available if it is needed, whereas
SWIG will usually not warn or error out as it is designed to work without
full type information. However, if type information is not specified
correctly, the wrappers can be sub-optimal and even result in uncompileable C/C++ code.
<li>If your program has a main() function, you may need to rename it
(read on).
@ -2945,16 +2946,21 @@ extern void dump(FILE *f);
<p>
Of course, in this case, our header file is pretty simple so we could
have made an interface file like this as well:</p>
use a simpler approach and use an interface file like this:</p>
<div class="code"><pre>
/* File : interface.i */
%module mymodule
%include header.h
%{
#include "header.h"
%}
%include "header.h"
</pre></div>
<p>
Naturally, your mileage may vary.</p>
The main advantage of this approach is minimal maintenance of an interface file for when the header file changes in the future.
In more complex projects, an interface file containing numerous <tt>%include</tt> and <tt>#include</tt> statements like this is one of the most common approaches to interface file design due to lower maintenance overhead.
</p>
<H3><a name="SWIG_nn48"></a>5.7.3 Why use separate interface files?</H3>

View file

@ -190,7 +190,7 @@ extern int mod(int, int);
extern double My_variable;
%}
%include tclsh.i // Include code for rebuilding tclsh
%include "tclsh.i" // Include code for rebuilding tclsh
</pre></div>
@ -2822,7 +2822,7 @@ int print_args(char **argv) {
return i;
}
%}
%include tclsh.i
%include "tclsh.i"
</pre></div>

View file

@ -5,8 +5,6 @@
import example
# CEO class, which overrides Employee::getPosition().
class PyCallback(example.Callback):
def __init__(self):
example.Callback.__init__(self)

View file

@ -64,7 +64,7 @@ INCLUDES = -I$(top_srcdir)/$(EXAMPLES)/$(TEST_SUITE)
LIBS = -L.
LIBPREFIX = lib
ACTION = check
INTERFACEDIR = ../
INTERFACEDIR = $(if $(wildcard $*.i), ./, ../)
#
# Please keep test cases in alphabetical order.

View file

@ -358,12 +358,51 @@ public class runme {
i.MemberInstance = Instances.memberinstance3;
if (i.MemberInstance != Instances.memberinstance3) throw new Exception("MemberInstance 1 failed");
}
// ignore enum item tests start
{
if ((int)enum_thorough.ignoreATest(IgnoreTest.IgnoreA.ignoreA_zero) != 0) throw new Exception("ignoreATest 0 failed");
if ((int)enum_thorough.ignoreATest(IgnoreTest.IgnoreA.ignoreA_three) != 3) throw new Exception("ignoreATest 3 failed");
if ((int)enum_thorough.ignoreATest(IgnoreTest.IgnoreA.ignoreA_ten) != 10) throw new Exception("ignoreATest 10 failed");
if ((int)enum_thorough.ignoreATest(IgnoreTest.IgnoreA.ignoreA_eleven) != 11) throw new Exception("ignoreATest 11 failed");
if ((int)enum_thorough.ignoreATest(IgnoreTest.IgnoreA.ignoreA_thirteen) != 13) throw new Exception("ignoreATest 13 failed");
if ((int)enum_thorough.ignoreATest(IgnoreTest.IgnoreA.ignoreA_fourteen) != 14) throw new Exception("ignoreATest 14 failed");
if ((int)enum_thorough.ignoreATest(IgnoreTest.IgnoreA.ignoreA_twenty) != 20) throw new Exception("ignoreATest 20 failed");
if ((int)enum_thorough.ignoreATest(IgnoreTest.IgnoreA.ignoreA_thirty) != 30) throw new Exception("ignoreATest 30 failed");
if ((int)enum_thorough.ignoreATest(IgnoreTest.IgnoreA.ignoreA_thirty_two) != 32) throw new Exception("ignoreATest 32 failed");
if ((int)enum_thorough.ignoreATest(IgnoreTest.IgnoreA.ignoreA_thirty_three) != 33) throw new Exception("ignoreATest 33 failed");
}
{
if ((int)enum_thorough.ignoreBTest(IgnoreTest.IgnoreB.ignoreB_eleven) != 11) throw new Exception("ignoreBTest 11 failed");
if ((int)enum_thorough.ignoreBTest(IgnoreTest.IgnoreB.ignoreB_twelve) != 12) throw new Exception("ignoreBTest 12 failed");
if ((int)enum_thorough.ignoreBTest(IgnoreTest.IgnoreB.ignoreB_thirty_one) != 31) throw new Exception("ignoreBTest 31 failed");
if ((int)enum_thorough.ignoreBTest(IgnoreTest.IgnoreB.ignoreB_thirty_two) != 32) throw new Exception("ignoreBTest 32 failed");
if ((int)enum_thorough.ignoreBTest(IgnoreTest.IgnoreB.ignoreB_forty_one) != 41) throw new Exception("ignoreBTest 41 failed");
if ((int)enum_thorough.ignoreBTest(IgnoreTest.IgnoreB.ignoreB_forty_two) != 42) throw new Exception("ignoreBTest 42 failed");
}
{
if ((int)enum_thorough.ignoreCTest(IgnoreTest.IgnoreC.ignoreC_ten) != 10) throw new Exception("ignoreCTest 10 failed");
if ((int)enum_thorough.ignoreCTest(IgnoreTest.IgnoreC.ignoreC_twelve) != 12) throw new Exception("ignoreCTest 12 failed");
if ((int)enum_thorough.ignoreCTest(IgnoreTest.IgnoreC.ignoreC_thirty) != 30) throw new Exception("ignoreCTest 30 failed");
if ((int)enum_thorough.ignoreCTest(IgnoreTest.IgnoreC.ignoreC_thirty_two) != 32) throw new Exception("ignoreCTest 32 failed");
if ((int)enum_thorough.ignoreCTest(IgnoreTest.IgnoreC.ignoreC_forty) != 40) throw new Exception("ignoreCTest 40 failed");
if ((int)enum_thorough.ignoreCTest(IgnoreTest.IgnoreC.ignoreC_forty_two) != 42) throw new Exception("ignoreCTest 42 failed");
}
{
if ((int)enum_thorough.ignoreDTest(IgnoreTest.IgnoreD.ignoreD_twenty_one) != 21) throw new Exception("ignoreDTest 21 failed");
if ((int)enum_thorough.ignoreDTest(IgnoreTest.IgnoreD.ignoreD_twenty_two) != 22) throw new Exception("ignoreDTest 22 failed");
}
{
if ((int)enum_thorough.ignoreETest(IgnoreTest.IgnoreE.ignoreE_zero) != 0) throw new Exception("ignoreETest 0 failed");
if ((int)enum_thorough.ignoreETest(IgnoreTest.IgnoreE.ignoreE_twenty_one) != 21) throw new Exception("ignoreETest 21 failed");
if ((int)enum_thorough.ignoreETest(IgnoreTest.IgnoreE.ignoreE_twenty_two) != 22) throw new Exception("ignoreETest 22 failed");
}
// ignore enum item tests end
{
if ((int)enum_thorough.repeatTest(repeat.one) != 1) throw new Exception("repeatTest 1 failed");
if ((int)enum_thorough.repeatTest(repeat.initial) != 1) throw new Exception("repeatTest 2 failed");
if ((int)enum_thorough.repeatTest(repeat.two) != 2) throw new Exception("repeatTest 3 failed");
if ((int)enum_thorough.repeatTest(repeat.three) != 3) throw new Exception("repeatTest 4 failed");
if ((int)enum_thorough.repeatTest(repeat.last) != 3) throw new Exception("repeatTest 5 failed");
if ((int)enum_thorough.repeatTest(repeat.llast) != 3) throw new Exception("repeatTest 5 failed");
if ((int)enum_thorough.repeatTest(repeat.end) != 3) throw new Exception("repeatTest 6 failed");
}
}

View file

@ -358,12 +358,51 @@ public class runme {
i.MemberInstance = Instances.memberinstance3;
if (i.MemberInstance != Instances.memberinstance3) throw new Exception("MemberInstance 1 failed");
}
// ignore enum item tests start
{
if (enum_thorough_simple.ignoreATest(IgnoreTest.ignoreA_zero) != 0) throw new Exception("ignoreATest 0 failed");
if (enum_thorough_simple.ignoreATest(IgnoreTest.ignoreA_three) != 3) throw new Exception("ignoreATest 3 failed");
if (enum_thorough_simple.ignoreATest(IgnoreTest.ignoreA_ten) != 10) throw new Exception("ignoreATest 10 failed");
if (enum_thorough_simple.ignoreATest(IgnoreTest.ignoreA_eleven) != 11) throw new Exception("ignoreATest 11 failed");
if (enum_thorough_simple.ignoreATest(IgnoreTest.ignoreA_thirteen) != 13) throw new Exception("ignoreATest 13 failed");
if (enum_thorough_simple.ignoreATest(IgnoreTest.ignoreA_fourteen) != 14) throw new Exception("ignoreATest 14 failed");
if (enum_thorough_simple.ignoreATest(IgnoreTest.ignoreA_twenty) != 20) throw new Exception("ignoreATest 20 failed");
if (enum_thorough_simple.ignoreATest(IgnoreTest.ignoreA_thirty) != 30) throw new Exception("ignoreATest 30 failed");
if (enum_thorough_simple.ignoreATest(IgnoreTest.ignoreA_thirty_two) != 32) throw new Exception("ignoreATest 32 failed");
if (enum_thorough_simple.ignoreATest(IgnoreTest.ignoreA_thirty_three) != 33) throw new Exception("ignoreATest 33 failed");
}
{
if (enum_thorough_simple.ignoreBTest(IgnoreTest.ignoreB_eleven) != 11) throw new Exception("ignoreBTest 11 failed");
if (enum_thorough_simple.ignoreBTest(IgnoreTest.ignoreB_twelve) != 12) throw new Exception("ignoreBTest 12 failed");
if (enum_thorough_simple.ignoreBTest(IgnoreTest.ignoreB_thirty_one) != 31) throw new Exception("ignoreBTest 31 failed");
if (enum_thorough_simple.ignoreBTest(IgnoreTest.ignoreB_thirty_two) != 32) throw new Exception("ignoreBTest 32 failed");
if (enum_thorough_simple.ignoreBTest(IgnoreTest.ignoreB_forty_one) != 41) throw new Exception("ignoreBTest 41 failed");
if (enum_thorough_simple.ignoreBTest(IgnoreTest.ignoreB_forty_two) != 42) throw new Exception("ignoreBTest 42 failed");
}
{
if (enum_thorough_simple.ignoreCTest(IgnoreTest.ignoreC_ten) != 10) throw new Exception("ignoreCTest 10 failed");
if (enum_thorough_simple.ignoreCTest(IgnoreTest.ignoreC_twelve) != 12) throw new Exception("ignoreCTest 12 failed");
if (enum_thorough_simple.ignoreCTest(IgnoreTest.ignoreC_thirty) != 30) throw new Exception("ignoreCTest 30 failed");
if (enum_thorough_simple.ignoreCTest(IgnoreTest.ignoreC_thirty_two) != 32) throw new Exception("ignoreCTest 32 failed");
if (enum_thorough_simple.ignoreCTest(IgnoreTest.ignoreC_forty) != 40) throw new Exception("ignoreCTest 40 failed");
if (enum_thorough_simple.ignoreCTest(IgnoreTest.ignoreC_forty_two) != 42) throw new Exception("ignoreCTest 42 failed");
}
{
if (enum_thorough_simple.ignoreDTest(IgnoreTest.ignoreD_twenty_one) != 21) throw new Exception("ignoreDTest 21 failed");
if (enum_thorough_simple.ignoreDTest(IgnoreTest.ignoreD_twenty_two) != 22) throw new Exception("ignoreDTest 22 failed");
}
{
if (enum_thorough_simple.ignoreETest(IgnoreTest.ignoreE_zero) != 0) throw new Exception("ignoreETest 0 failed");
if (enum_thorough_simple.ignoreETest(IgnoreTest.ignoreE_twenty_one) != 21) throw new Exception("ignoreETest 21 failed");
if (enum_thorough_simple.ignoreETest(IgnoreTest.ignoreE_twenty_two) != 22) throw new Exception("ignoreETest 22 failed");
}
// ignore enum item tests end
{
if (enum_thorough_simple.repeatTest(enum_thorough_simple.one) != 1) throw new Exception("repeatTest 1 failed");
if (enum_thorough_simple.repeatTest(enum_thorough_simple.initial) != 1) throw new Exception("repeatTest 2 failed");
if (enum_thorough_simple.repeatTest(enum_thorough_simple.two) != 2) throw new Exception("repeatTest 3 failed");
if (enum_thorough_simple.repeatTest(enum_thorough_simple.three) != 3) throw new Exception("repeatTest 4 failed");
if (enum_thorough_simple.repeatTest(enum_thorough_simple.last) != 3) throw new Exception("repeatTest 5 failed");
if (enum_thorough_simple.repeatTest(enum_thorough_simple.llast) != 3) throw new Exception("repeatTest 5 failed");
if (enum_thorough_simple.repeatTest(enum_thorough_simple.end) != 3) throw new Exception("repeatTest 6 failed");
}
}

View file

@ -358,12 +358,51 @@ public class runme {
i.MemberInstance = Instances.memberinstance3;
if (i.MemberInstance != Instances.memberinstance3) throw new Exception("MemberInstance 1 failed");
}
// ignore enum item tests start
{
if (enum_thorough_typesafe.ignoreATest(IgnoreTest.IgnoreA.ignoreA_zero).swigValue != 0) throw new Exception("ignoreATest 0 failed");
if (enum_thorough_typesafe.ignoreATest(IgnoreTest.IgnoreA.ignoreA_three).swigValue != 3) throw new Exception("ignoreATest 3 failed");
if (enum_thorough_typesafe.ignoreATest(IgnoreTest.IgnoreA.ignoreA_ten).swigValue != 10) throw new Exception("ignoreATest 10 failed");
if (enum_thorough_typesafe.ignoreATest(IgnoreTest.IgnoreA.ignoreA_eleven).swigValue != 11) throw new Exception("ignoreATest 11 failed");
if (enum_thorough_typesafe.ignoreATest(IgnoreTest.IgnoreA.ignoreA_thirteen).swigValue != 13) throw new Exception("ignoreATest 13 failed");
if (enum_thorough_typesafe.ignoreATest(IgnoreTest.IgnoreA.ignoreA_fourteen).swigValue != 14) throw new Exception("ignoreATest 14 failed");
if (enum_thorough_typesafe.ignoreATest(IgnoreTest.IgnoreA.ignoreA_twenty).swigValue != 20) throw new Exception("ignoreATest 20 failed");
if (enum_thorough_typesafe.ignoreATest(IgnoreTest.IgnoreA.ignoreA_thirty).swigValue != 30) throw new Exception("ignoreATest 30 failed");
if (enum_thorough_typesafe.ignoreATest(IgnoreTest.IgnoreA.ignoreA_thirty_two).swigValue != 32) throw new Exception("ignoreATest 32 failed");
if (enum_thorough_typesafe.ignoreATest(IgnoreTest.IgnoreA.ignoreA_thirty_three).swigValue != 33) throw new Exception("ignoreATest 33 failed");
}
{
if (enum_thorough_typesafe.ignoreBTest(IgnoreTest.IgnoreB.ignoreB_eleven).swigValue != 11) throw new Exception("ignoreBTest 11 failed");
if (enum_thorough_typesafe.ignoreBTest(IgnoreTest.IgnoreB.ignoreB_twelve).swigValue != 12) throw new Exception("ignoreBTest 12 failed");
if (enum_thorough_typesafe.ignoreBTest(IgnoreTest.IgnoreB.ignoreB_thirty_one).swigValue != 31) throw new Exception("ignoreBTest 31 failed");
if (enum_thorough_typesafe.ignoreBTest(IgnoreTest.IgnoreB.ignoreB_thirty_two).swigValue != 32) throw new Exception("ignoreBTest 32 failed");
if (enum_thorough_typesafe.ignoreBTest(IgnoreTest.IgnoreB.ignoreB_forty_one).swigValue != 41) throw new Exception("ignoreBTest 41 failed");
if (enum_thorough_typesafe.ignoreBTest(IgnoreTest.IgnoreB.ignoreB_forty_two).swigValue != 42) throw new Exception("ignoreBTest 42 failed");
}
{
if (enum_thorough_typesafe.ignoreCTest(IgnoreTest.IgnoreC.ignoreC_ten).swigValue != 10) throw new Exception("ignoreCTest 10 failed");
if (enum_thorough_typesafe.ignoreCTest(IgnoreTest.IgnoreC.ignoreC_twelve).swigValue != 12) throw new Exception("ignoreCTest 12 failed");
if (enum_thorough_typesafe.ignoreCTest(IgnoreTest.IgnoreC.ignoreC_thirty).swigValue != 30) throw new Exception("ignoreCTest 30 failed");
if (enum_thorough_typesafe.ignoreCTest(IgnoreTest.IgnoreC.ignoreC_thirty_two).swigValue != 32) throw new Exception("ignoreCTest 32 failed");
if (enum_thorough_typesafe.ignoreCTest(IgnoreTest.IgnoreC.ignoreC_forty).swigValue != 40) throw new Exception("ignoreCTest 40 failed");
if (enum_thorough_typesafe.ignoreCTest(IgnoreTest.IgnoreC.ignoreC_forty_two).swigValue != 42) throw new Exception("ignoreCTest 42 failed");
}
{
if (enum_thorough_typesafe.ignoreDTest(IgnoreTest.IgnoreD.ignoreD_twenty_one).swigValue != 21) throw new Exception("ignoreDTest 21 failed");
if (enum_thorough_typesafe.ignoreDTest(IgnoreTest.IgnoreD.ignoreD_twenty_two).swigValue != 22) throw new Exception("ignoreDTest 22 failed");
}
{
if (enum_thorough_typesafe.ignoreETest(IgnoreTest.IgnoreE.ignoreE_zero).swigValue != 0) throw new Exception("ignoreETest 0 failed");
if (enum_thorough_typesafe.ignoreETest(IgnoreTest.IgnoreE.ignoreE_twenty_one).swigValue != 21) throw new Exception("ignoreETest 21 failed");
if (enum_thorough_typesafe.ignoreETest(IgnoreTest.IgnoreE.ignoreE_twenty_two).swigValue != 22) throw new Exception("ignoreETest 22 failed");
}
// ignore enum item tests end
{
if (enum_thorough_typesafe.repeatTest(repeat.one).swigValue != 1) throw new Exception("repeatTest 1 failed");
if (enum_thorough_typesafe.repeatTest(repeat.initial).swigValue != 1) throw new Exception("repeatTest 2 failed");
if (enum_thorough_typesafe.repeatTest(repeat.two).swigValue != 2) throw new Exception("repeatTest 3 failed");
if (enum_thorough_typesafe.repeatTest(repeat.three).swigValue != 3) throw new Exception("repeatTest 4 failed");
if (enum_thorough_typesafe.repeatTest(repeat.last).swigValue != 3) throw new Exception("repeatTest 5 failed");
if (enum_thorough_typesafe.repeatTest(repeat.llast).swigValue != 3) throw new Exception("repeatTest 5 failed");
if (enum_thorough_typesafe.repeatTest(repeat.end).swigValue != 3) throw new Exception("repeatTest 6 failed");
}
}

View file

@ -0,0 +1,243 @@
/* -----------------------------------------------------------------------------
* See the LICENSE file for information on copyright, usage and redistribution
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
*
* li_std_map_runme.cs
*
* SWIG C# tester for std_map.i
* Implementation by Yuval Baror (http://yuval.bar-or.org)
*
* This class tests all the functionality of the std_map.i wrapper.
* Upon successful testing, the main function doesn't print out anything.
* If any error is found - it will be printed on the screen.
* ----------------------------------------------------------------------------- */
using System;
using System.Collections.Generic;
using li_std_mapNamespace;
public class li_std_map_runme {
private static readonly int collectionSize = 20;
private static readonly int midCollection = collectionSize / 2;
public static void Main()
{
// Set up an int int map
StringIntMap simap = new StringIntMap();
for (int i = 0; i < collectionSize; i++)
{
int val = i * 18;
simap.Add(i.ToString(), val);
}
// Count property test
if (simap.Count != collectionSize)
throw new Exception("Count test failed");
// IsReadOnly property test
if (simap.IsReadOnly)
throw new Exception("IsReadOnly test failed");
// Item indexing test
simap["0"] = 200;
if (simap["0"] != 200)
throw new Exception("Item property test failed");
simap["0"] = 0 * 18;
// ContainsKey() test
for (int i = 0; i < collectionSize; i++)
{
if (!simap.ContainsKey(i.ToString()))
throw new Exception("ContainsKey test " + i + " failed");
}
// ContainsKey() test
for (int i = 0; i < collectionSize; i++)
{
if (!simap.Contains(new KeyValuePair<string, int>(i.ToString(), i * 18)))
throw new Exception("Contains test " + i + " failed");
}
// TryGetValue() test
int value;
bool rc = simap.TryGetValue("3", out value);
if (rc != true || value != (3 * 18))
throw new Exception("TryGetValue test 1 failed");
rc = simap.TryGetValue("-1", out value);
if (rc != false)
throw new Exception("TryGetValue test 2 failed");
// Keys and Values test
{
IList<string> keys = new List<string>(simap.Keys);
IList<int> values = new List<int>(simap.Values);
if (keys.Count != collectionSize)
throw new Exception("Keys count test failed");
if (values.Count != collectionSize)
throw new Exception("Values count test failed");
for (int i = 0; i < keys.Count; i++)
{
if (simap[keys[i]] != values[i])
throw new Exception("Keys and values test failed for index " + i);
}
}
// Add and Remove test
for (int i = 100; i < 103; i++)
{
simap.Add(i.ToString(), i * 18);
if (!simap.ContainsKey(i.ToString()) || simap[i.ToString()] != (i * 18))
throw new Exception("Add test failed for index " + i);
simap.Remove(i.ToString());
if (simap.ContainsKey(i.ToString()))
throw new Exception("Remove test failed for index " + i);
}
for (int i = 200; i < 203; i++)
{
simap.Add(new KeyValuePair<string, int>(i.ToString(), i * 18));
if (!simap.ContainsKey(i.ToString()) || simap[i.ToString()] != (i * 18))
throw new Exception("Add explicit test failed for index " + i);
simap.Remove(new KeyValuePair<string, int>(i.ToString(), i * 18));
if (simap.ContainsKey(i.ToString()))
throw new Exception("Remove explicit test failed for index " + i);
}
// Duplicate key test
try
{
simap.Add("3", 0);
throw new Exception("Adding duplicate key test failed");
}
catch (ArgumentException)
{
}
// CopyTo() test
{
KeyValuePair<string, int>[] outputarray = new KeyValuePair<string, int>[collectionSize];
simap.CopyTo(outputarray);
foreach (KeyValuePair<string, int> val in outputarray)
{
if (simap[val.Key] != val.Value)
throw new Exception("CopyTo (1) test failed, index:" + val.Key);
}
}
{
KeyValuePair<string, int>[] outputarray = new KeyValuePair<string, int>[midCollection + collectionSize];
simap.CopyTo(outputarray, midCollection);
for (int i = midCollection; i < midCollection + collectionSize; i++)
{
KeyValuePair<string, int> val = outputarray[i];
if (simap[val.Key] != val.Value)
throw new Exception("CopyTo (2) test failed, index:" + val.Key);
}
}
{
KeyValuePair<string, int>[] outputarray = new KeyValuePair<string, int>[collectionSize - 1];
try
{
simap.CopyTo(outputarray);
throw new Exception("CopyTo (4) test failed");
}
catch (ArgumentException)
{
}
}
// Clear test
simap.Clear();
if (simap.Count != 0)
throw new Exception("Clear test failed");
// Test wrapped methods
for (int i = 1; i <= 5; i++)
{
simap[i.ToString()] = i;
}
double avg = li_std_map.valueAverage(simap);
if (avg != 3.0)
throw new Exception("Wrapped method valueAverage test failed. Got " + avg);
string keyStringified = li_std_map.stringifyKeys(simap);
if (keyStringified != " 1 2 3 4 5")
throw new Exception("Wrapped method stringifyKeys test failed. Got " + keyStringified);
// Test a map with a new specialized type (Struct)
{
IntStructMap ismap = new IntStructMap();
for (int i = 0; i < 10; i++)
{
ismap.Add(i, new Struct(i * 10.1));
}
if (ismap.Count != 10)
throw new Exception("Count test on specialized map failed");
foreach (KeyValuePair<int, Struct> p in ismap)
{
if ((p.Key * 10.1) != p.Value.num)
throw new Exception("Iteration test on specialized map failed for index " + p.Key);
}
}
// Test a map of pointers
{
IntStructPtrMap ispmap = new IntStructPtrMap();
for (int i = 0; i < 10; i++)
{
ispmap.Add(i, new Struct(i * 10.1));
}
if (ispmap.Count != 10)
throw new Exception("Count test on specialized pointer map failed");
foreach (KeyValuePair<int, Struct> p in ispmap)
{
if ((p.Key * 10.1) != p.Value.num)
throw new Exception("Iteration test on specialized pointer map failed for index " + p.Key);
}
}
{
IntStructConstPtrMap iscpmap = new IntStructConstPtrMap();
for (int i = 0; i < 10; i++)
{
iscpmap.Add(i, new Struct(i * 10.1));
}
if (iscpmap.Count != 10)
throw new Exception("Count test on specialized const pointer map failed");
foreach (KeyValuePair<int, Struct> p in iscpmap)
{
if ((p.Key * 10.1) != p.Value.num)
throw new Exception("Iteration test on specialized const pointer map failed for index " + p.Key);
}
}
// Test non-specialized map
{
StructIntMap limap = new StructIntMap();
Struct s7 = new Struct(7);
Struct s8 = new Struct(8);
limap.setitem(s7 , 8);
if (limap.getitem(s7) != 8)
throw new Exception("Assignment test on non-specialized map failed");
if (!limap.ContainsKey(s7))
throw new Exception("Key test (1) on non-specialized map failed");
if (limap.ContainsKey(s8))
throw new Exception("Key test (2) on non-specialized map failed");
}
// All done
}
}

View file

@ -153,7 +153,7 @@ public class li_std_vector_runme {
}
}
try {
new DoubleVector(null);
new DoubleVector((System.Collections.ICollection)null);
throw new Exception("ICollection constructor null test failed");
} catch (ArgumentNullException) {
}
@ -180,6 +180,13 @@ public class li_std_vector_runme {
throw new Exception("LastIndexOf non-existent test failed");
if (dv.LastIndexOf(33.3) != 6)
throw new Exception("LastIndexOf position test failed");
// Copy constructor test
DoubleVector dvCopy = new DoubleVector(dv);
for (int i=0; i<doubleArray.Length; i++) {
if (doubleArray[i] != dvCopy[i])
throw new Exception("Copy constructor failed, index:" + i);
}
}
{
// Repeat() test

View file

@ -487,11 +487,53 @@ struct Instances {
// Repeated values
#if defined(SWIGJAVA)
%javaconst(1);
// needed for typesafe and proper enums only
%javaconst(0) ignoreA_three;
%javaconst(0) ignoreA_thirteen;
#elif defined(SWIGCSHARP)
// needed for typesafe enums only
#ifdef SWIG_TEST_NOCSCONST
%csconst(0) ignoreA_three;
%csconst(0) ignoreA_thirteen;
#endif
%csconst(1);
#endif
#if defined(SWIGPERL)
%ignore ignoreA_one;
%ignore ignoreA_two;
%ignore ignoreA_twelve;
%ignore ignoreA_thirty_one;
%ignore ignoreB_ten;
%ignore ignoreB_twenty;
%ignore ignoreB_thirty;
%ignore ignoreB_forty;
%ignore ignoreC_eleven;
%ignore ignoreC_thirty_one;
%ignore ignoreC_forty_one;
%ignore ignoreD_ten;
%ignore ignoreD_twenty;
%ignore ignoreE_twenty;
%inline %{
struct IgnoreTest {
enum IgnoreA { ignoreA_zero, ignoreA_one, ignoreA_two, ignoreA_three, ignoreA_ten=10, ignoreA_eleven, ignoreA_twelve, ignoreA_thirteen, ignoreA_fourteen, ignoreA_twenty=20, ignoreA_thirty=30, ignoreA_thirty_one, ignoreA_thirty_two, ignoreA_thirty_three };
enum IgnoreB { ignoreB_ten=10, ignoreB_eleven, ignoreB_twelve, ignoreB_twenty=20, ignoreB_thirty=30, ignoreB_thirty_one, ignoreB_thirty_two, ignoreB_forty=40, ignoreB_forty_one, ignoreB_forty_two };
enum IgnoreC { ignoreC_ten=10, ignoreC_eleven, ignoreC_twelve, ignoreC_twenty=20, ignoreC_thirty=30, ignoreC_thirty_one, ignoreC_thirty_two, ignoreC_forty=40, ignoreC_forty_one, ignoreC_forty_two };
enum IgnoreD { ignoreD_ten=10, ignoreD_twenty=20, ignoreD_twenty_one, ignoreD_twenty_two };
enum IgnoreE { ignoreE_zero, ignoreE_twenty=20, ignoreE_twenty_one, ignoreE_twenty_two };
};
IgnoreTest::IgnoreA ignoreATest(IgnoreTest::IgnoreA n) { return n; }
IgnoreTest::IgnoreB ignoreBTest(IgnoreTest::IgnoreB n) { return n; }
IgnoreTest::IgnoreC ignoreCTest(IgnoreTest::IgnoreC n) { return n; }
IgnoreTest::IgnoreD ignoreDTest(IgnoreTest::IgnoreD n) { return n; }
IgnoreTest::IgnoreE ignoreETest(IgnoreTest::IgnoreE n) { return n; }
%}
%inline %{
namespace RepeatSpace {
@ -509,24 +551,3 @@ repeat repeatTest(repeat e) { return e; }
%}
#else
%inline %{
namespace RepeatSpace {
typedef enum
{
one = 1,
initial = one,
two,
three,
last = three,
end = last
} repeat;
repeat repeatTest(repeat e) { return e; }
}
%}
#endif

View file

@ -3,5 +3,7 @@
// Test enum wrapping using the typesafe enum pattern in the target language
%include "enumtypesafe.swg"
#define SWIG_TEST_NOCSCONST // For C# typesafe enums
%include "enum_thorough.i"

View file

@ -369,12 +369,51 @@ public class enum_thorough_proper_runme {
i.setMemberInstance(Instances.memberinstance3);
if (i.getMemberInstance() != Instances.memberinstance3) throw new RuntimeException("MemberInstance 1 failed");
}
// ignore enum item tests start
{
if (enum_thorough_proper.ignoreATest(IgnoreTest.IgnoreA.ignoreA_zero).swigValue() != 0) throw new RuntimeException("ignoreATest 0 failed");
if (enum_thorough_proper.ignoreATest(IgnoreTest.IgnoreA.ignoreA_three).swigValue() != 3) throw new RuntimeException("ignoreATest 3 failed");
if (enum_thorough_proper.ignoreATest(IgnoreTest.IgnoreA.ignoreA_ten).swigValue() != 10) throw new RuntimeException("ignoreATest 10 failed");
if (enum_thorough_proper.ignoreATest(IgnoreTest.IgnoreA.ignoreA_eleven).swigValue() != 11) throw new RuntimeException("ignoreATest 11 failed");
if (enum_thorough_proper.ignoreATest(IgnoreTest.IgnoreA.ignoreA_thirteen).swigValue() != 13) throw new RuntimeException("ignoreATest 13 failed");
if (enum_thorough_proper.ignoreATest(IgnoreTest.IgnoreA.ignoreA_fourteen).swigValue() != 14) throw new RuntimeException("ignoreATest 14 failed");
if (enum_thorough_proper.ignoreATest(IgnoreTest.IgnoreA.ignoreA_twenty).swigValue() != 20) throw new RuntimeException("ignoreATest 20 failed");
if (enum_thorough_proper.ignoreATest(IgnoreTest.IgnoreA.ignoreA_thirty).swigValue() != 30) throw new RuntimeException("ignoreATest 30 failed");
if (enum_thorough_proper.ignoreATest(IgnoreTest.IgnoreA.ignoreA_thirty_two).swigValue() != 32) throw new RuntimeException("ignoreATest 32 failed");
if (enum_thorough_proper.ignoreATest(IgnoreTest.IgnoreA.ignoreA_thirty_three).swigValue() != 33) throw new RuntimeException("ignoreATest 33 failed");
}
{
if (enum_thorough_proper.ignoreBTest(IgnoreTest.IgnoreB.ignoreB_eleven).swigValue() != 11) throw new RuntimeException("ignoreBTest 11 failed");
if (enum_thorough_proper.ignoreBTest(IgnoreTest.IgnoreB.ignoreB_twelve).swigValue() != 12) throw new RuntimeException("ignoreBTest 12 failed");
if (enum_thorough_proper.ignoreBTest(IgnoreTest.IgnoreB.ignoreB_thirty_one).swigValue() != 31) throw new RuntimeException("ignoreBTest 31 failed");
if (enum_thorough_proper.ignoreBTest(IgnoreTest.IgnoreB.ignoreB_thirty_two).swigValue() != 32) throw new RuntimeException("ignoreBTest 32 failed");
if (enum_thorough_proper.ignoreBTest(IgnoreTest.IgnoreB.ignoreB_forty_one).swigValue() != 41) throw new RuntimeException("ignoreBTest 41 failed");
if (enum_thorough_proper.ignoreBTest(IgnoreTest.IgnoreB.ignoreB_forty_two).swigValue() != 42) throw new RuntimeException("ignoreBTest 42 failed");
}
{
if (enum_thorough_proper.ignoreCTest(IgnoreTest.IgnoreC.ignoreC_ten).swigValue() != 10) throw new RuntimeException("ignoreCTest 10 failed");
if (enum_thorough_proper.ignoreCTest(IgnoreTest.IgnoreC.ignoreC_twelve).swigValue() != 12) throw new RuntimeException("ignoreCTest 12 failed");
if (enum_thorough_proper.ignoreCTest(IgnoreTest.IgnoreC.ignoreC_thirty).swigValue() != 30) throw new RuntimeException("ignoreCTest 30 failed");
if (enum_thorough_proper.ignoreCTest(IgnoreTest.IgnoreC.ignoreC_thirty_two).swigValue() != 32) throw new RuntimeException("ignoreCTest 32 failed");
if (enum_thorough_proper.ignoreCTest(IgnoreTest.IgnoreC.ignoreC_forty).swigValue() != 40) throw new RuntimeException("ignoreCTest 40 failed");
if (enum_thorough_proper.ignoreCTest(IgnoreTest.IgnoreC.ignoreC_forty_two).swigValue() != 42) throw new RuntimeException("ignoreCTest 42 failed");
}
{
if (enum_thorough_proper.ignoreDTest(IgnoreTest.IgnoreD.ignoreD_twenty_one).swigValue() != 21) throw new RuntimeException("ignoreDTest 21 failed");
if (enum_thorough_proper.ignoreDTest(IgnoreTest.IgnoreD.ignoreD_twenty_two).swigValue() != 22) throw new RuntimeException("ignoreDTest 22 failed");
}
{
if (enum_thorough_proper.ignoreETest(IgnoreTest.IgnoreE.ignoreE_zero).swigValue() != 0) throw new RuntimeException("ignoreETest 0 failed");
if (enum_thorough_proper.ignoreETest(IgnoreTest.IgnoreE.ignoreE_twenty_one).swigValue() != 21) throw new RuntimeException("ignoreETest 21 failed");
if (enum_thorough_proper.ignoreETest(IgnoreTest.IgnoreE.ignoreE_twenty_two).swigValue() != 22) throw new RuntimeException("ignoreETest 22 failed");
}
// ignore enum item tests end
{
if (enum_thorough_proper.repeatTest(repeat.one).swigValue() != 1) throw new RuntimeException("repeatTest 1 failed");
if (enum_thorough_proper.repeatTest(repeat.initial).swigValue() != 1) throw new RuntimeException("repeatTest 2 failed");
if (enum_thorough_proper.repeatTest(repeat.two).swigValue() != 2) throw new RuntimeException("repeatTest 3 failed");
if (enum_thorough_proper.repeatTest(repeat.three).swigValue() != 3) throw new RuntimeException("repeatTest 4 failed");
if (enum_thorough_proper.repeatTest(repeat.last).swigValue() != 3) throw new RuntimeException("repeatTest 5 failed");
if (enum_thorough_proper.repeatTest(repeat.llast).swigValue() != 3) throw new RuntimeException("repeatTest 5 failed");
if (enum_thorough_proper.repeatTest(repeat.end).swigValue() != 3) throw new RuntimeException("repeatTest 6 failed");
}
}

View file

@ -369,12 +369,51 @@ public class enum_thorough_runme {
i.setMemberInstance(Instances.memberinstance3);
if (i.getMemberInstance() != Instances.memberinstance3) throw new RuntimeException("MemberInstance 1 failed");
}
// ignore enum item tests start
{
if (enum_thorough.ignoreATest(IgnoreTest.IgnoreA.ignoreA_zero).swigValue() != 0) throw new RuntimeException("ignoreATest 0 failed");
if (enum_thorough.ignoreATest(IgnoreTest.IgnoreA.ignoreA_three).swigValue() != 3) throw new RuntimeException("ignoreATest 3 failed");
if (enum_thorough.ignoreATest(IgnoreTest.IgnoreA.ignoreA_ten).swigValue() != 10) throw new RuntimeException("ignoreATest 10 failed");
if (enum_thorough.ignoreATest(IgnoreTest.IgnoreA.ignoreA_eleven).swigValue() != 11) throw new RuntimeException("ignoreATest 11 failed");
if (enum_thorough.ignoreATest(IgnoreTest.IgnoreA.ignoreA_thirteen).swigValue() != 13) throw new RuntimeException("ignoreATest 13 failed");
if (enum_thorough.ignoreATest(IgnoreTest.IgnoreA.ignoreA_fourteen).swigValue() != 14) throw new RuntimeException("ignoreATest 14 failed");
if (enum_thorough.ignoreATest(IgnoreTest.IgnoreA.ignoreA_twenty).swigValue() != 20) throw new RuntimeException("ignoreATest 20 failed");
if (enum_thorough.ignoreATest(IgnoreTest.IgnoreA.ignoreA_thirty).swigValue() != 30) throw new RuntimeException("ignoreATest 30 failed");
if (enum_thorough.ignoreATest(IgnoreTest.IgnoreA.ignoreA_thirty_two).swigValue() != 32) throw new RuntimeException("ignoreATest 32 failed");
if (enum_thorough.ignoreATest(IgnoreTest.IgnoreA.ignoreA_thirty_three).swigValue() != 33) throw new RuntimeException("ignoreATest 33 failed");
}
{
if (enum_thorough.ignoreBTest(IgnoreTest.IgnoreB.ignoreB_eleven).swigValue() != 11) throw new RuntimeException("ignoreBTest 11 failed");
if (enum_thorough.ignoreBTest(IgnoreTest.IgnoreB.ignoreB_twelve).swigValue() != 12) throw new RuntimeException("ignoreBTest 12 failed");
if (enum_thorough.ignoreBTest(IgnoreTest.IgnoreB.ignoreB_thirty_one).swigValue() != 31) throw new RuntimeException("ignoreBTest 31 failed");
if (enum_thorough.ignoreBTest(IgnoreTest.IgnoreB.ignoreB_thirty_two).swigValue() != 32) throw new RuntimeException("ignoreBTest 32 failed");
if (enum_thorough.ignoreBTest(IgnoreTest.IgnoreB.ignoreB_forty_one).swigValue() != 41) throw new RuntimeException("ignoreBTest 41 failed");
if (enum_thorough.ignoreBTest(IgnoreTest.IgnoreB.ignoreB_forty_two).swigValue() != 42) throw new RuntimeException("ignoreBTest 42 failed");
}
{
if (enum_thorough.ignoreCTest(IgnoreTest.IgnoreC.ignoreC_ten).swigValue() != 10) throw new RuntimeException("ignoreCTest 10 failed");
if (enum_thorough.ignoreCTest(IgnoreTest.IgnoreC.ignoreC_twelve).swigValue() != 12) throw new RuntimeException("ignoreCTest 12 failed");
if (enum_thorough.ignoreCTest(IgnoreTest.IgnoreC.ignoreC_thirty).swigValue() != 30) throw new RuntimeException("ignoreCTest 30 failed");
if (enum_thorough.ignoreCTest(IgnoreTest.IgnoreC.ignoreC_thirty_two).swigValue() != 32) throw new RuntimeException("ignoreCTest 32 failed");
if (enum_thorough.ignoreCTest(IgnoreTest.IgnoreC.ignoreC_forty).swigValue() != 40) throw new RuntimeException("ignoreCTest 40 failed");
if (enum_thorough.ignoreCTest(IgnoreTest.IgnoreC.ignoreC_forty_two).swigValue() != 42) throw new RuntimeException("ignoreCTest 42 failed");
}
{
if (enum_thorough.ignoreDTest(IgnoreTest.IgnoreD.ignoreD_twenty_one).swigValue() != 21) throw new RuntimeException("ignoreDTest 21 failed");
if (enum_thorough.ignoreDTest(IgnoreTest.IgnoreD.ignoreD_twenty_two).swigValue() != 22) throw new RuntimeException("ignoreDTest 22 failed");
}
{
if (enum_thorough.ignoreETest(IgnoreTest.IgnoreE.ignoreE_zero).swigValue() != 0) throw new RuntimeException("ignoreETest 0 failed");
if (enum_thorough.ignoreETest(IgnoreTest.IgnoreE.ignoreE_twenty_one).swigValue() != 21) throw new RuntimeException("ignoreETest 21 failed");
if (enum_thorough.ignoreETest(IgnoreTest.IgnoreE.ignoreE_twenty_two).swigValue() != 22) throw new RuntimeException("ignoreETest 22 failed");
}
// ignore enum item tests end
{
if (enum_thorough.repeatTest(repeat.one).swigValue() != 1) throw new RuntimeException("repeatTest 1 failed");
if (enum_thorough.repeatTest(repeat.initial).swigValue() != 1) throw new RuntimeException("repeatTest 2 failed");
if (enum_thorough.repeatTest(repeat.two).swigValue() != 2) throw new RuntimeException("repeatTest 3 failed");
if (enum_thorough.repeatTest(repeat.three).swigValue() != 3) throw new RuntimeException("repeatTest 4 failed");
if (enum_thorough.repeatTest(repeat.last).swigValue() != 3) throw new RuntimeException("repeatTest 5 failed");
if (enum_thorough.repeatTest(repeat.llast).swigValue() != 3) throw new RuntimeException("repeatTest 5 failed");
if (enum_thorough.repeatTest(repeat.end).swigValue() != 3) throw new RuntimeException("repeatTest 6 failed");
}
}

View file

@ -369,12 +369,51 @@ public class enum_thorough_simple_runme {
i.setMemberInstance(Instances.memberinstance3);
if (i.getMemberInstance() != Instances.memberinstance3) throw new RuntimeException("MemberInstance 1 failed");
}
// ignore enum item tests start
{
if (enum_thorough_simple.ignoreATest(IgnoreTest.ignoreA_zero) != 0) throw new RuntimeException("ignoreATest 0 failed");
if (enum_thorough_simple.ignoreATest(IgnoreTest.ignoreA_three) != 3) throw new RuntimeException("ignoreATest 3 failed");
if (enum_thorough_simple.ignoreATest(IgnoreTest.ignoreA_ten) != 10) throw new RuntimeException("ignoreATest 10 failed");
if (enum_thorough_simple.ignoreATest(IgnoreTest.ignoreA_eleven) != 11) throw new RuntimeException("ignoreATest 11 failed");
if (enum_thorough_simple.ignoreATest(IgnoreTest.ignoreA_thirteen) != 13) throw new RuntimeException("ignoreATest 13 failed");
if (enum_thorough_simple.ignoreATest(IgnoreTest.ignoreA_fourteen) != 14) throw new RuntimeException("ignoreATest 14 failed");
if (enum_thorough_simple.ignoreATest(IgnoreTest.ignoreA_twenty) != 20) throw new RuntimeException("ignoreATest 20 failed");
if (enum_thorough_simple.ignoreATest(IgnoreTest.ignoreA_thirty) != 30) throw new RuntimeException("ignoreATest 30 failed");
if (enum_thorough_simple.ignoreATest(IgnoreTest.ignoreA_thirty_two) != 32) throw new RuntimeException("ignoreATest 32 failed");
if (enum_thorough_simple.ignoreATest(IgnoreTest.ignoreA_thirty_three) != 33) throw new RuntimeException("ignoreATest 33 failed");
}
{
if (enum_thorough_simple.ignoreBTest(IgnoreTest.ignoreB_eleven) != 11) throw new RuntimeException("ignoreBTest 11 failed");
if (enum_thorough_simple.ignoreBTest(IgnoreTest.ignoreB_twelve) != 12) throw new RuntimeException("ignoreBTest 12 failed");
if (enum_thorough_simple.ignoreBTest(IgnoreTest.ignoreB_thirty_one) != 31) throw new RuntimeException("ignoreBTest 31 failed");
if (enum_thorough_simple.ignoreBTest(IgnoreTest.ignoreB_thirty_two) != 32) throw new RuntimeException("ignoreBTest 32 failed");
if (enum_thorough_simple.ignoreBTest(IgnoreTest.ignoreB_forty_one) != 41) throw new RuntimeException("ignoreBTest 41 failed");
if (enum_thorough_simple.ignoreBTest(IgnoreTest.ignoreB_forty_two) != 42) throw new RuntimeException("ignoreBTest 42 failed");
}
{
if (enum_thorough_simple.ignoreCTest(IgnoreTest.ignoreC_ten) != 10) throw new RuntimeException("ignoreCTest 10 failed");
if (enum_thorough_simple.ignoreCTest(IgnoreTest.ignoreC_twelve) != 12) throw new RuntimeException("ignoreCTest 12 failed");
if (enum_thorough_simple.ignoreCTest(IgnoreTest.ignoreC_thirty) != 30) throw new RuntimeException("ignoreCTest 30 failed");
if (enum_thorough_simple.ignoreCTest(IgnoreTest.ignoreC_thirty_two) != 32) throw new RuntimeException("ignoreCTest 32 failed");
if (enum_thorough_simple.ignoreCTest(IgnoreTest.ignoreC_forty) != 40) throw new RuntimeException("ignoreCTest 40 failed");
if (enum_thorough_simple.ignoreCTest(IgnoreTest.ignoreC_forty_two) != 42) throw new RuntimeException("ignoreCTest 42 failed");
}
{
if (enum_thorough_simple.ignoreDTest(IgnoreTest.ignoreD_twenty_one) != 21) throw new RuntimeException("ignoreDTest 21 failed");
if (enum_thorough_simple.ignoreDTest(IgnoreTest.ignoreD_twenty_two) != 22) throw new RuntimeException("ignoreDTest 22 failed");
}
{
if (enum_thorough_simple.ignoreETest(IgnoreTest.ignoreE_zero) != 0) throw new RuntimeException("ignoreETest 0 failed");
if (enum_thorough_simple.ignoreETest(IgnoreTest.ignoreE_twenty_one) != 21) throw new RuntimeException("ignoreETest 21 failed");
if (enum_thorough_simple.ignoreETest(IgnoreTest.ignoreE_twenty_two) != 22) throw new RuntimeException("ignoreETest 22 failed");
}
// ignore enum item tests end
{
if (enum_thorough_simple.repeatTest(enum_thorough_simpleConstants.one) != 1) throw new RuntimeException("repeatTest 1 failed");
if (enum_thorough_simple.repeatTest(enum_thorough_simpleConstants.initial) != 1) throw new RuntimeException("repeatTest 2 failed");
if (enum_thorough_simple.repeatTest(enum_thorough_simpleConstants.two) != 2) throw new RuntimeException("repeatTest 3 failed");
if (enum_thorough_simple.repeatTest(enum_thorough_simpleConstants.three) != 3) throw new RuntimeException("repeatTest 4 failed");
if (enum_thorough_simple.repeatTest(enum_thorough_simpleConstants.last) != 3) throw new RuntimeException("repeatTest 5 failed");
if (enum_thorough_simple.repeatTest(enum_thorough_simpleConstants.llast) != 3) throw new RuntimeException("repeatTest 5 failed");
if (enum_thorough_simple.repeatTest(enum_thorough_simpleConstants.end) != 3) throw new RuntimeException("repeatTest 6 failed");
}
}

View file

@ -369,12 +369,51 @@ public class enum_thorough_typeunsafe_runme {
i.setMemberInstance(Instances.memberinstance3);
if (i.getMemberInstance() != Instances.memberinstance3) throw new RuntimeException("MemberInstance 1 failed");
}
// ignore enum item tests start
{
if (enum_thorough_typeunsafe.ignoreATest(IgnoreTest.IgnoreA.ignoreA_zero) != 0) throw new RuntimeException("ignoreATest 0 failed");
if (enum_thorough_typeunsafe.ignoreATest(IgnoreTest.IgnoreA.ignoreA_three) != 3) throw new RuntimeException("ignoreATest 3 failed");
if (enum_thorough_typeunsafe.ignoreATest(IgnoreTest.IgnoreA.ignoreA_ten) != 10) throw new RuntimeException("ignoreATest 10 failed");
if (enum_thorough_typeunsafe.ignoreATest(IgnoreTest.IgnoreA.ignoreA_eleven) != 11) throw new RuntimeException("ignoreATest 11 failed");
if (enum_thorough_typeunsafe.ignoreATest(IgnoreTest.IgnoreA.ignoreA_thirteen) != 13) throw new RuntimeException("ignoreATest 13 failed");
if (enum_thorough_typeunsafe.ignoreATest(IgnoreTest.IgnoreA.ignoreA_fourteen) != 14) throw new RuntimeException("ignoreATest 14 failed");
if (enum_thorough_typeunsafe.ignoreATest(IgnoreTest.IgnoreA.ignoreA_twenty) != 20) throw new RuntimeException("ignoreATest 20 failed");
if (enum_thorough_typeunsafe.ignoreATest(IgnoreTest.IgnoreA.ignoreA_thirty) != 30) throw new RuntimeException("ignoreATest 30 failed");
if (enum_thorough_typeunsafe.ignoreATest(IgnoreTest.IgnoreA.ignoreA_thirty_two) != 32) throw new RuntimeException("ignoreATest 32 failed");
if (enum_thorough_typeunsafe.ignoreATest(IgnoreTest.IgnoreA.ignoreA_thirty_three) != 33) throw new RuntimeException("ignoreATest 33 failed");
}
{
if (enum_thorough_typeunsafe.ignoreBTest(IgnoreTest.IgnoreB.ignoreB_eleven) != 11) throw new RuntimeException("ignoreBTest 11 failed");
if (enum_thorough_typeunsafe.ignoreBTest(IgnoreTest.IgnoreB.ignoreB_twelve) != 12) throw new RuntimeException("ignoreBTest 12 failed");
if (enum_thorough_typeunsafe.ignoreBTest(IgnoreTest.IgnoreB.ignoreB_thirty_one) != 31) throw new RuntimeException("ignoreBTest 31 failed");
if (enum_thorough_typeunsafe.ignoreBTest(IgnoreTest.IgnoreB.ignoreB_thirty_two) != 32) throw new RuntimeException("ignoreBTest 32 failed");
if (enum_thorough_typeunsafe.ignoreBTest(IgnoreTest.IgnoreB.ignoreB_forty_one) != 41) throw new RuntimeException("ignoreBTest 41 failed");
if (enum_thorough_typeunsafe.ignoreBTest(IgnoreTest.IgnoreB.ignoreB_forty_two) != 42) throw new RuntimeException("ignoreBTest 42 failed");
}
{
if (enum_thorough_typeunsafe.ignoreCTest(IgnoreTest.IgnoreC.ignoreC_ten) != 10) throw new RuntimeException("ignoreCTest 10 failed");
if (enum_thorough_typeunsafe.ignoreCTest(IgnoreTest.IgnoreC.ignoreC_twelve) != 12) throw new RuntimeException("ignoreCTest 12 failed");
if (enum_thorough_typeunsafe.ignoreCTest(IgnoreTest.IgnoreC.ignoreC_thirty) != 30) throw new RuntimeException("ignoreCTest 30 failed");
if (enum_thorough_typeunsafe.ignoreCTest(IgnoreTest.IgnoreC.ignoreC_thirty_two) != 32) throw new RuntimeException("ignoreCTest 32 failed");
if (enum_thorough_typeunsafe.ignoreCTest(IgnoreTest.IgnoreC.ignoreC_forty) != 40) throw new RuntimeException("ignoreCTest 40 failed");
if (enum_thorough_typeunsafe.ignoreCTest(IgnoreTest.IgnoreC.ignoreC_forty_two) != 42) throw new RuntimeException("ignoreCTest 42 failed");
}
{
if (enum_thorough_typeunsafe.ignoreDTest(IgnoreTest.IgnoreD.ignoreD_twenty_one) != 21) throw new RuntimeException("ignoreDTest 21 failed");
if (enum_thorough_typeunsafe.ignoreDTest(IgnoreTest.IgnoreD.ignoreD_twenty_two) != 22) throw new RuntimeException("ignoreDTest 22 failed");
}
{
if (enum_thorough_typeunsafe.ignoreETest(IgnoreTest.IgnoreE.ignoreE_zero) != 0) throw new RuntimeException("ignoreETest 0 failed");
if (enum_thorough_typeunsafe.ignoreETest(IgnoreTest.IgnoreE.ignoreE_twenty_one) != 21) throw new RuntimeException("ignoreETest 21 failed");
if (enum_thorough_typeunsafe.ignoreETest(IgnoreTest.IgnoreE.ignoreE_twenty_two) != 22) throw new RuntimeException("ignoreETest 22 failed");
}
// ignore enum item tests end
{
if (enum_thorough_typeunsafe.repeatTest(repeat.one) != 1) throw new RuntimeException("repeatTest 1 failed");
if (enum_thorough_typeunsafe.repeatTest(repeat.initial) != 1) throw new RuntimeException("repeatTest 2 failed");
if (enum_thorough_typeunsafe.repeatTest(repeat.two) != 2) throw new RuntimeException("repeatTest 3 failed");
if (enum_thorough_typeunsafe.repeatTest(repeat.three) != 3) throw new RuntimeException("repeatTest 4 failed");
if (enum_thorough_typeunsafe.repeatTest(repeat.last) != 3) throw new RuntimeException("repeatTest 5 failed");
if (enum_thorough_typeunsafe.repeatTest(repeat.llast) != 3) throw new RuntimeException("repeatTest 5 failed");
if (enum_thorough_typeunsafe.repeatTest(repeat.end) != 3) throw new RuntimeException("repeatTest 6 failed");
}
}

View file

@ -1,45 +1,96 @@
/**
* @file li_std_map.i
* @author gga
* @date Mon Apr 30 15:03:58 2007
*
* @brief a test of map containers.
* Languages should define swig::LANGUAGE_OBJ to be
* an entity of their native pointer type which can be
* included in a STL container.
*
* For example:
* swig::LANGUAGE_OBJ is GC_VALUE in Ruby
* swig::LANGUAGE_OBJ is SwigPtr_PyObject in python
*
*
*/
%module("templatereduce") li_std_map
%feature("trackobjects");
%include std_pair.i
%include std_map.i
%include std_multimap.i
%include "std_pair.i"
%include "std_map.i"
%include "std_string.i"
// Declare some maps to play around with
%template(IntIntMap) std::map<int, int>;
%template(StringIntMap) std::map<std::string, int>;
%ignore Struct::operator<;
%ignore Struct::operator==;
// Add an inline function to test
%inline %{
struct A{
int val;
A(int v = 0): val(v)
{
}
double valueAverage(std::map<std::string, int> m) {
if (m.size() == 0) {
return 0.0;
}
double a = 0.0;
for (std::map<std::string, int>::iterator i = m.begin(); i != m.end(); i++) {
a += i->second;
}
return a / m.size();
}
std::string stringifyKeys(std::map<std::string, int> m) {
std::string a;
for (std::map<std::string, int>::iterator i = m.begin(); i != m.end(); i++) {
a += " " + i->first;
}
return a;
}
struct Struct {
double num;
Struct() : num(0.0) {}
Struct(double d) : num(d) {}
bool operator<(const Struct &other) const { return num < other.num; }
bool operator==(const Struct &other) const { return num == other.num; }
};
%}
namespace std
{
#if defined(SWIGCSHARP)
// Specialize some more non-default map types
SWIG_STD_MAP_SPECIALIZED(int, int *, int, SWIGTYPE_p_int)
SWIG_STD_MAP_SPECIALIZED(int, const int *, int, SWIGTYPE_p_int)
SWIG_STD_MAP_SPECIALIZED_SIMPLE(int, Struct)
SWIG_STD_MAP_SPECIALIZED(int, Struct *, int, Struct)
SWIG_STD_MAP_SPECIALIZED(int, const Struct *, int, Struct)
SWIG_STD_MAP_SPECIALIZED(Struct *, int, Struct, int)
#endif
//#if !defined(SWIGR)
// Test out some maps with pointer types
%template(IntIntPtrMap) std::map<int, int *>;
%template(IntConstIntPtrMap) std::map<int, const int *>;
//#endif
// Test out some maps with non-basic types and non-basic pointer types
%template(IntStructMap) std::map<int, Struct>;
%template(IntStructPtrMap) std::map<int, Struct *>;
%template(IntStructConstPtrMap) std::map<int, const Struct *>;
%template(StructPtrIntMap) std::map<Struct *, int>;
// Test out a non-specialized map
%template(StructIntMap) std::map<Struct, int>;
// Additional map definitions for Ruby, Python and Octave tests
%inline %{
struct A{
int val;
A(int v = 0): val(v) {
}
};
%}
namespace std {
%template(pairii) pair<int, int>;
%template(pairAA) pair<int, A>;
%template(pairA) pair<int, A*>;
%template(mapA) map<int, A*>;
%template(mmapA) multimap<int, A*>;
%template(paircA1) pair<const int, A*>;
%template(paircA2) pair<const int, const A*>;
@ -59,25 +110,14 @@ namespace std
}
%inline {
std::pair<int, A*> p_identa(std::pair<int, A*> p) {
return p;
}
%inline
{
std::pair<int, A*>
p_identa(std::pair<int, A*> p) {
return p;
}
std::map<int,A*> m_identa(const std::map<int,A*>& v)
{
return v;
}
std::map<int, A*> m_identa(const std::map<int,A*>& v) {
return v;
}
}
namespace std
{
%template(mapii) map<int,int>;
}

View file

@ -0,0 +1,25 @@
%module("templatereduce") li_std_multimap
%feature("trackobjects");
%include std_pair.i
%include std_map.i
%include std_multimap.i
%inline %{
struct A{
int val;
A(int v = 0): val(v)
{
}
};
%}
namespace std
{
%template(pairA) pair<int, A*>;
%template(mapA) map<int, A*>;
%template(multimapA) multimap<int, A*>;
}

View file

@ -49,7 +49,7 @@ for k in pm,
endif
endfor
mii = li_std_map.mapii();
mii = li_std_map.IntIntMap();
mii{1} = 1;
mii{1} = 2;

View file

@ -15,6 +15,7 @@ CPP_TEST_CASES += \
li_cdata \
li_cstring \
li_cdata_carrays \
byreference \
C_TEST_CASES += \
li_cdata \

View file

@ -0,0 +1,52 @@
%module byreference
%include "reference.i"
%inline %{
double FrVal;
double ToVal;
void PDouble(double *REFERENCE, int t = 0)
{ ToVal = *REFERENCE; *REFERENCE = FrVal + t; }
void RDouble(double &REFERENCE, int t = 0)
{ ToVal = REFERENCE; REFERENCE = FrVal + t; }
void PFloat(float *REFERENCE, int t = 0)
{ ToVal = *REFERENCE; *REFERENCE = FrVal + t; }
void RFloat(float &REFERENCE, int t = 0)
{ ToVal = REFERENCE; REFERENCE = FrVal + t; }
void PInt(int *REFERENCE, int t = 0)
{ ToVal = *REFERENCE; *REFERENCE = FrVal + t; }
void RInt(int &REFERENCE, int t = 0)
{ ToVal = REFERENCE; REFERENCE = FrVal + t; }
void PShort(short *REFERENCE, int t = 0)
{ ToVal = *REFERENCE; *REFERENCE = FrVal + t; }
void RShort(short &REFERENCE, int t = 0)
{ ToVal = REFERENCE; REFERENCE = FrVal + t; }
void PLong(long *REFERENCE, int t = 0)
{ ToVal = *REFERENCE; *REFERENCE = FrVal + t; }
void RLong(long &REFERENCE, int t = 0)
{ ToVal = REFERENCE; REFERENCE = FrVal + t; }
void PUInt(unsigned int *REFERENCE, int t = 0)
{ ToVal = *REFERENCE; *REFERENCE = FrVal + t; }
void RUInt(unsigned int &REFERENCE, int t = 0)
{ ToVal = REFERENCE; REFERENCE = FrVal + t; }
void PUShort(unsigned short *REFERENCE, int t = 0)
{ ToVal = *REFERENCE; *REFERENCE = FrVal + t; }
void RUShort(unsigned short &REFERENCE, int t = 0)
{ ToVal = REFERENCE; REFERENCE = FrVal + t; }
void PULong(unsigned long *REFERENCE, int t = 0)
{ ToVal = *REFERENCE; *REFERENCE = FrVal + t; }
void RULong(unsigned long &REFERENCE, int t = 0)
{ ToVal = REFERENCE; REFERENCE = FrVal + t; }
void PUChar(unsigned char *REFERENCE, int t = 0)
{ ToVal = *REFERENCE; *REFERENCE = FrVal + t; }
void RUChar(unsigned char &REFERENCE, int t = 0)
{ ToVal = REFERENCE; REFERENCE = FrVal + t; }
void PChar(signed char *REFERENCE, int t = 0)
{ ToVal = *REFERENCE; *REFERENCE = FrVal + t; }
void RChar(signed char &REFERENCE, int t = 0)
{ ToVal = REFERENCE; REFERENCE = FrVal + t; }
void PBool(bool *REFERENCE, int t = 0)
{ ToVal = *REFERENCE; *REFERENCE = FrVal + t; }
void RBool(bool &REFERENCE, int t = 0)
{ ToVal = REFERENCE; REFERENCE = FrVal + t; }
%}

View file

@ -0,0 +1,36 @@
use strict;
use warnings;
use Test::More tests => 68;
BEGIN { use_ok('byreference') }
require_ok('byreference');
sub chk { my($type, $call, $v1, $v2) = @_;
$byreference::FrVal = $v1;
my $v = $v2;
eval { $call->(\$v) };
is($@, '', "$type check");
is($byreference::ToVal, $v2, "$type out");
is($v, $v1, "$type in");
}
chk("double*", \&byreference::PDouble, 12.2, 18.6);
chk("double&", \&byreference::RDouble, 32.5, 64.8);
chk("float*", \&byreference::PFloat, 64.5, 96.0);
chk("float&", \&byreference::RFloat, 98.5, 6.25);
chk("int*", \&byreference::PInt, 1887, 3356);
chk("int&", \&byreference::RInt, 2622, 9867);
chk("short*", \&byreference::PShort, 4752, 3254);
chk("short&", \&byreference::RShort, 1898, 5757);
chk("long*", \&byreference::PLong, 6687, 7132);
chk("long&", \&byreference::RLong, 8346, 4398);
chk("uint*", \&byreference::PUInt, 6853, 5529);
chk("uint&", \&byreference::RUInt, 5483, 7135);
chk("ushort*", \&byreference::PUShort, 9960, 9930);
chk("ushort&", \&byreference::RUShort, 1193, 4178);
chk("ulong*", \&byreference::PULong, 7960, 4788);
chk("ulong&", \&byreference::RULong, 8829, 1603);
chk("uchar*", \&byreference::PUChar, 110, 239);
chk("uchar&", \&byreference::RUChar, 15, 97);
chk("char*", \&byreference::PChar, -7, 118);
chk("char&", \&byreference::RChar, -3, -107);
chk("bool*", \&byreference::PBool, 0, 1);
chk("bool&", \&byreference::RBool, 1, 0);

View file

@ -1,7 +1,7 @@
# an adaptation of ../java/enum_thorough_runme.java
use strict;
use warnings;
use Test::More tests => 272;
use Test::More tests => 298;
BEGIN { use_ok('enum_thorough') }
require_ok('enum_thorough');
@ -348,17 +348,51 @@ SKIP: {
$i->{MemberInstance} = $enum_thorough::Instances::memberinstance3;
is($i->{MemberInstance}, $enum_thorough::Instances::memberinstance3, "MemberInstance 1");
}
# ignore enum item tests start
{
is(enum_thorough::ignoreATest($enum_thorough::IgnoreTest::ignoreA_zero), 0, "ignoreATest 0");
is(enum_thorough::ignoreATest($enum_thorough::IgnoreTest::ignoreA_three), 3, "ignoreATest 3");
is(enum_thorough::ignoreATest($enum_thorough::IgnoreTest::ignoreA_ten), 10, "ignoreATest 10");
is(enum_thorough::ignoreATest($enum_thorough::IgnoreTest::ignoreA_eleven), 11, "ignoreATest 11");
is(enum_thorough::ignoreATest($enum_thorough::IgnoreTest::ignoreA_thirteen), 13, "ignoreATest 13");
is(enum_thorough::ignoreATest($enum_thorough::IgnoreTest::ignoreA_fourteen), 14, "ignoreATest 14");
is(enum_thorough::ignoreATest($enum_thorough::IgnoreTest::ignoreA_twenty), 20, "ignoreATest 20");
is(enum_thorough::ignoreATest($enum_thorough::IgnoreTest::ignoreA_thirty), 30, "ignoreATest 30");
is(enum_thorough::ignoreATest($enum_thorough::IgnoreTest::ignoreA_thirty_two), 32, "ignoreATest 32");
is(enum_thorough::ignoreATest($enum_thorough::IgnoreTest::ignoreA_thirty_three), 33, "ignoreATest 33");
}
{
is(enum_thorough::ignoreBTest($enum_thorough::IgnoreTest::ignoreB_eleven), 11, "ignoreBTest 11");
is(enum_thorough::ignoreBTest($enum_thorough::IgnoreTest::ignoreB_twelve), 12, "ignoreBTest 12");
is(enum_thorough::ignoreBTest($enum_thorough::IgnoreTest::ignoreB_thirty_one), 31, "ignoreBTest 31");
is(enum_thorough::ignoreBTest($enum_thorough::IgnoreTest::ignoreB_thirty_two), 32, "ignoreBTest 32");
is(enum_thorough::ignoreBTest($enum_thorough::IgnoreTest::ignoreB_forty_one), 41, "ignoreBTest 41");
is(enum_thorough::ignoreBTest($enum_thorough::IgnoreTest::ignoreB_forty_two), 42, "ignoreBTest 42");
}
{
is(enum_thorough::ignoreCTest($enum_thorough::IgnoreTest::ignoreC_ten), 10, "ignoreCTest 10");
is(enum_thorough::ignoreCTest($enum_thorough::IgnoreTest::ignoreC_twelve), 12, "ignoreCTest 12");
is(enum_thorough::ignoreCTest($enum_thorough::IgnoreTest::ignoreC_thirty), 30, "ignoreCTest 30");
is(enum_thorough::ignoreCTest($enum_thorough::IgnoreTest::ignoreC_thirty_two), 32, "ignoreCTest 32");
is(enum_thorough::ignoreCTest($enum_thorough::IgnoreTest::ignoreC_forty), 40, "ignoreCTest 40");
is(enum_thorough::ignoreCTest($enum_thorough::IgnoreTest::ignoreC_forty_two), 42, "ignoreCTest 42");
}
{
is(enum_thorough::ignoreDTest($enum_thorough::IgnoreTest::ignoreD_twenty_one), 21, "ignoreDTest 21");
is(enum_thorough::ignoreDTest($enum_thorough::IgnoreTest::ignoreD_twenty_two), 22, "ignoreDTest 22");
}
{
is(enum_thorough::ignoreETest($enum_thorough::IgnoreTest::ignoreE_zero), 0, "ignoreETest 0");
is(enum_thorough::ignoreETest($enum_thorough::IgnoreTest::ignoreE_twenty_one), 21, "ignoreETest 21");
is(enum_thorough::ignoreETest($enum_thorough::IgnoreTest::ignoreE_twenty_two), 22, "ignoreETest 22");
}
# ignore enum item tests end
{
is(enum_thorough::repeatTest($enum_thorough::one), 1, "repeatTest 1");
is(enum_thorough::repeatTest($enum_thorough::initial), 1, "repeatTest 2");
is(enum_thorough::repeatTest($enum_thorough::two), 2, "repeatTest 3");
is(enum_thorough::repeatTest($enum_thorough::three), 3, "repeatTest 4");
{ local $TODO = "overzealous keyword guarding";
ok(defined($enum_thorough::last), "found enum value");
SKIP: {
skip "enum value not in expected package", 1 unless defined $enum_thorough::last;
is(enum_thorough::repeatTest($enum_thorough::last), 3, "repeatTest 5");
}}
is(enum_thorough::repeatTest($enum_thorough::llast), 3, "repeatTest 5");
is(enum_thorough::repeatTest($enum_thorough::end), 3, "repeatTest 6");
}
@ -368,8 +402,8 @@ SKIP: {
is(enum_thorough::speedTest4($enum_thorough::SpeedClass::slow),
$enum_thorough::SpeedClass::slow, "speedTest Global 4");
is(enum_thorough::speedTest5($enum_thorough::SpeedClass::slow),
$enum_thorough::SpeedClass::slow, "speedTest Global 5 failed");
$enum_thorough::SpeedClass::slow, "speedTest Global 5");
is(enum_thorough::speedTest4($enum_thorough::SpeedClass::fast),
$enum_thorough::SpeedClass::fast, "speedTest Global 4 failed");
$enum_thorough::SpeedClass::fast, "speedTest Global 4");
is(enum_thorough::speedTest5($enum_thorough::SpeedClass::fast),
$enum_thorough::SpeedClass::fast, "speedTest Global 5 failed");
$enum_thorough::SpeedClass::fast, "speedTest Global 5");

View file

@ -16,28 +16,12 @@ include $(srcdir)/../common.mk
# Overridden variables here
TARGETPREFIX =# Should be php_ for Windows, empty otherwise
makecpptests:
@bash -ec 'for test in $(CPP_TEST_CASES) ; do $(MAKE) clean && $(MAKE) $${test}.cpptest; done'
maketests: makecpptests makectests
makectests:
@bash -ec 'for test in $(C_TEST_CASES) ; do $($(MAKE)) clean && $(MAKE) $${test}.cpptest; done'
runcpptests:
@bash -ec 'for test in $(CPP_TEST_CASES) ; do if [ -f $${test}_runme.php ] ; then $(MAKE) clean && $(MAKE) $${test}.cpptest; fi ; done'
runctests:
@bash -ec 'for test in $(C_TEST_CASES) ; do if [ -f $${test}_runme.php ] ; then $(MAKE) clean && $(MAKE) $${test}.cpptest; fi; done'
runtests: runcpptests runctests
# write out tests without a _runme.php
missingcpptests:
@bash -ec 'for test in $(CPP_TEST_CASES) ; do test -f $${test}_runme.php || echo $${test}; done'
for test in $(CPP_TEST_CASES) ; do test -f $${test}_runme.php || echo $${test}; done
missingctests:
@bash -ec 'for test in $(C_TEST_CASES) ; do test -f $${test}_runme.php || echo $${test}; done'
for test in $(C_TEST_CASES) ; do test -f $${test}_runme.php || echo $${test}; done
missingtests: missingcpptests missingctests

View file

@ -50,6 +50,7 @@ CPP_TEST_CASES += \
li_std_vectora \
li_std_vector_extra \
li_std_map \
li_std_multimap \
li_std_pair_extra \
li_std_set \
li_std_stream \

View file

@ -48,7 +48,7 @@ for k in pm:
mii = li_std_map.mapii()
mii = li_std_map.IntIntMap()
mii[1] = 1
mii[1] = 2

View file

@ -15,6 +15,7 @@ CPP_TEST_CASES = \
li_factory \
li_std_functors \
li_std_map \
li_std_multimap \
li_std_pair_lang_object \
li_std_queue \
li_std_set \

View file

@ -1,6 +1,6 @@
#!/usr/bin/env ruby
#
# Tests for std::map and std::multimap
# Tests for std::map
#
#
#
@ -41,18 +41,9 @@ m["foo"] = "hello"
pm = Li_std_map::LanguageMap.new
m.each_key { |k| pm[k] = m[k] }
m.each_key { |k| swig_assert_equal("pm[#{k.inspect}]", "m[#{k.inspect}]", binding) }
m = Li_std_map::MmapA.new
m[0] = a1
m[0] = a2
m[0].size == 2
m.respond_to?(:each) == true
m.respond_to?(:each_key) == true
m.respond_to?(:each_value) == true
m.values_at(0)[0] == m[0]
EOF
mii = Li_std_map::Mapii.new
mii = Li_std_map::IntIntMap.new
mii[1] = 1
mii[1] = 2

View file

@ -0,0 +1,27 @@
#!/usr/bin/env ruby
#
# Tests for std::multimap
#
#
#
#
#
require 'swig_assert'
require 'li_std_multimap'
swig_assert_each_line(<<'EOF', binding)
a1 = Li_std_multimap::A.new(3)
a2 = Li_std_multimap::A.new(7)
m = Li_std_multimap::MultimapA.new
m[0] = a1
m[0] = a2
m[0].size == 2
m.respond_to?(:each) == true
m.respond_to?(:each_key) == true
m.respond_to?(:each_value) == true
m.values_at(0)[0] == m[0]
EOF

View file

@ -50,6 +50,14 @@
(void)stardesc;
(void)ampdesc;
}
{ /* Test descriptor macro */
void *desc = $descriptor(const struct xyzzy **);
void *stardesc = $descriptor(const struct xyzzy *);
void *ampdesc = $descriptor(const struct xyzzy ***);
(void)desc;
(void)stardesc;
(void)ampdesc;
}
$1 = ($ltype) temp;
}

View file

@ -803,6 +803,19 @@ SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
/* Array reference typemaps */
%apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) }
/* Marshal C/C++ pointer to IntPtr */
%typemap(ctype) void *VOID_INT_PTR "void *"
%typemap(imtype) void *VOID_INT_PTR "IntPtr"
%typemap(cstype) void *VOID_INT_PTR "IntPtr"
%typemap(in) void *VOID_INT_PTR %{ $1 = ($1_ltype)$input; %}
%typemap(out) void *VOID_INT_PTR %{ $result = (void *)$1; %}
%typemap(csin) void *VOID_INT_PTR "$csinput"
%typemap(csout, excode=SWIGEXCODE) void *VOID_INT_PTR {
IntPtr ret = $imcall;$excode
return ret;
}
/* Typemaps used for the generation of proxy and type wrapper class code */
%typemap(csbase) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) ""
%typemap(csclassmodifiers) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) "public class"

View file

@ -68,7 +68,7 @@ static SWIG_CSharpException_t SWIG_csharp_exceptions[] = {
static SWIG_CSharpExceptionArgument_t SWIG_csharp_exceptions_argument[] = {
{ SWIG_CSharpArgumentException, NULL },
{ SWIG_CSharpArgumentNullException, NULL },
{ SWIG_CSharpArgumentOutOfRangeException, NULL },
{ SWIG_CSharpArgumentOutOfRangeException, NULL }
};
static void SWIGUNUSED SWIG_CSharpSetPendingException(SWIG_CSharpExceptionCodes code, const char *msg) {

View file

@ -5,171 +5,618 @@
* std_map.i
*
* SWIG typemaps for std::map
*
* The C# wrapper is made to look and feel like a C# System.Collections.Generic.IDictionary<>.
*
* Using this wrapper is fairly simple. For example, to create a map from integers to doubles use:
*
* %include <std_map.i>
* %template(Map_Int_Double) std::map<int, double>
*
* Very often the C# generated code will not compile as the C++ template type is not the same as the C#
* proxy type, so use the SWIG_STD_MAP_SPECIALIZED or SWIG_STD_MAP_SPECIALIZED_SIMPLE macros. For example:
*
* SWIG_STD_MAP_SPECIALIZED(MyCppKeyClass, MyCppValueClass, MyCsKeyClass, MyCsValueClass)
* %template(Map_MyCppKeyClass_MyCppValueClass) std::map<MyCppKeyClass, MyCppValueClass >;
*
* Or if the C# class names are the same as the C++ class names, you can use:
*
* SWIG_STD_MAP_SPECIALIZED_SIMPLE(MyKeyClass, MyValueClass)
* %template(Map_MyCppKeyClass_MyCppValueClass) std::map<MyKeyClass, MyValueClass >;
*
* Notes:
* 1) For .NET 1 compatibility, define SWIG_DOTNET_1 when compiling the C# code. In this case
* the C# wrapper has only basic functionality.
* 2) IEnumerable<> is implemented in the proxy class which is useful for using LINQ with
* C++ std::map wrappers.
*
* Warning: heavy macro usage in this file. Use swig -E to get a sane view on the real file contents!
* ----------------------------------------------------------------------------- */
%include <std_common.i>
// ------------------------------------------------------------------------
// std::map
// ------------------------------------------------------------------------
%{
#include <map>
#include <algorithm>
#include <stdexcept>
%}
// exported class
// A minimal implementation to be used when no specialization exists.
%define SWIG_STD_MAP_MINIMAL_INTERNAL(K, T)
public:
map();
map(const map<K, T > &other);
typedef K key_type;
typedef T mapped_type;
typedef size_t size_type;
size_type size() const;
bool empty() const;
%rename(Clear) clear;
void clear();
%extend {
const mapped_type& getitem(const key_type& key) throw (std::out_of_range) {
std::map<K,T >::iterator iter = $self->find(key);
if (iter != $self->end())
return iter->second;
else
throw std::out_of_range("key not found");
}
void setitem(const key_type& key, const mapped_type& x) {
(*$self)[key] = x;
}
bool ContainsKey(const key_type& key) {
std::map<K, T >::iterator iter = $self->find(key);
return iter != $self->end();
}
void Add(const key_type& key, const mapped_type& val) throw (std::out_of_range) {
std::map<K, T >::iterator iter = $self->find(key);
if (iter != $self->end())
throw std::out_of_range("key already exists");
$self->insert(std::pair<K, T >(key, val));
}
bool Remove(const key_type& key) {
std::map<K, T >::iterator iter = $self->find(key);
if (iter != $self->end()) {
$self->erase(iter);
return true;
}
return false;
}
}
%enddef
/* The specialized std::map implementation
* K is the C++ key type
* T is the C++ value type
* CSKEYTYPE is the C# key type
* CSVALUETYPE is the C# value type
*/
%define SWIG_STD_MAP_SPECIALIZED_INTERNAL(K, T, CSKEYTYPE, CSVALUETYPE)
// add typemaps here
%typemap(csinterfaces) std::map<K, T > "IDisposable \n#if !SWIG_DOTNET_1\n , System.Collections.Generic.IDictionary<CSKEYTYPE, CSVALUETYPE>\n#endif\n";
%typemap(cscode) std::map<K, T > %{
public CSVALUETYPE this[CSKEYTYPE key] {
get {
return getitem(key);
}
set {
setitem(key, value);
}
}
public bool TryGetValue(CSKEYTYPE key, out CSVALUETYPE value) {
if (this.ContainsKey(key)) {
value = this[key];
return true;
}
value = default(CSVALUETYPE);
return false;
}
public int Count {
get {
return (int)size();
}
}
public bool IsReadOnly {
get {
return false;
}
}
#if !SWIG_DOTNET_1
public System.Collections.Generic.ICollection<CSKEYTYPE> Keys {
get {
System.Collections.Generic.ICollection<CSKEYTYPE> keys = new System.Collections.Generic.List<CSKEYTYPE>();
IntPtr iter = create_iterator_begin();
try {
while (true) {
keys.Add(get_next_key(iter));
}
} catch (ArgumentOutOfRangeException) {
}
return keys;
}
}
public System.Collections.Generic.ICollection<CSVALUETYPE> Values {
get {
System.Collections.Generic.ICollection<CSVALUETYPE> vals = new System.Collections.Generic.List<CSVALUETYPE>();
foreach (System.Collections.Generic.KeyValuePair<CSKEYTYPE, CSVALUETYPE> pair in this) {
vals.Add(pair.Value);
}
return vals;
}
}
public void Add(System.Collections.Generic.KeyValuePair<CSKEYTYPE, CSVALUETYPE> item) {
Add(item.Key, item.Value);
}
public bool Remove(System.Collections.Generic.KeyValuePair<CSKEYTYPE, CSVALUETYPE> item) {
if (Contains(item)) {
return Remove(item.Key);
} else {
return false;
}
}
public bool Contains(System.Collections.Generic.KeyValuePair<CSKEYTYPE, CSVALUETYPE> item) {
if (this[item.Key] == item.Value) {
return true;
} else {
return false;
}
}
public void CopyTo(System.Collections.Generic.KeyValuePair<CSKEYTYPE, CSVALUETYPE>[] array) {
CopyTo(array, 0);
}
public void CopyTo(System.Collections.Generic.KeyValuePair<CSKEYTYPE, CSVALUETYPE>[] array, int arrayIndex) {
if (array == null)
throw new ArgumentNullException("array");
if (arrayIndex < 0)
throw new ArgumentOutOfRangeException("arrayIndex", "Value is less than zero");
if (array.Rank > 1)
throw new ArgumentException("Multi dimensional array.", "array");
if (arrayIndex+this.Count > array.Length)
throw new ArgumentException("Number of elements to copy is too large.");
System.Collections.Generic.IList<CSKEYTYPE> keyList = new System.Collections.Generic.List<CSKEYTYPE>(this.Keys);
for (int i = 0; i < keyList.Count; i++) {
CSKEYTYPE currentKey = keyList[i];
array.SetValue(new System.Collections.Generic.KeyValuePair<CSKEYTYPE, CSVALUETYPE>(currentKey, this[currentKey]), arrayIndex+i);
}
}
System.Collections.Generic.IEnumerator<System.Collections.Generic.KeyValuePair<CSKEYTYPE, CSVALUETYPE>> System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<CSKEYTYPE, CSVALUETYPE>>.GetEnumerator() {
return new $csclassnameEnumerator(this);
}
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() {
return new $csclassnameEnumerator(this);
}
public $csclassnameEnumerator GetEnumerator() {
return new $csclassnameEnumerator(this);
}
// Type-safe enumerator
/// Note that the IEnumerator documentation requires an InvalidOperationException to be thrown
/// whenever the collection is modified. This has been done for changes in the size of the
/// collection but not when one of the elements of the collection is modified as it is a bit
/// tricky to detect unmanaged code that modifies the collection under our feet.
public sealed class $csclassnameEnumerator : System.Collections.IEnumerator,
System.Collections.Generic.IEnumerator<System.Collections.Generic.KeyValuePair<CSKEYTYPE, CSVALUETYPE>>
{
private $csclassname collectionRef;
private System.Collections.Generic.IList<CSKEYTYPE> keyCollection;
private int currentIndex;
private object currentObject;
private int currentSize;
public $csclassnameEnumerator($csclassname collection) {
collectionRef = collection;
keyCollection = new System.Collections.Generic.List<CSKEYTYPE>(collection.Keys);
currentIndex = -1;
currentObject = null;
currentSize = collectionRef.Count;
}
// Type-safe iterator Current
public System.Collections.Generic.KeyValuePair<CSKEYTYPE, CSVALUETYPE> Current {
get {
if (currentIndex == -1)
throw new InvalidOperationException("Enumeration not started.");
if (currentIndex > currentSize - 1)
throw new InvalidOperationException("Enumeration finished.");
if (currentObject == null)
throw new InvalidOperationException("Collection modified.");
return (System.Collections.Generic.KeyValuePair<CSKEYTYPE, CSVALUETYPE>)currentObject;
}
}
// Type-unsafe IEnumerator.Current
object System.Collections.IEnumerator.Current {
get {
return Current;
}
}
public bool MoveNext() {
int size = collectionRef.Count;
bool moveOkay = (currentIndex+1 < size) && (size == currentSize);
if (moveOkay) {
currentIndex++;
CSKEYTYPE currentKey = keyCollection[currentIndex];
currentObject = new System.Collections.Generic.KeyValuePair<CSKEYTYPE, CSVALUETYPE>(currentKey, collectionRef[currentKey]);
} else {
currentObject = null;
}
return moveOkay;
}
public void Reset() {
currentIndex = -1;
currentObject = null;
if (collectionRef.Count != currentSize) {
throw new InvalidOperationException("Collection modified.");
}
}
public void Dispose() {
currentIndex = -1;
currentObject = null;
}
}
#endif
%}
public:
map();
map(const map<K, T > &other);
typedef K key_type;
typedef T mapped_type;
typedef size_t size_type;
size_type size() const;
bool empty() const;
%rename(Clear) clear;
void clear();
%extend {
const mapped_type& getitem(const key_type& key) throw (std::out_of_range) {
std::map<K,T >::iterator iter = $self->find(key);
if (iter != $self->end())
return iter->second;
else
throw std::out_of_range("key not found");
}
void setitem(const key_type& key, const mapped_type& x) {
(*$self)[key] = x;
}
bool ContainsKey(const key_type& key) {
std::map<K, T >::iterator iter = $self->find(key);
return iter != $self->end();
}
void Add(const key_type& key, const mapped_type& val) throw (std::out_of_range) {
std::map<K, T >::iterator iter = $self->find(key);
if (iter != $self->end())
throw std::out_of_range("key already exists");
$self->insert(std::pair<K, T >(key, val));
}
bool Remove(const key_type& key) {
std::map<K, T >::iterator iter = $self->find(key);
if (iter != $self->end()) {
$self->erase(iter);
return true;
}
return false;
}
// create_iterator_begin() and get_next_key() work together to provide a collection of keys to C#
%apply void *VOID_INT_PTR { std::map<K, T >::iterator *std::map<K, T >::create_iterator_begin }
%apply void *VOID_INT_PTR { std::map<K, T >::iterator *swigiterator }
std::map<K, T >::iterator *create_iterator_begin() {
return new std::map<K, T >::iterator($self->begin());
}
const key_type& get_next_key(std::map<K, T >::iterator *swigiterator) throw (std::out_of_range) {
std::map<K, T >::iterator iter = *swigiterator;
if (iter == $self->end()) {
delete swigiterator;
throw std::out_of_range("no more map elements");
}
(*swigiterator)++;
return (*iter).first;
}
}
%csmethodmodifiers std::map<K, T >::size "private"
%csmethodmodifiers std::map<K, T >::getitem "private"
%csmethodmodifiers std::map<K, T >::setitem "private"
%csmethodmodifiers std::map<K, T >::create_iterator_begin "private"
%csmethodmodifiers std::map<K, T >::get_next_key "private"
%enddef
// Main specialization macros
%define SWIG_STD_MAP_SPECIALIZED(K, T, CSKEY, CSVAL)
namespace std {
template<class K, class T> class map {
// add typemaps here
public:
map();
map(const map<K,T> &);
unsigned int size() const;
bool empty() const;
void clear();
%extend {
T& get(const K& key) throw (std::out_of_range) {
std::map<K,T >::iterator i = self->find(key);
if (i != self->end())
return i->second;
else
throw std::out_of_range("key not found");
}
void set(const K& key, const T& x) {
(*self)[key] = x;
}
void del(const K& key) throw (std::out_of_range) {
std::map<K,T >::iterator i = self->find(key);
if (i != self->end())
self->erase(i);
else
throw std::out_of_range("key not found");
}
bool has_key(const K& key) {
std::map<K,T >::iterator i = self->find(key);
return i != self->end();
}
}
};
// specializations for built-ins
%define specialize_std_map_on_key(K,CHECK,CONVERT_FROM,CONVERT_TO)
template<class T> class map<K,T> {
// add typemaps here
public:
map();
map(const map<K,T> &);
unsigned int size() const;
bool empty() const;
void clear();
%extend {
T& get(K key) throw (std::out_of_range) {
std::map<K,T >::iterator i = self->find(key);
if (i != self->end())
return i->second;
else
throw std::out_of_range("key not found");
}
void set(K key, const T& x) {
(*self)[key] = x;
}
void del(K key) throw (std::out_of_range) {
std::map<K,T >::iterator i = self->find(key);
if (i != self->end())
self->erase(i);
else
throw std::out_of_range("key not found");
}
bool has_key(K key) {
std::map<K,T >::iterator i = self->find(key);
return i != self->end();
}
}
};
%enddef
%define specialize_std_map_on_value(T,CHECK,CONVERT_FROM,CONVERT_TO)
template<class K> class map<K,T> {
// add typemaps here
public:
map();
map(const map<K,T> &);
unsigned int size() const;
bool empty() const;
void clear();
%extend {
T get(const K& key) throw (std::out_of_range) {
std::map<K,T >::iterator i = self->find(key);
if (i != self->end())
return i->second;
else
throw std::out_of_range("key not found");
}
void set(const K& key, T x) {
(*self)[key] = x;
}
void del(const K& key) throw (std::out_of_range) {
std::map<K,T >::iterator i = self->find(key);
if (i != self->end())
self->erase(i);
else
throw std::out_of_range("key not found");
}
bool has_key(const K& key) {
std::map<K,T >::iterator i = self->find(key);
return i != self->end();
}
}
};
%enddef
%define specialize_std_map_on_both(K,CHECK_K,CONVERT_K_FROM,CONVERT_K_TO,
T,CHECK_T,CONVERT_T_FROM,CONVERT_T_TO)
template<> class map<K,T> {
// add typemaps here
public:
map();
map(const map<K,T> &);
unsigned int size() const;
bool empty() const;
void clear();
%extend {
T get(K key) throw (std::out_of_range) {
std::map<K,T >::iterator i = self->find(key);
if (i != self->end())
return i->second;
else
throw std::out_of_range("key not found");
}
void set(K key, T x) {
(*self)[key] = x;
}
void del(K key) throw (std::out_of_range) {
std::map<K,T >::iterator i = self->find(key);
if (i != self->end())
self->erase(i);
else
throw std::out_of_range("key not found");
}
bool has_key(K key) {
std::map<K,T >::iterator i = self->find(key);
return i != self->end();
}
}
};
%enddef
// add specializations here
template<> class map<K, T > {
SWIG_STD_MAP_SPECIALIZED_INTERNAL(K, T, CSKEY, CSVAL)
};
}
%enddef
%define SWIG_STD_MAP_SPECIALIZED_SIMPLE(K, T)
SWIG_STD_MAP_SPECIALIZED(K, T, K, T)
%enddef
// Old macros (deprecated)
%define specialize_std_map_on_key(K,CHECK,CONVERT_FROM,CONVERT_TO)
#warning specialize_std_map_on_key ignored - macro is deprecated, please use SWIG_STD_MAP_MINIMAL_INTERNAL in Lib/csharp/std_map.i
%enddef
%define specialize_std_map_on_value(T,CHECK,CONVERT_FROM,CONVERT_TO)
#warning specialize_std_map_on_value ignored - macro is deprecated, please use SWIG_STD_MAP_MINIMAL_INTERNAL in Lib/csharp/std_map.i
%enddef
%define specialize_std_map_on_both(K,CHECK_K,CONVERT_K_FROM,CONVERT_K_TO, T,CHECK_T,CONVERT_T_FROM,CONVERT_T_TO)
#warning specialize_std_map_on_both ignored - macro is deprecated, please use SWIG_STD_MAP_MINIMAL_INTERNAL in Lib/csharp/std_map.i
%enddef
// Default implementation
namespace std {
template<class K, class T> class map {
SWIG_STD_MAP_MINIMAL_INTERNAL(K, T)
};
}
// specializations for built-ins
SWIG_STD_MAP_SPECIALIZED(std::string, std::string, string, string)
SWIG_STD_MAP_SPECIALIZED(std::string, bool, string, bool)
SWIG_STD_MAP_SPECIALIZED(std::string, int, string, int)
SWIG_STD_MAP_SPECIALIZED(std::string, unsigned long long, string, ulong)
SWIG_STD_MAP_SPECIALIZED(std::string, unsigned long, string, uint)
SWIG_STD_MAP_SPECIALIZED(std::string, unsigned short, string, ushort)
SWIG_STD_MAP_SPECIALIZED(std::string, long long, string, long)
SWIG_STD_MAP_SPECIALIZED(std::string, unsigned int, string, uint)
SWIG_STD_MAP_SPECIALIZED(std::string, unsigned char, string, byte)
SWIG_STD_MAP_SPECIALIZED(std::string, signed char, string, sbyte)
SWIG_STD_MAP_SPECIALIZED(std::string, double, string, double)
SWIG_STD_MAP_SPECIALIZED(std::string, short, string, short)
SWIG_STD_MAP_SPECIALIZED(std::string, float, string, float)
SWIG_STD_MAP_SPECIALIZED(std::string, char, string, char)
SWIG_STD_MAP_SPECIALIZED(std::string, long, string, int)
SWIG_STD_MAP_SPECIALIZED(bool, std::string, bool, string)
SWIG_STD_MAP_SPECIALIZED_SIMPLE(bool, bool)
SWIG_STD_MAP_SPECIALIZED_SIMPLE(bool, int)
SWIG_STD_MAP_SPECIALIZED(bool, unsigned long long, bool, ulong)
SWIG_STD_MAP_SPECIALIZED(bool, unsigned long, bool, uint)
SWIG_STD_MAP_SPECIALIZED(bool, unsigned short, bool, ushort)
SWIG_STD_MAP_SPECIALIZED(bool, long long, bool, long)
SWIG_STD_MAP_SPECIALIZED(bool, unsigned int, bool, uint)
SWIG_STD_MAP_SPECIALIZED(bool, unsigned char, bool, byte)
SWIG_STD_MAP_SPECIALIZED(bool, signed char, bool, sbyte)
SWIG_STD_MAP_SPECIALIZED_SIMPLE(bool, double)
SWIG_STD_MAP_SPECIALIZED_SIMPLE(bool, short)
SWIG_STD_MAP_SPECIALIZED_SIMPLE(bool, float)
SWIG_STD_MAP_SPECIALIZED_SIMPLE(bool, char)
SWIG_STD_MAP_SPECIALIZED(bool, long, bool, int)
SWIG_STD_MAP_SPECIALIZED(int, std::string, int, string)
SWIG_STD_MAP_SPECIALIZED_SIMPLE(int, bool)
SWIG_STD_MAP_SPECIALIZED_SIMPLE(int, int)
SWIG_STD_MAP_SPECIALIZED(int, unsigned long long, int, ulong)
SWIG_STD_MAP_SPECIALIZED(int, unsigned long, int, uint)
SWIG_STD_MAP_SPECIALIZED(int, unsigned short, int, ushort)
SWIG_STD_MAP_SPECIALIZED(int, long long, int, long)
SWIG_STD_MAP_SPECIALIZED(int, unsigned int, int, uint)
SWIG_STD_MAP_SPECIALIZED(int, unsigned char, int, byte)
SWIG_STD_MAP_SPECIALIZED(int, signed char, int, sbyte)
SWIG_STD_MAP_SPECIALIZED_SIMPLE(int, double)
SWIG_STD_MAP_SPECIALIZED_SIMPLE(int, short)
SWIG_STD_MAP_SPECIALIZED_SIMPLE(int, float)
SWIG_STD_MAP_SPECIALIZED_SIMPLE(int, char)
SWIG_STD_MAP_SPECIALIZED(int, long, int, int)
SWIG_STD_MAP_SPECIALIZED(unsigned long long, std::string, ulong, string)
SWIG_STD_MAP_SPECIALIZED(unsigned long long, bool, ulong, bool)
SWIG_STD_MAP_SPECIALIZED(unsigned long long, int, ulong, int)
SWIG_STD_MAP_SPECIALIZED(unsigned long long, unsigned long long, ulong, ulong)
SWIG_STD_MAP_SPECIALIZED(unsigned long long, unsigned long, ulong, uint)
SWIG_STD_MAP_SPECIALIZED(unsigned long long, unsigned short, ulong, ushort)
SWIG_STD_MAP_SPECIALIZED(unsigned long long, long long, ulong, long)
SWIG_STD_MAP_SPECIALIZED(unsigned long long, unsigned int, ulong, uint)
SWIG_STD_MAP_SPECIALIZED(unsigned long long, unsigned char, ulong, byte)
SWIG_STD_MAP_SPECIALIZED(unsigned long long, signed char, ulong, sbyte)
SWIG_STD_MAP_SPECIALIZED(unsigned long long, double, ulong, double)
SWIG_STD_MAP_SPECIALIZED(unsigned long long, short, ulong, short)
SWIG_STD_MAP_SPECIALIZED(unsigned long long, float, ulong, float)
SWIG_STD_MAP_SPECIALIZED(unsigned long long, char, ulong, char)
SWIG_STD_MAP_SPECIALIZED(unsigned long long, long, ulong, int)
SWIG_STD_MAP_SPECIALIZED(unsigned long, std::string, uint, string)
SWIG_STD_MAP_SPECIALIZED(unsigned long, bool, uint, bool)
SWIG_STD_MAP_SPECIALIZED(unsigned long, int, uint, int)
SWIG_STD_MAP_SPECIALIZED(unsigned long, unsigned long long, uint, ulong)
SWIG_STD_MAP_SPECIALIZED(unsigned long, unsigned long, uint, uint)
SWIG_STD_MAP_SPECIALIZED(unsigned long, unsigned short, uint, ushort)
SWIG_STD_MAP_SPECIALIZED(unsigned long, long long, uint, long)
SWIG_STD_MAP_SPECIALIZED(unsigned long, unsigned int, uint, uint)
SWIG_STD_MAP_SPECIALIZED(unsigned long, unsigned char, uint, byte)
SWIG_STD_MAP_SPECIALIZED(unsigned long, signed char, uint, sbyte)
SWIG_STD_MAP_SPECIALIZED(unsigned long, double, uint, double)
SWIG_STD_MAP_SPECIALIZED(unsigned long, short, uint, short)
SWIG_STD_MAP_SPECIALIZED(unsigned long, float, uint, float)
SWIG_STD_MAP_SPECIALIZED(unsigned long, char, uint, char)
SWIG_STD_MAP_SPECIALIZED(unsigned long, long, uint, int)
SWIG_STD_MAP_SPECIALIZED(unsigned short, std::string, ushort, string)
SWIG_STD_MAP_SPECIALIZED(unsigned short, bool, ushort, bool)
SWIG_STD_MAP_SPECIALIZED(unsigned short, int, ushort, int)
SWIG_STD_MAP_SPECIALIZED(unsigned short, unsigned long long, ushort, ulong)
SWIG_STD_MAP_SPECIALIZED(unsigned short, unsigned long, ushort, uint)
SWIG_STD_MAP_SPECIALIZED(unsigned short, unsigned short, ushort, ushort)
SWIG_STD_MAP_SPECIALIZED(unsigned short, long long, ushort, long)
SWIG_STD_MAP_SPECIALIZED(unsigned short, unsigned int, ushort, uint)
SWIG_STD_MAP_SPECIALIZED(unsigned short, unsigned char, ushort, byte)
SWIG_STD_MAP_SPECIALIZED(unsigned short, signed char, ushort, sbyte)
SWIG_STD_MAP_SPECIALIZED(unsigned short, double, ushort, double)
SWIG_STD_MAP_SPECIALIZED(unsigned short, short, ushort, short)
SWIG_STD_MAP_SPECIALIZED(unsigned short, float, ushort, float)
SWIG_STD_MAP_SPECIALIZED(unsigned short, char, ushort, char)
SWIG_STD_MAP_SPECIALIZED(unsigned short, long, ushort, int)
SWIG_STD_MAP_SPECIALIZED(long long, std::string, long, string)
SWIG_STD_MAP_SPECIALIZED(long long, bool, long, bool)
SWIG_STD_MAP_SPECIALIZED(long long, int, long, int)
SWIG_STD_MAP_SPECIALIZED(long long, unsigned long long, long, ulong)
SWIG_STD_MAP_SPECIALIZED(long long, unsigned long, long, uint)
SWIG_STD_MAP_SPECIALIZED(long long, unsigned short, long, ushort)
SWIG_STD_MAP_SPECIALIZED(long long, long long, long, long)
SWIG_STD_MAP_SPECIALIZED(long long, unsigned int, long, uint)
SWIG_STD_MAP_SPECIALIZED(long long, unsigned char, long, byte)
SWIG_STD_MAP_SPECIALIZED(long long, signed char, long, sbyte)
SWIG_STD_MAP_SPECIALIZED(long long, double, long, double)
SWIG_STD_MAP_SPECIALIZED(long long, short, long, short)
SWIG_STD_MAP_SPECIALIZED(long long, float, long, float)
SWIG_STD_MAP_SPECIALIZED(long long, char, long, char)
SWIG_STD_MAP_SPECIALIZED(long long, long, long, int)
SWIG_STD_MAP_SPECIALIZED(unsigned int, std::string, uint, string)
SWIG_STD_MAP_SPECIALIZED(unsigned int, bool, uint, bool)
SWIG_STD_MAP_SPECIALIZED(unsigned int, int, uint, int)
SWIG_STD_MAP_SPECIALIZED(unsigned int, unsigned long long, uint, ulong)
SWIG_STD_MAP_SPECIALIZED(unsigned int, unsigned long, uint, uint)
SWIG_STD_MAP_SPECIALIZED(unsigned int, unsigned short, uint, ushort)
SWIG_STD_MAP_SPECIALIZED(unsigned int, long long, uint, long)
SWIG_STD_MAP_SPECIALIZED(unsigned int, unsigned int, uint, uint)
SWIG_STD_MAP_SPECIALIZED(unsigned int, unsigned char, uint, byte)
SWIG_STD_MAP_SPECIALIZED(unsigned int, signed char, uint, sbyte)
SWIG_STD_MAP_SPECIALIZED(unsigned int, double, uint, double)
SWIG_STD_MAP_SPECIALIZED(unsigned int, short, uint, short)
SWIG_STD_MAP_SPECIALIZED(unsigned int, float, uint, float)
SWIG_STD_MAP_SPECIALIZED(unsigned int, char, uint, char)
SWIG_STD_MAP_SPECIALIZED(unsigned int, long, uint, int)
SWIG_STD_MAP_SPECIALIZED(unsigned char, std::string, byte, string)
SWIG_STD_MAP_SPECIALIZED(unsigned char, bool, byte, bool)
SWIG_STD_MAP_SPECIALIZED(unsigned char, int, byte, int)
SWIG_STD_MAP_SPECIALIZED(unsigned char, unsigned long long, byte, ulong)
SWIG_STD_MAP_SPECIALIZED(unsigned char, unsigned long, byte, uint)
SWIG_STD_MAP_SPECIALIZED(unsigned char, unsigned short, byte, ushort)
SWIG_STD_MAP_SPECIALIZED(unsigned char, long long, byte, long)
SWIG_STD_MAP_SPECIALIZED(unsigned char, unsigned int, byte, uint)
SWIG_STD_MAP_SPECIALIZED(unsigned char, unsigned char, byte, byte)
SWIG_STD_MAP_SPECIALIZED(unsigned char, signed char, byte, sbyte)
SWIG_STD_MAP_SPECIALIZED(unsigned char, double, byte, double)
SWIG_STD_MAP_SPECIALIZED(unsigned char, short, byte, short)
SWIG_STD_MAP_SPECIALIZED(unsigned char, float, byte, float)
SWIG_STD_MAP_SPECIALIZED(unsigned char, char, byte, char)
SWIG_STD_MAP_SPECIALIZED(unsigned char, long, byte, int)
SWIG_STD_MAP_SPECIALIZED(signed char, std::string, sbyte, string)
SWIG_STD_MAP_SPECIALIZED(signed char, bool, sbyte, bool)
SWIG_STD_MAP_SPECIALIZED(signed char, int, sbyte, int)
SWIG_STD_MAP_SPECIALIZED(signed char, unsigned long long, sbyte, ulong)
SWIG_STD_MAP_SPECIALIZED(signed char, unsigned long, sbyte, uint)
SWIG_STD_MAP_SPECIALIZED(signed char, unsigned short, sbyte, ushort)
SWIG_STD_MAP_SPECIALIZED(signed char, long long, sbyte, long)
SWIG_STD_MAP_SPECIALIZED(signed char, unsigned int, sbyte, uint)
SWIG_STD_MAP_SPECIALIZED(signed char, unsigned char, sbyte, byte)
SWIG_STD_MAP_SPECIALIZED(signed char, signed char, sbyte, sbyte)
SWIG_STD_MAP_SPECIALIZED(signed char, double, sbyte, double)
SWIG_STD_MAP_SPECIALIZED(signed char, short, sbyte, short)
SWIG_STD_MAP_SPECIALIZED(signed char, float, sbyte, float)
SWIG_STD_MAP_SPECIALIZED(signed char, char, sbyte, char)
SWIG_STD_MAP_SPECIALIZED(signed char, long, sbyte, int)
SWIG_STD_MAP_SPECIALIZED(double, std::string, double, string)
SWIG_STD_MAP_SPECIALIZED_SIMPLE(double, bool)
SWIG_STD_MAP_SPECIALIZED_SIMPLE(double, int)
SWIG_STD_MAP_SPECIALIZED(double, unsigned long long, double, ulong)
SWIG_STD_MAP_SPECIALIZED(double, unsigned long, double, uint)
SWIG_STD_MAP_SPECIALIZED(double, unsigned short, double, ushort)
SWIG_STD_MAP_SPECIALIZED(double, long long, double, long)
SWIG_STD_MAP_SPECIALIZED(double, unsigned int, double, uint)
SWIG_STD_MAP_SPECIALIZED(double, unsigned char, double, byte)
SWIG_STD_MAP_SPECIALIZED(double, signed char, double, sbyte)
SWIG_STD_MAP_SPECIALIZED_SIMPLE(double, double)
SWIG_STD_MAP_SPECIALIZED_SIMPLE(double, short)
SWIG_STD_MAP_SPECIALIZED_SIMPLE(double, float)
SWIG_STD_MAP_SPECIALIZED_SIMPLE(double, char)
SWIG_STD_MAP_SPECIALIZED(double, long, double, int)
SWIG_STD_MAP_SPECIALIZED(short, std::string, short, string)
SWIG_STD_MAP_SPECIALIZED_SIMPLE(short, bool)
SWIG_STD_MAP_SPECIALIZED_SIMPLE(short, int)
SWIG_STD_MAP_SPECIALIZED(short, unsigned long long, short, ulong)
SWIG_STD_MAP_SPECIALIZED(short, unsigned long, short, uint)
SWIG_STD_MAP_SPECIALIZED(short, unsigned short, short, ushort)
SWIG_STD_MAP_SPECIALIZED(short, long long, short, long)
SWIG_STD_MAP_SPECIALIZED(short, unsigned int, short, uint)
SWIG_STD_MAP_SPECIALIZED(short, unsigned char, short, byte)
SWIG_STD_MAP_SPECIALIZED(short, signed char, short, sbyte)
SWIG_STD_MAP_SPECIALIZED_SIMPLE(short, double)
SWIG_STD_MAP_SPECIALIZED_SIMPLE(short, short)
SWIG_STD_MAP_SPECIALIZED_SIMPLE(short, float)
SWIG_STD_MAP_SPECIALIZED_SIMPLE(short, char)
SWIG_STD_MAP_SPECIALIZED(short, long, short, int)
SWIG_STD_MAP_SPECIALIZED(float, std::string, float, string)
SWIG_STD_MAP_SPECIALIZED_SIMPLE(float, bool)
SWIG_STD_MAP_SPECIALIZED_SIMPLE(float, int)
SWIG_STD_MAP_SPECIALIZED(float, unsigned long long, float, ulong)
SWIG_STD_MAP_SPECIALIZED(float, unsigned long, float, uint)
SWIG_STD_MAP_SPECIALIZED(float, unsigned short, float, ushort)
SWIG_STD_MAP_SPECIALIZED(float, long long, float, long)
SWIG_STD_MAP_SPECIALIZED(float, unsigned int, float, uint)
SWIG_STD_MAP_SPECIALIZED(float, unsigned char, float, byte)
SWIG_STD_MAP_SPECIALIZED(float, signed char, float, sbyte)
SWIG_STD_MAP_SPECIALIZED_SIMPLE(float, double)
SWIG_STD_MAP_SPECIALIZED_SIMPLE(float, short)
SWIG_STD_MAP_SPECIALIZED_SIMPLE(float, float)
SWIG_STD_MAP_SPECIALIZED_SIMPLE(float, char)
SWIG_STD_MAP_SPECIALIZED(float, long, float, int)
SWIG_STD_MAP_SPECIALIZED(char, std::string, char, string)
SWIG_STD_MAP_SPECIALIZED_SIMPLE(char, bool)
SWIG_STD_MAP_SPECIALIZED_SIMPLE(char, int)
SWIG_STD_MAP_SPECIALIZED(char, unsigned long long, char, ulong)
SWIG_STD_MAP_SPECIALIZED(char, unsigned long, char, uint)
SWIG_STD_MAP_SPECIALIZED(char, unsigned short, char, ushort)
SWIG_STD_MAP_SPECIALIZED(char, long long, char, long)
SWIG_STD_MAP_SPECIALIZED(char, unsigned int, char, uint)
SWIG_STD_MAP_SPECIALIZED(char, unsigned char, char, byte)
SWIG_STD_MAP_SPECIALIZED(char, signed char, char, sbyte)
SWIG_STD_MAP_SPECIALIZED_SIMPLE(char, double)
SWIG_STD_MAP_SPECIALIZED_SIMPLE(char, short)
SWIG_STD_MAP_SPECIALIZED_SIMPLE(char, float)
SWIG_STD_MAP_SPECIALIZED_SIMPLE(char, char)
SWIG_STD_MAP_SPECIALIZED(char, long, char, int)
SWIG_STD_MAP_SPECIALIZED(long, std::string, int, string)
SWIG_STD_MAP_SPECIALIZED(long, bool, int, bool)
SWIG_STD_MAP_SPECIALIZED(long, int, int, int)
SWIG_STD_MAP_SPECIALIZED(long, unsigned long long, int, ulong)
SWIG_STD_MAP_SPECIALIZED(long, unsigned long, int, uint)
SWIG_STD_MAP_SPECIALIZED(long, unsigned short, int, ushort)
SWIG_STD_MAP_SPECIALIZED(long, long long, int, long)
SWIG_STD_MAP_SPECIALIZED(long, unsigned int, int, uint)
SWIG_STD_MAP_SPECIALIZED(long, unsigned char, int, byte)
SWIG_STD_MAP_SPECIALIZED(long, signed char, int, sbyte)
SWIG_STD_MAP_SPECIALIZED(long, double, int, double)
SWIG_STD_MAP_SPECIALIZED(long, short, int, short)
SWIG_STD_MAP_SPECIALIZED(long, float, int, float)
SWIG_STD_MAP_SPECIALIZED(long, char, int, char)
SWIG_STD_MAP_SPECIALIZED(long, long, int, int)
// add specializations here

View file

@ -19,7 +19,8 @@
* %template(VectKlass) std::vector<SomeNamespace::Klass>;
*
* Note that IEnumerable<> is implemented in the proxy class which is useful for using LINQ with
* C++ std::vector wrappers.
* C++ std::vector wrappers. IEnumerable<> is replaced by IList<> wherever we are confident that the
* required C++ operator== is available for correct compilation.
*
* Warning: heavy macro usage in this file. Use swig -E to get a sane view on the real file contents!
* ----------------------------------------------------------------------------- */
@ -31,8 +32,8 @@
// MACRO for use within the std::vector class body
// CSTYPE and CTYPE respectively correspond to the types in the cstype and ctype typemaps
%define SWIG_STD_VECTOR_MINIMUM_INTERNAL(CONST_REFERENCE_TYPE, CSTYPE, CTYPE...)
%typemap(csinterfaces) std::vector<CTYPE > "IDisposable, System.Collections.IEnumerable\n#if !SWIG_DOTNET_1\n , System.Collections.Generic.IEnumerable<CSTYPE>\n#endif\n";
%define SWIG_STD_VECTOR_MINIMUM_INTERNAL(CSINTERFACE, CONST_REFERENCE_TYPE, CSTYPE, CTYPE...)
%typemap(csinterfaces) std::vector<CTYPE > "IDisposable, System.Collections.IEnumerable\n#if !SWIG_DOTNET_1\n , System.Collections.Generic.CSINTERFACE<CSTYPE>\n#endif\n";
%typemap(cscode) std::vector<CTYPE > %{
public $csclassname(System.Collections.ICollection c) : this() {
if (c == null)
@ -225,6 +226,7 @@
%newobject GetRange(int index, int count);
%newobject Repeat(const value_type& value, int count);
vector();
vector(const vector &other);
%extend {
vector(int capacity) throw (std::out_of_range) {
std::vector<CTYPE >* pv = 0;
@ -237,26 +239,26 @@
return pv;
}
CTYPE getitemcopy(int index) throw (std::out_of_range) {
if (index>=0 && index<(int)self->size())
return (*self)[index];
if (index>=0 && index<(int)$self->size())
return (*$self)[index];
else
throw std::out_of_range("index");
}
const_reference getitem(int index) throw (std::out_of_range) {
if (index>=0 && index<(int)self->size())
return (*self)[index];
if (index>=0 && index<(int)$self->size())
return (*$self)[index];
else
throw std::out_of_range("index");
}
void setitem(int index, const value_type& val) throw (std::out_of_range) {
if (index>=0 && index<(int)self->size())
(*self)[index] = val;
if (index>=0 && index<(int)$self->size())
(*$self)[index] = val;
else
throw std::out_of_range("index");
}
// Takes a deep copy of the elements unlike ArrayList.AddRange
void AddRange(const std::vector<CTYPE >& values) {
self->insert(self->end(), values.begin(), values.end());
$self->insert($self->end(), values.begin(), values.end());
}
// Takes a deep copy of the elements unlike ArrayList.GetRange
std::vector<CTYPE > *GetRange(int index, int count) throw (std::out_of_range, std::invalid_argument) {
@ -264,26 +266,26 @@
throw std::out_of_range("index");
if (count < 0)
throw std::out_of_range("count");
if (index >= (int)self->size()+1 || index+count > (int)self->size())
if (index >= (int)$self->size()+1 || index+count > (int)$self->size())
throw std::invalid_argument("invalid range");
return new std::vector<CTYPE >(self->begin()+index, self->begin()+index+count);
return new std::vector<CTYPE >($self->begin()+index, $self->begin()+index+count);
}
void Insert(int index, const value_type& x) throw (std::out_of_range) {
if (index>=0 && index<(int)self->size()+1)
self->insert(self->begin()+index, x);
if (index>=0 && index<(int)$self->size()+1)
$self->insert($self->begin()+index, x);
else
throw std::out_of_range("index");
}
// Takes a deep copy of the elements unlike ArrayList.InsertRange
void InsertRange(int index, const std::vector<CTYPE >& values) throw (std::out_of_range) {
if (index>=0 && index<(int)self->size()+1)
self->insert(self->begin()+index, values.begin(), values.end());
if (index>=0 && index<(int)$self->size()+1)
$self->insert($self->begin()+index, values.begin(), values.end());
else
throw std::out_of_range("index");
}
void RemoveAt(int index) throw (std::out_of_range) {
if (index>=0 && index<(int)self->size())
self->erase(self->begin() + index);
if (index>=0 && index<(int)$self->size())
$self->erase($self->begin() + index);
else
throw std::out_of_range("index");
}
@ -292,9 +294,9 @@
throw std::out_of_range("index");
if (count < 0)
throw std::out_of_range("count");
if (index >= (int)self->size()+1 || index+count > (int)self->size())
if (index >= (int)$self->size()+1 || index+count > (int)$self->size())
throw std::invalid_argument("invalid range");
self->erase(self->begin()+index, self->begin()+index+count);
$self->erase($self->begin()+index, $self->begin()+index+count);
}
static std::vector<CTYPE > *Repeat(const value_type& value, int count) throw (std::out_of_range) {
if (count < 0)
@ -302,59 +304,58 @@
return new std::vector<CTYPE >(count, value);
}
void Reverse() {
std::reverse(self->begin(), self->end());
std::reverse($self->begin(), $self->end());
}
void Reverse(int index, int count) throw (std::out_of_range, std::invalid_argument) {
if (index < 0)
throw std::out_of_range("index");
if (count < 0)
throw std::out_of_range("count");
if (index >= (int)self->size()+1 || index+count > (int)self->size())
if (index >= (int)$self->size()+1 || index+count > (int)$self->size())
throw std::invalid_argument("invalid range");
std::reverse(self->begin()+index, self->begin()+index+count);
std::reverse($self->begin()+index, $self->begin()+index+count);
}
// Takes a deep copy of the elements unlike ArrayList.SetRange
void SetRange(int index, const std::vector<CTYPE >& values) throw (std::out_of_range) {
if (index < 0)
throw std::out_of_range("index");
if (index+values.size() > self->size())
if (index+values.size() > $self->size())
throw std::out_of_range("index");
std::copy(values.begin(), values.end(), self->begin()+index);
std::copy(values.begin(), values.end(), $self->begin()+index);
}
}
%enddef
%define SWIG_STD_VECTOR_MINIMUM(CSTYPE, CTYPE...)
SWIG_STD_VECTOR_MINIMUM_INTERNAL(const value_type&, CSTYPE, CTYPE)
SWIG_STD_VECTOR_MINIMUM_INTERNAL(IEnumerable, const value_type&, CSTYPE, CTYPE)
%enddef
// Extra methods added to the collection class if operator== is defined for the class being wrapped
// CSTYPE and CTYPE respectively correspond to the types in the cstype and ctype typemaps
// The class will then implement IList<>, which adds extra functionality
%define SWIG_STD_VECTOR_EXTRA_OP_EQUALS_EQUALS(CSTYPE, CTYPE...)
%extend {
bool Contains(const value_type& value) {
return std::find(self->begin(), self->end(), value) != self->end();
return std::find($self->begin(), $self->end(), value) != $self->end();
}
int IndexOf(const value_type& value) {
int index = -1;
std::vector<CTYPE >::iterator it = std::find(self->begin(), self->end(), value);
if (it != self->end())
index = (int)(it - self->begin());
std::vector<CTYPE >::iterator it = std::find($self->begin(), $self->end(), value);
if (it != $self->end())
index = (int)(it - $self->begin());
return index;
}
int LastIndexOf(const value_type& value) {
int index = -1;
std::vector<CTYPE >::reverse_iterator rit = std::find(self->rbegin(), self->rend(), value);
if (rit != self->rend())
index = (int)(self->rend() - 1 - rit);
std::vector<CTYPE >::reverse_iterator rit = std::find($self->rbegin(), $self->rend(), value);
if (rit != $self->rend())
index = (int)($self->rend() - 1 - rit);
return index;
}
bool Remove(const value_type& value) {
std::vector<CTYPE >::iterator it = std::find(self->begin(), self->end(), value);
if (it != self->end()) {
self->erase(it);
std::vector<CTYPE >::iterator it = std::find($self->begin(), $self->end(), value);
if (it != $self->end()) {
$self->erase(it);
return true;
}
return false;
@ -367,7 +368,7 @@ SWIG_STD_VECTOR_MINIMUM_INTERNAL(const value_type&, CSTYPE, CTYPE)
%define SWIG_STD_VECTOR_SPECIALIZE(CSTYPE, CTYPE...)
namespace std {
template<> class vector<CTYPE > {
SWIG_STD_VECTOR_MINIMUM(CSTYPE, CTYPE)
SWIG_STD_VECTOR_MINIMUM_INTERNAL(IList, const value_type&, CSTYPE, CTYPE)
SWIG_STD_VECTOR_EXTRA_OP_EQUALS_EQUALS(CSTYPE, CTYPE)
};
}
@ -409,7 +410,7 @@ namespace std {
};
// bool is a bit different in the C++ standard
template<> class vector<bool> {
SWIG_STD_VECTOR_MINIMUM_INTERNAL(bool, bool, bool)
SWIG_STD_VECTOR_MINIMUM_INTERNAL(IList, bool, bool, bool)
SWIG_STD_VECTOR_EXTRA_OP_EQUALS_EQUALS(bool, bool)
};
}

View file

@ -27,11 +27,10 @@ namespace SWIG_INTRUSIVE_PTR_NAMESPACE {
}
%fragment("SWIG_intrusive_deleter", "header") {
template<class T> struct SWIG_intrusive_deleter
{
void operator()(T * p)
{
if(p) intrusive_ptr_release(p);
template<class T> struct SWIG_intrusive_deleter {
void operator()(T *p) {
if (p)
intrusive_ptr_release(p);
}
};
}

View file

@ -83,7 +83,8 @@ static void SWIGUNUSED SWIG_JavaThrowException(JNIEnv *jenv, SWIG_JavaExceptionC
{ SWIG_JavaNullPointerException, "java/lang/NullPointerException" },
{ SWIG_JavaDirectorPureVirtual, "java/lang/RuntimeException" },
{ SWIG_JavaUnknownError, "java/lang/UnknownError" },
{ (SWIG_JavaExceptionCodes)0, "java/lang/UnknownError" } };
{ (SWIG_JavaExceptionCodes)0, "java/lang/UnknownError" }
};
const SWIG_JavaExceptions_t *except_ptr = java_exceptions;
while (except_ptr->code != code && except_ptr->code)

View file

@ -202,6 +202,35 @@ as follows :
$1 = &dvalue;
}
%typemap(typecheck) int *REFERENCE, int &REFERENCE,
short *REFERENCE, short &REFERENCE,
long *REFERENCE, long &REFERENCE,
signed char *REFERENCE, signed char &REFERENCE,
bool *REFERENCE, bool &REFERENCE
{
$1 = SvROK($input) && SvIOK(SvRV($input));
}
%typemap(typecheck) double *REFERENCE, double &REFERENCE,
float *REFERENCE, float &REFERENCE
{
$1 = SvROK($input);
if($1) {
SV *tmpsv = SvRV($input);
$1 = SvNOK(tmpsv) || SvIOK(tmpsv);
}
}
%typemap(typecheck) unsigned int *REFERENCE, unsigned int &REFERENCE,
unsigned short *REFERENCE, unsigned short &REFERENCE,
unsigned long *REFERENCE, unsigned long &REFERENCE,
unsigned char *REFERENCE, unsigned char &REFERENCE
{
$1 = SvROK($input);
if($1) {
SV *tmpsv = SvRV($input);
$1 = SvUOK(tmpsv) || SvIOK(tmpsv);
}
}
%typemap(argout) double *REFERENCE, double &REFERENCE,
float *REFERENCE, float &REFERENCE
{
@ -214,7 +243,7 @@ as follows :
%typemap(argout) int *REFERENCE, int &REFERENCE,
short *REFERENCE, short &REFERENCE,
long *REFERENCE, long &REFERENCE,
signed char *REFERENCE, unsigned char &REFERENCE,
signed char *REFERENCE, signed char &REFERENCE,
bool *REFERENCE, bool &REFERENCE
{
SV *tempsv;

View file

@ -383,9 +383,7 @@ SwigPyObject_repr(SwigPyObject *v, PyObject *args)
#endif
{
const char *name = SWIG_TypePrettyName(v->ty);
PyObject *hex = SwigPyObject_hex(v);
PyObject *repr = SWIG_Python_str_FromFormat("<Swig Object of type '%s' at %p>", name, hex);
Py_DECREF(hex);
PyObject *repr = SWIG_Python_str_FromFormat("<Swig Object of type '%s' at %p>", name, v);
if (v->next) {
#ifdef METH_NOARGS
PyObject *nrep = SwigPyObject_repr((SwigPyObject *)v->next);

View file

@ -483,7 +483,7 @@ void add_defined_foreign_type(Node *n, int overwrite = 0, String *k = 0,
if (!Strcmp(nodeType(n), "cdecl") && !Strcmp(Getattr(n, "storage"), "typedef")) {
SwigType *type = SwigType_strip_qualifiers(Getattr(n, "type"));
#ifdef ALLEGROCL_CLASS_DEBUG
Printf(stderr, "Examining typedef '%s' for class references.\n", type);
Printf(stderr, "Examining typedef '%s' for class references. (%d)\n", type, SwigType_isclass(type));
#endif
if (SwigType_isclass(type)) {
#ifdef ALLEGROCL_CLASS_DEBUG
@ -761,6 +761,7 @@ String *internal_compose_foreign_type(SwigType *ty) {
Setattr(nn,"allegrocl:package",current_namespace);
add_forward_referenced_type(nn, 0);
// tok_name is dangling here, unused. ouch. why?
Printf(ffiType, "%s", get_ffi_type(tok, ""), tok_name);
}
}
@ -934,9 +935,8 @@ String *infix_to_prefix(String *val, char split_op, const String *op, String *ty
Printf(result, ")");
Delete(ored);
return part_failed ? 0 : result;
} else {
Delete(ored);
}
Delete(ored);
return 0;
}
@ -955,7 +955,7 @@ String *convert_literal(String *literal, String *type, bool try_to_split) {
String *ns = listify_namespace(current_namespace);
// very basic parsing of infix expressions.
if (try_to_split) {
if (try_to_split && SwigType_type(type) != T_STRING) {
if ((res = infix_to_prefix(num, '|', "logior", type)))
return res;
if ((res = infix_to_prefix(num, '&', "logand", type)))
@ -970,9 +970,20 @@ String *convert_literal(String *literal, String *type, bool try_to_split) {
return res;
if ((res = infix_to_prefix(num, '-', "-", type)))
return res;
// if ((res = infix_to_prefix(num, '~', "lognot", type))) return res;
// if( (res = infix_to_prefix(num, '<<', "ash", type)) ) return res;
}
// unary complement...
if (s[0] == '~' && Len(num) >= 2) {
String *id = NewString(++s);
String *id_conv = convert_literal(id, type, false);
Delete(id);
if (id_conv)
return NewStringf("(lognot %s)", id_conv);
s--;
}
if (SwigType_type(type) == T_FLOAT || SwigType_type(type) == T_DOUBLE || SwigType_type(type) == T_LONGDOUBLE) {
// Use CL syntax for float literals
String *oldnum = Copy(num);
@ -1136,7 +1147,7 @@ void emit_synonym(Node *synonym) {
of_ltype = lookup_defined_foreign_ltype(of_name);
// Printf(f_clhead,";; from emit-synonym\n");
// Printf(stderr,";; from emit-synonym syn='%s' of_ltype='%s'\n", syn_ltype, of_ltype);
if( of_ltype )
Printf(f_clhead, "(swig-def-synonym-type %s\n %s\n %s)\n", syn_ltype, of_ltype, syn_type);

View file

@ -1227,7 +1227,7 @@ public:
if ((enum_feature == ProperEnum) && Getattr(parentNode(n), "sym:name") && !Getattr(parentNode(n), "unnamedinstance")) {
// Wrap (non-anonymous) C/C++ enum with a proper C# enum
// Emit the enum item.
if (!Getattr(n, "_last")) // Only the first enum item has this attribute set
if (!GetFlag(n, "firstenumitem"))
Printf(enum_code, ",\n");
Printf(enum_code, " %s", symname);

View file

@ -1283,7 +1283,7 @@ public:
if ((enum_feature == ProperEnum) && Getattr(parentNode(n), "sym:name") && !Getattr(parentNode(n), "unnamedinstance")) {
// Wrap (non-anonymous) C/C++ enum with a proper Java enum
// Emit the enum item.
if (!Getattr(n, "_last")) // Only the first enum item has this attribute set
if (!GetFlag(n, "firstenumitem"))
Printf(enum_code, ",\n");
Printf(enum_code, " %s", symname);
if (Getattr(n, "enumvalue")) {

View file

@ -1627,11 +1627,6 @@ public:
Setattr(n, "type", return_type);
tm = Swig_typemap_lookup("directorout", n, "c_result", w);
Setattr(n, "type", type);
if (tm == 0) {
String *name = NewString("c_result");
tm = Swig_typemap_search("directorout", return_type, name, NULL);
Delete(name);
}
if (tm != 0) {
Replaceall(tm, "$input", "swig_result");
/* TODO check this */

View file

@ -1305,11 +1305,6 @@ public:
Setattr(n, "type", return_type);
tm = Swig_typemap_lookup("directorout", n, "result", w);
Setattr(n, "type", type);
if (tm == 0) {
String *name = NewString("result");
tm = Swig_typemap_search("directorout", return_type, name, NULL);
Delete(name);
}
if (tm != 0) {
char temp[24];
sprintf(temp, "out(%d)", idx);

View file

@ -3949,11 +3949,6 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) {
Setattr(n, "type", return_type);
tm = Swig_typemap_lookup("directorout", n, "result", w);
Setattr(n, "type", type);
if (tm == 0) {
String *name = NewString("result");
tm = Swig_typemap_search("directorout", return_type, name, NULL);
Delete(name);
}
if (tm != 0) {
if (outputs > 1) {
Printf(w->code, "output = PyTuple_GetItem(result, %d);\n", idx++);

View file

@ -3245,11 +3245,6 @@ public:
Setattr(n, "type", return_type);
tm = Swig_typemap_lookup("directorout", n, "result", w);
Setattr(n, "type", type);
if (tm == 0) {
String *name = NewString("result");
tm = Swig_typemap_search("directorout", return_type, name, NULL);
Delete(name);
}
if (tm != 0) {
if (outputs > 1 && !asvoid ) {
Printf(w->code, "output = rb_ary_entry(result, %d);\n", idx++);

View file

@ -730,6 +730,49 @@ class TypePass:private Dispatcher {
}
Setattr(n, "enumtype", enumtype);
// This block of code is for dealing with %ignore on an enum item where the target language
// attempts to use the C enum value in the target language itself and expects the previous enum value
// to be one more than the previous value... the previous enum item might not exist if it is ignored!
// - It sets the first non-ignored enum item with the "firstenumitem" attribute.
// - It adds an enumvalue attribute if the previous enum item is ignored
{
Node *c;
int count = 0;
String *previous = 0;
bool previous_ignored = false;
bool firstenumitem = false;
for (c = firstChild(n); c; c = nextSibling(c)) {
assert(strcmp(Char(nodeType(c)), "enumitem") == 0);
bool reset;
String *enumvalue = Getattr(c, "enumvalue");
if (GetFlag(c, "feature:ignore")) {
reset = enumvalue ? true : false;
previous_ignored = true;
} else {
if (!enumvalue && previous_ignored) {
if (previous)
Setattr(c, "enumvalue", NewStringf("(%s) + %d", previous, count+1));
else
Setattr(c, "enumvalue", NewStringf("%d", count));
SetFlag(c, "virtenumvalue"); // identify enumvalue as virtual, ie not from the parsed source
}
if (!firstenumitem) {
SetFlag(c, "firstenumitem");
firstenumitem = true;
}
reset = true;
previous_ignored = false;
}
if (reset) {
previous = enumvalue ? enumvalue : Getattr(c, "name");
count = 0;
} else {
count++;
}
}
}
emit_children(n);
return SWIG_OK;
}
@ -753,13 +796,16 @@ class TypePass:private Dispatcher {
Setattr(n, "value", new_value);
Delete(new_value);
}
// Make up an enumvalue if one was not specified in the parsed code
if (Getattr(n, "_last") && !Getattr(n, "enumvalue")) { // Only the first enum item has _last set
Setattr(n, "enumvalueex", "0");
}
Node *next = nextSibling(n);
if (next && !Getattr(next, "enumvalue")) {
Setattr(next, "enumvalueex", NewStringf("%s + 1", Getattr(n, "sym:name")));
// Make up an enumvalue if one was not specified in the parsed code (not designed to be used on enum items and %ignore - enumvalue will be set instead)
if (!GetFlag(n, "feature:ignore")) {
if (Getattr(n, "_last") && !Getattr(n, "enumvalue")) { // Only the first enum item has _last set (Note: first non-ignored enum item has firstenumitem set)
Setattr(n, "enumvalueex", "0");
}
if (next && !Getattr(next, "enumvalue")) {
Setattr(next, "enumvalueex", NewStringf("%s + 1", Getattr(n, "sym:name")));
}
}
return SWIG_OK;