Merge branch 'bkotzz-add_set_map'

* bkotzz-add_set_map:
  Add missing typedefs to Java STL containers
  Combine duplicate unordered_set unordered_map testcases
  Nicer looking generated Java container code
  Replicate some cosmetic changes from std_map.i
  Legacy macros, protected iterator, typedefs
  Remove c++11 from stl.i
  Add to STL file as well
  Maps both working as java.util impls
  Mostly working for map
  Add set/unordered_set that extend AbstractSet
  Move unordered containers under cpp11_ prefix
  Add test cases to C++11 list
  Add unordered_{set|map} and set to Java
This commit is contained in:
William S Fulton 2019-02-12 18:09:38 +00:00
commit 136e6cfe2b
13 changed files with 1211 additions and 45 deletions

View file

@ -44,6 +44,8 @@ CPP_TEST_CASES = \
java_typemaps_proxy \
java_typemaps_typewrapper \
li_std_list \
li_std_map \
li_std_set \
# li_boost_intrusive_ptr
CPP11_TEST_CASES = \
@ -51,6 +53,8 @@ CPP11_TEST_CASES = \
cpp11_shared_ptr_nullptr_in_containers \
cpp11_shared_ptr_overload \
cpp11_shared_ptr_upcast \
cpp11_std_unordered_map \
cpp11_std_unordered_set \
cpp11_strongly_typed_enumerations_simple \
DOXYGEN_TEST_CASES := \

View file

