mirror of https://github.com/swig/swig
Add nspacemove example for STL types
Java's nested iterator class in std::map, std::set, std::unordered_map, std::unordered_set needs to be public instead of protected for access to work when moving STL types into different Java packages.
This commit is contained in:
parent
e4795e9af0
commit
946e4ccf18
|
@ -354,6 +354,7 @@ CPP_TEST_CASES += \
|
|||
nspace_extend \
|
||||
nspacemove \
|
||||
nspacemove_nested \
|
||||
nspacemove_stl \
|
||||
null_pointer \
|
||||
numeric_bounds_checking \
|
||||
operator_overload \
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
using System;
|
||||
|
||||
public class runme
|
||||
{
|
||||
static void Main()
|
||||
{
|
||||
nspacemove_stlNamespace.CPlusPlus.Standard.Ints.VectorInt vi = new nspacemove_stlNamespace.CPlusPlus.Standard.Ints.VectorInt();
|
||||
nspacemove_stlNamespace.CPlusPlus.Standard.Strings.VectorString vs = new nspacemove_stlNamespace.CPlusPlus.Standard.Strings.VectorString();
|
||||
nspacemove_stlNamespace.CPlusPlus.Maps.MapIntInt mii = new nspacemove_stlNamespace.CPlusPlus.Maps.MapIntInt();
|
||||
nspacemove_stlNamespace.CPlusPlus.Maps.MapIntString mis = new nspacemove_stlNamespace.CPlusPlus.Maps.MapIntString();
|
||||
|
||||
nspacemove_stlNamespace.nspacemove_stl.test_vector_int(vi);
|
||||
nspacemove_stlNamespace.nspacemove_stl.test_vector_string(vs);
|
||||
nspacemove_stlNamespace.nspacemove_stl.test_map_int(mii);
|
||||
nspacemove_stlNamespace.nspacemove_stl.test_map_string(mis);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
module nspacemove_stl_runme;
|
||||
|
||||
import std.exception;
|
||||
import nspacemove_stl.nspacemove_stl;
|
||||
|
||||
void main() {
|
||||
auto vi = new nspacemove_stl.CPlusPlus.Standard.Ints.VectorInt.VectorInt();
|
||||
auto vs = new nspacemove_stl.CPlusPlus.Standard.Strings.VectorString.VectorString();
|
||||
auto mii = new nspacemove_stl.CPlusPlus.Maps.MapIntInt.MapIntInt();
|
||||
auto mis = new nspacemove_stl.CPlusPlus.Maps.MapIntString.MapIntString();
|
||||
|
||||
nspacemove_stl.nspacemove_stl.test_vector_int(vi);
|
||||
nspacemove_stl.nspacemove_stl.test_vector_string(vs);
|
||||
nspacemove_stl.nspacemove_stl.test_map_int(mii);
|
||||
nspacemove_stl.nspacemove_stl.test_map_string(mis);
|
||||
}
|
|
@ -89,6 +89,7 @@ nspace.%: JAVA_PACKAGE = $*Package
|
|||
nspace_extend.%: JAVA_PACKAGE = $*Package
|
||||
nspacemove.%: JAVA_PACKAGE = $*Package
|
||||
nspacemove_nested.%: JAVA_PACKAGE = $*Package
|
||||
nspacemove_stl.%: JAVA_PACKAGE = $*Package
|
||||
|
||||
# Rules for the different types of tests
|
||||
%.cpptest:
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
public class nspacemove_stl_runme {
|
||||
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("nspacemove_stl");
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String argv[]) {
|
||||
nspacemove_stlPackage.CPlusPlus.Standard.Ints.VectorInt vi = new nspacemove_stlPackage.CPlusPlus.Standard.Ints.VectorInt();
|
||||
nspacemove_stlPackage.CPlusPlus.Standard.Strings.VectorString vs = new nspacemove_stlPackage.CPlusPlus.Standard.Strings.VectorString();
|
||||
nspacemove_stlPackage.CPlusPlus.Maps.MapIntInt mii = new nspacemove_stlPackage.CPlusPlus.Maps.MapIntInt();
|
||||
nspacemove_stlPackage.CPlusPlus.Maps.MapIntString mis = new nspacemove_stlPackage.CPlusPlus.Maps.MapIntString();
|
||||
|
||||
nspacemove_stlPackage.nspacemove_stl.test_vector_int(vi);
|
||||
nspacemove_stlPackage.nspacemove_stl.test_vector_string(vs);
|
||||
nspacemove_stlPackage.nspacemove_stl.test_map_int(mii);
|
||||
nspacemove_stlPackage.nspacemove_stl.test_map_string(mis);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
var nspacemove_stl = require("nspacemove_stl");
|
||||
|
||||
vi = new nspacemove_stl.CPlusPlus.Standard.Ints.VectorInt()
|
||||
vs = new nspacemove_stl.CPlusPlus.Standard.Strings.VectorString()
|
||||
mii = new nspacemove_stl.CPlusPlus.Maps.MapIntInt()
|
||||
mis = new nspacemove_stl.CPlusPlus.Maps.MapIntString()
|
||||
|
||||
nspacemove_stl.test_vector_int(vi)
|
||||
nspacemove_stl.test_vector_string(vs)
|
||||
nspacemove_stl.test_map_int(mii)
|
||||
nspacemove_stl.test_map_string(mis)
|
|
@ -0,0 +1,18 @@
|
|||
require("import") -- the import fn
|
||||
import("nspacemove_stl") -- import lib
|
||||
|
||||
-- catch "undefined" global variables
|
||||
local env = _ENV -- Lua 5.2
|
||||
if not env then env = getfenv () end -- Lua 5.1
|
||||
setmetatable(env, {__index=function (t,i) error("undefined global variable `"..i.."'",2) end})
|
||||
|
||||
|
||||
vi = nspacemove_stl.CPlusPlus.Standard.Ints.VectorInt()
|
||||
vs = nspacemove_stl.CPlusPlus.Standard.Strings.VectorString()
|
||||
mii = nspacemove_stl.CPlusPlus.Maps.MapIntInt()
|
||||
mis = nspacemove_stl.CPlusPlus.Maps.MapIntString()
|
||||
|
||||
nspacemove_stl.test_vector_int(vi)
|
||||
nspacemove_stl.test_vector_string(vs)
|
||||
nspacemove_stl.test_map_int(mii)
|
||||
nspacemove_stl.test_map_string(mis)
|
|
@ -0,0 +1,27 @@
|
|||
%module nspacemove_stl
|
||||
|
||||
#if defined(SWIGJAVA)
|
||||
SWIG_JAVABODY_PROXY(public, public, SWIGTYPE)
|
||||
#endif
|
||||
|
||||
// %nspacemove needed before %include std_vector.i, std_map.i etc so that this nspace targetting the template is attached to the template node
|
||||
%nspacemove(CPlusPlus::Maps) std::map;
|
||||
|
||||
%include <stl.i>
|
||||
|
||||
// %nspacemove needed at least before instantiation of the templates
|
||||
%nspacemove(CPlusPlus::Standard::Ints) std::vector<int>;
|
||||
%nspacemove(CPlusPlus::Standard::Strings) std::vector<std::string>;
|
||||
|
||||
%template(VectorInt) std::vector<int>;
|
||||
%template(VectorString) std::vector<std::string>;
|
||||
|
||||
%template(MapIntInt) std::map<int, int>;
|
||||
%template(MapIntString) std::map<int, std::string>;
|
||||
|
||||
%inline %{
|
||||
void test_vector_int(std::vector<int> a) {}
|
||||
void test_vector_string(std::vector<std::string> a) {}
|
||||
void test_map_int(std::map<int, int> a) {}
|
||||
void test_map_string(std::map<int, std::string> a) {}
|
||||
%}
|
|
@ -156,7 +156,7 @@ template<class K, class T, class C = std::less< K> > class map {
|
|||
map(const map& other);
|
||||
|
||||
struct iterator {
|
||||
%typemap(javaclassmodifiers) iterator "protected class"
|
||||
%typemap(javaclassmodifiers) iterator "public class"
|
||||
%extend {
|
||||
std::map< K, T, C >::iterator getNextUnchecked() {
|
||||
std::map< K, T, C >::iterator copy = (*$self);
|
||||
|
|
|
@ -142,7 +142,7 @@ class set {
|
|||
public:
|
||||
|
||||
struct iterator {
|
||||
%typemap(javaclassmodifiers) iterator "protected class"
|
||||
%typemap(javaclassmodifiers) iterator "public class"
|
||||
%extend {
|
||||
void incrementUnchecked() {
|
||||
++(*$self);
|
||||
|
|
|
@ -156,7 +156,7 @@ template<class K, class T> class unordered_map {
|
|||
unordered_map(const unordered_map& other);
|
||||
|
||||
struct iterator {
|
||||
%typemap(javaclassmodifiers) iterator "protected class"
|
||||
%typemap(javaclassmodifiers) iterator "public class"
|
||||
%extend {
|
||||
std::unordered_map< K, T >::iterator getNextUnchecked() {
|
||||
std::unordered_map< K, T >::iterator copy = (*$self);
|
||||
|
|
|
@ -138,7 +138,7 @@ class unordered_set {
|
|||
public:
|
||||
|
||||
struct iterator {
|
||||
%typemap(javaclassmodifiers) iterator "protected class"
|
||||
%typemap(javaclassmodifiers) iterator "public class"
|
||||
%extend {
|
||||
void incrementUnchecked() {
|
||||
++(*$self);
|
||||
|
|
Loading…
Reference in New Issue