Merge branch 'csharp-set-fixes'

* csharp-set-fixes:
  Fix std::vector<> Java typemaps for primitive types
  Allow std::set<> C# typemaps to work for non-nullable types too
  Replace leftover string with the proper type in C# set typemap
This commit is contained in:
William S Fulton 2019-07-12 08:13:19 +01:00
commit 1e66c13abd
5 changed files with 58 additions and 4 deletions

View file

@ -85,5 +85,21 @@ public class runme
ss = new StringSet{"foo", "bar", "baz"};
ss.UnionWith(new[] {"baz", "quux"});
checkThat(ss.SetEquals(new[] {"foo", "bar", "baz", "quux"}), "UnionWith works");
// Check a set of another type.
FooSet fooSet = new FooSet();
ISet<Foo> fooISet = fooSet;
checkThat(fooISet.Count == 0, "is initially empty");
checkThat(fooISet.Add(new Foo(17)), "added successfully");
checkThat(fooISet.Count == 1, "is not empty any more");
// And a set of primitive type.
IntSet intSet = new IntSet();
checkThat(intSet.Count == 0, "is initially empty");
checkThat(intSet.Add(17), "17 added successfully");
checkThat(!intSet.Add(17), "17 not added again");
checkThat(intSet.Count == 1, "not empty any more");
checkThat(intSet.Add(289), "289 added successfully");
checkThat(intSet.Count == 2, "even less empty now");
}
}

View file

@ -71,5 +71,20 @@ public class li_std_set_runme {
checkThat(ss.removeAll(found));
checkThat(ss.isEmpty());
checkThat(ss.size() == 0);
// Check a set of another type.
java.util.AbstractSet<Foo> fooSet = new FooSet();
checkThat(fooSet.isEmpty());
checkThat(fooSet.add(new Foo(17)));
checkThat(fooSet.size() == 1);
// And a set of primitive type.
java.util.AbstractSet<Integer> intSet = new IntSet();
checkThat(intSet.isEmpty());
checkThat(intSet.add(17));
checkThat(!intSet.add(17));
checkThat(intSet.size() == 1);
checkThat(intSet.add(289));
checkThat(intSet.size() == 2);
}
}

View file

@ -23,7 +23,26 @@
%template(v_int) std::vector<int>;
%template(set_string) std::set<std::string>;
#elif defined(SWIGJAVA) || defined(SWIGCSHARP)
// This operator is only defined because it's needed to store objects of
// type Foo in std::set in C++, we don't need to wrap it.
%ignore operator<;
%inline %{
struct Foo
{
explicit Foo(int n) : n(n) {}
int n;
friend bool operator<(Foo foo1, Foo foo2)
{
return foo1.n < foo2.n;
}
};
%}
%template(IntSet) std::set<int>;
%template(StringSet) std::set<std::string>;
%template(FooSet) std::set<Foo>;
#endif
#if defined(SWIGRUBY)