@ -0,0 +1,122 @@
import cpp11_std_unordered_map.*;
public class cpp11_std_unordered_map_runme {
static {
try {
System.loadLibrary("cpp11_std_unordered_map");
} 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 checkThat(boolean mustBeTrue) throws Throwable {
if (!mustBeTrue) {
// Index [2], since this function is one hop away from main, and [1] is the current method.
throw new RuntimeException("Test failed at line number " + Thread.currentThread().getStackTrace()[2].getLineNumber());
}
}
public static void main(String argv[]) throws Throwable
{
java.util.AbstractMap<String, Integer> sim = new UnorderedMapStringInt();
java.util.AbstractMap<Integer, Integer> iim = new UnorderedMapIntInt();
checkThat(sim.isEmpty());
checkThat(iim.isEmpty());
checkThat(sim.size() == 0);
checkThat(iim.size() == 0);
checkThat(sim.get("key") == null);
checkThat(iim.get(1) == null);
checkThat(!sim.containsKey("key"));
checkThat(!iim.containsKey(1));
checkThat(sim.put("key", 2) == null);
checkThat(iim.put(1, 2) == null);
checkThat(sim.size() == 1);
checkThat(iim.size() == 1);
checkThat(!sim.isEmpty());
checkThat(!iim.isEmpty());
checkThat(sim.get("key") == 2);
checkThat(iim.get(1) == 2);
checkThat(sim.remove("key") == 2);
checkThat(iim.remove(1) == 2);
checkThat(sim.isEmpty());
checkThat(iim.isEmpty());
checkThat(sim.size() == 0);
checkThat(iim.size() == 0);
checkThat(sim.get("key") == null);
checkThat(iim.get(1) == null);
checkThat(sim.remove("key") == null);
checkThat(iim.remove(1) == null);
checkThat(sim.put("key", 2) == null);
checkThat(iim.put(1, 2) == null);
sim.clear();
iim.clear();
checkThat(sim.isEmpty());
checkThat(iim.isEmpty());
checkThat(sim.put("key1", 1) == null);
checkThat(iim.put(1, 1) == null);
checkThat(sim.put("key2", 2) == null);
checkThat(iim.put(2, 2) == null);
checkThat(sim.size() == 2);
checkThat(iim.size() == 2);
checkThat(sim.get("key1") == 1);
checkThat(iim.get(1) == 1);
checkThat(sim.get("key2") == 2);
checkThat(iim.get(2) == 2);
checkThat(sim.put("key1", 3) == 1);
checkThat(iim.put(1, 3) == 1);
checkThat(sim.size() == 2);
checkThat(iim.size() == 2);
checkThat(sim.get("key1") == 3);
checkThat(iim.get(1) == 3);
java.util.Set<java.util.Map.Entry<String, Integer>> sim_es = sim.entrySet();
java.util.Map<String, Integer> sim_default = new java.util.HashMap<String, Integer>();
sim_default.put("key1", 3);
sim_default.put("key2", 2);
java.util.Set<java.util.Map.Entry<String, Integer>> sim_es_default = sim_default.entrySet();
checkThat(sim_es.size() == sim_es_default.size());
for (java.util.Map.Entry<String, Integer> entry : sim_es) {
checkThat(sim_es_default.contains(entry));
checkThat(sim_default.containsKey(entry.getKey()));
checkThat(sim_default.containsValue(entry.getValue()));
Integer oldValue = entry.getValue();
entry.setValue(oldValue + 1);
checkThat(sim.get(entry.getKey()) == (oldValue + 1));
}
java.util.Set<java.util.Map.Entry<Integer, Integer>> iim_es = iim.entrySet();
java.util.Map<Integer, Integer> iim_default = new java.util.HashMap<Integer, Integer>();
iim_default.put(1, 3);
iim_default.put(2, 2);
java.util.Set<java.util.Map.Entry<Integer, Integer>> iim_es_default = iim_default.entrySet();
checkThat(iim_es.size() == iim_es_default.size());
for (java.util.Map.Entry<Integer, Integer> entry : iim_es) {
checkThat(iim_es_default.contains(entry));
checkThat(iim_default.containsKey(entry.getKey()));
checkThat(iim_default.containsValue(entry.getValue()));
Integer oldValue = entry.getValue();
entry.setValue(oldValue + 1);
checkThat(iim.get(entry.getKey()) == (oldValue + 1));
}
}
}

View file

@ -0,0 +1,75 @@
import cpp11_std_unordered_set.*;
public class cpp11_std_unordered_set_runme {
static {
try {
System.loadLibrary("cpp11_std_unordered_set");
} 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 checkThat(boolean mustBeTrue) throws Throwable {
if (!mustBeTrue) {
// Index [2], since this function is one hop away from main, and [1] is the current method.
throw new RuntimeException("Test failed at line number " + Thread.currentThread().getStackTrace()[2].getLineNumber());
}
}
public static void main(String argv[]) throws Throwable
{
java.util.AbstractSet<String> ss = new UnorderedSetString();
checkThat(ss.isEmpty());
checkThat(!ss.contains("key"));
checkThat(!ss.remove("key"));
checkThat(ss.add("key"));
checkThat(!ss.add("key"));
checkThat(ss.contains("key"));
checkThat(ss.remove("key"));
checkThat(ss.isEmpty());
checkThat(ss.size() == 0);
checkThat(ss.add("key1"));
checkThat(ss.add("key2"));
checkThat(ss.add("key3"));
checkThat(ss.size() == 3);
ss.clear();
checkThat(ss.isEmpty());
checkThat(ss.size() == 0);
checkThat(ss.addAll(java.util.Arrays.asList("one", "two", "three")));
checkThat(ss.size() == 3);
checkThat(ss.contains("one"));
checkThat(!ss.contains("four"));
checkThat(ss.containsAll(java.util.Arrays.asList("one", "two", "three")));
checkThat(ss.containsAll(java.util.Arrays.asList("one", "two")));
checkThat(!ss.containsAll(java.util.Arrays.asList("one", "two", "four")));
checkThat(!ss.containsAll(java.util.Arrays.asList("one", "two", "three", "four")));
checkThat(!ss.addAll(java.util.Arrays.asList("one", "two", "three")));
java.util.Set<String> found = new java.util.HashSet<String>();
java.util.Iterator<String> itr = ss.iterator();
while (itr.hasNext()) {
found.add(itr.next());
}
checkThat(ss.containsAll(found));
checkThat(found.containsAll(ss));
java.util.AbstractSet<String> ss2 = new UnorderedSetString(ss);
checkThat(ss2.containsAll(ss));
checkThat(ss.containsAll(ss2));
checkThat(!ss.removeAll(java.util.Arrays.asList("five", "four")));
checkThat(ss.removeAll(found));
checkThat(ss.isEmpty());
checkThat(ss.size() == 0);
}
}

View file

@ -0,0 +1,122 @@
import li_std_map.*;
public class li_std_map_runme {
static {
try {
System.loadLibrary("li_std_map");
} 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 checkThat(boolean mustBeTrue) throws Throwable {
if (!mustBeTrue) {
// Index [2], since this function is one hop away from main, and [1] is the current method.
throw new RuntimeException("Test failed at line number " + Thread.currentThread().getStackTrace()[2].getLineNumber());
}
}
public static void main(String argv[]) throws Throwable
{
java.util.AbstractMap<String, Integer> sim = new StringIntMap();
java.util.AbstractMap<Integer, Integer> iim = new IntIntMap();
checkThat(sim.isEmpty());
checkThat(iim.isEmpty());
checkThat(sim.size() == 0);
checkThat(iim.size() == 0);
checkThat(sim.get("key") == null);
checkThat(iim.get(1) == null);
checkThat(!sim.containsKey("key"));
checkThat(!iim.containsKey(1));
checkThat(sim.put("key", 2) == null);
checkThat(iim.put(1, 2) == null);
checkThat(sim.size() == 1);
checkThat(iim.size() == 1);
checkThat(!sim.isEmpty());
checkThat(!iim.isEmpty());
checkThat(sim.get("key") == 2);
checkThat(iim.get(1) == 2);
checkThat(sim.remove("key") == 2);
checkThat(iim.remove(1) == 2);
checkThat(sim.isEmpty());
checkThat(iim.isEmpty());
checkThat(sim.size() == 0);
checkThat(iim.size() == 0);
checkThat(sim.get("key") == null);
checkThat(iim.get(1) == null);
checkThat(sim.remove("key") == null);
checkThat(iim.remove(1) == null);
checkThat(sim.put("key", 2) == null);
checkThat(iim.put(1, 2) == null);
sim.clear();
iim.clear();
checkThat(sim.isEmpty());
checkThat(iim.isEmpty());
checkThat(sim.put("key1", 1) == null);
checkThat(iim.put(1, 1) == null);
checkThat(sim.put("key2", 2) == null);
checkThat(iim.put(2, 2) == null);
checkThat(sim.size() == 2);
checkThat(iim.size() == 2);
checkThat(sim.get("key1") == 1);
checkThat(iim.get(1) == 1);
checkThat(sim.get("key2") == 2);
checkThat(iim.get(2) == 2);
checkThat(sim.put("key1", 3) == 1);
checkThat(iim.put(1, 3) == 1);
checkThat(sim.size() == 2);
checkThat(iim.size() == 2);
checkThat(sim.get("key1") == 3);
checkThat(iim.get(1) == 3);
java.util.Set<java.util.Map.Entry<String, Integer>> sim_es = sim.entrySet();
java.util.Map<String, Integer> sim_default = new java.util.HashMap<String, Integer>();
sim_default.put("key1", 3);
sim_default.put("key2", 2);
java.util.Set<java.util.Map.Entry<String, Integer>> sim_es_default = sim_default.entrySet();
checkThat(sim_es.size() == sim_es_default.size());
for (java.util.Map.Entry<String, Integer> entry : sim_es) {
checkThat(sim_es_default.contains(entry));
checkThat(sim_default.containsKey(entry.getKey()));
checkThat(sim_default.containsValue(entry.getValue()));
Integer oldValue = entry.getValue();
entry.setValue(oldValue + 1);
checkThat(sim.get(entry.getKey()) == (oldValue + 1));
}
java.util.Set<java.util.Map.Entry<Integer, Integer>> iim_es = iim.entrySet();
java.util.Map<Integer, Integer> iim_default = new java.util.HashMap<Integer, Integer>();
iim_default.put(1, 3);
iim_default.put(2, 2);
java.util.Set<java.util.Map.Entry<Integer, Integer>> iim_es_default = iim_default.entrySet();
checkThat(iim_es.size() == iim_es_default.size());
for (java.util.Map.Entry<Integer, Integer> entry : iim_es) {
checkThat(iim_es_default.contains(entry));
checkThat(iim_default.containsKey(entry.getKey()));
checkThat(iim_default.containsValue(entry.getValue()));
Integer oldValue = entry.getValue();
entry.setValue(oldValue + 1);
checkThat(iim.get(entry.getKey()) == (oldValue + 1));
}
}
}

View file

@ -0,0 +1,75 @@
import li_std_set.*;
public class li_std_set_runme {
static {
try {
System.loadLibrary("li_std_set");
} 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 checkThat(boolean mustBeTrue) throws Throwable {
if (!mustBeTrue) {
// Index [2], since this function is one hop away from main, and [1] is the current method.
throw new RuntimeException("Test failed at line number " + Thread.currentThread().getStackTrace()[2].getLineNumber());
}
}
public static void main(String argv[]) throws Throwable
{
java.util.AbstractSet<String> ss = new StringSet();
checkThat(ss.isEmpty());
checkThat(!ss.contains("key"));
checkThat(!ss.remove("key"));
checkThat(ss.add("key"));
checkThat(!ss.add("key"));
checkThat(ss.contains("key"));
checkThat(ss.remove("key"));
checkThat(ss.isEmpty());
checkThat(ss.size() == 0);
checkThat(ss.add("key1"));
checkThat(ss.add("key2"));
checkThat(ss.add("key3"));
checkThat(ss.size() == 3);
ss.clear();
checkThat(ss.isEmpty());
checkThat(ss.size() == 0);
checkThat(ss.addAll(java.util.Arrays.asList("one", "two", "three")));
checkThat(ss.size() == 3);
checkThat(ss.contains("one"));
checkThat(!ss.contains("four"));
checkThat(ss.containsAll(java.util.Arrays.asList("one", "two", "three")));
checkThat(ss.containsAll(java.util.Arrays.asList("one", "two")));
checkThat(!ss.containsAll(java.util.Arrays.asList("one", "two", "four")));
checkThat(!ss.containsAll(java.util.Arrays.asList("one", "two", "three", "four")));
checkThat(!ss.addAll(java.util.Arrays.asList("one", "two", "three")));
java.util.Set<String> found = new java.util.HashSet<String>();
java.util.Iterator<String> itr = ss.iterator();
while (itr.hasNext()) {
found.add(itr.next());
}
checkThat(ss.containsAll(found));
checkThat(found.containsAll(ss));
java.util.AbstractSet<String> ss2 = new StringSet(ss);
checkThat(ss2.containsAll(ss));
checkThat(ss.containsAll(ss2));
checkThat(!ss.removeAll(java.util.Arrays.asList("five", "four")));
checkThat(ss.removeAll(found));
checkThat(ss.isEmpty());
checkThat(ss.size() == 0);
}
}