Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 33 additions & 93 deletions MMCoreJ_wrap/MMCoreJ.i
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
// CVS: $Id: MMCoreJ.i 16466 2017-08-23 21:46:52Z nico $
//

#if SWIG_VERSION < 0x020000 || SWIG_VERSION >= 0x040000
#error SWIG 2.x or 3.x is currently required to build MMCoreJ
// Different SWIG major versions can produce incompatible Java APIs.
#if SWIG_VERSION < 0x040000 || SWIG_VERSION >= 0x050000
#error "SWIG 4.x is required to build MMCoreJ"
#endif

%module (directors="1") MMCoreJ
Expand Down Expand Up @@ -603,7 +604,6 @@
// Map all exception objects coming from C++ level
// generic Java Exception
//
%rename(eql) operator=;

// CMMError used by MMCore
%typemap(throws, throws="java.lang.Exception") CMMError {
Expand Down Expand Up @@ -632,9 +632,17 @@
// We've translated exceptions to java.lang.Exception, so don't wrap the unused
// C++ exception classes.
%ignore CMMError;
%ignore MetadataError;
%ignore MetadataKeyError;
%ignore MetadataIndexError;

// Hide methods that take istringstream, which is not usable from Java
%ignore Metadata::readLine;
%ignore MetadataTag::ReadLine;
%ignore MetadataTag::Restore;
%ignore MetadataArrayTag::Restore;
%ignore MetadataSingleTag::Restore;


%typemap(javaimports) CMMCore %{
import mmcorej.org.json.JSONObject;
Expand Down Expand Up @@ -937,6 +945,16 @@

// instantiate STL mappings

// SWIG 4 changed the std::vector wrappers and (among other things) removed
// the constructor overload taking (Java) long, which creates a vector of the
// requested number of empty/default elements. Since all of the element types
// that we wrap vector for are default-constructible, we can add back this
// overload.
// See the 2019-02-28 entry in https://www.swig.org/Release/CHANGES.
%extend std::vector {
vector(size_type count) { return new std::vector<T>(count); }
}

namespace std {
%typemap(javaimports) vector<char> %{
import java.lang.Iterable;
Expand Down Expand Up @@ -965,22 +983,18 @@ namespace std {
throw new NoSuchElementException();
}
}

public void remove() throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}
};
}

public Character[] toArray() {
if (0==size())
return new Character[0];

Character ints[] = new Character[(int) size()];
Character cs[] = new Character[(int) size()];
for (int i=0; i<size(); ++i) {
ints[i] = get(i);
cs[i] = get(i);
}
return ints;
return cs;
}
%}

Expand Down Expand Up @@ -1016,22 +1030,18 @@ namespace std {
throw new NoSuchElementException();
}
}

public void remove() throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}
};
}

public Integer[] toArray() {
if (0==size())
return new Integer[0];

Integer ints[] = new Integer[(int) size()];
Integer is[] = new Integer[(int) size()];
for (int i=0; i<size(); ++i) {
ints[i] = get(i);
is[i] = get(i);
}
return ints;
return is;
}
%}

Expand Down Expand Up @@ -1062,22 +1072,18 @@ namespace std {
throw new NoSuchElementException();
}
}

public void remove() throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}
};
}

public Double[] toArray() {
if (0==size())
return new Double[0];

Double ints[] = new Double[(int) size()];
Double ds[] = new Double[(int) size()];
for (int i=0; i<size(); ++i) {
ints[i] = get(i);
ds[i] = get(i);
}
return ints;
return ds;
}
%}

Expand Down Expand Up @@ -1110,10 +1116,6 @@ namespace std {
throw new NoSuchElementException();
}
}

public void remove() throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}
};
}

Expand All @@ -1129,57 +1131,6 @@ namespace std {
}

%}



%typemap(javaimports) vector<bool> %{
import java.lang.Iterable;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.lang.UnsupportedOperationException;
%}

%typemap(javainterfaces) vector<bool> %{ Iterable<Boolean>%}

%typemap(javacode) vector<bool> %{

public Iterator<Boolean> iterator() {
return new Iterator<Boolean>() {

private int i_=0;

public boolean hasNext() {
return (i_<size());
}

public Boolean next() throws NoSuchElementException {
if (hasNext()) {
++i_;
return get(i_-1);
} else {
throw new NoSuchElementException();
}
}

public void remove() throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}
};
}

public Boolean[] toArray() {
if (0==size())
return new Boolean[0];

Boolean strs[] = new Boolean[(int) size()];
for (int i=0; i<size(); ++i) {
strs[i] = get(i);
}
return strs;
}

%}


%typemap(javaimports) vector<unsigned> %{
import java.lang.Iterable;
Expand Down Expand Up @@ -1208,22 +1159,18 @@ namespace std {
throw new NoSuchElementException();
}
}

public void remove() throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}
};
}

public Long[] toArray() {
if (0==size())
return new Long[0];

Long ints[] = new Long[(int) size()];
Long ls[] = new Long[(int) size()];
for (int i=0; i<size(); ++i) {
ints[i] = get(i);
ls[i] = get(i);
}
return ints;
return ls;
}
%}

Expand All @@ -1234,14 +1181,7 @@ namespace std {
%template(LongVector) vector<long>;
%template(DoubleVector) vector<double>;
%template(StrVector) vector<string>;
%template(BooleanVector) vector<bool>;
%template(UnsignedVector) vector<unsigned>;
%template(pair_ss) pair<string, string>;
%template(StrMap) map<string, string>;




}


Expand Down