phase 2 of c# simplifications
This commit is contained in:
@@ -13,7 +13,10 @@
|
||||
|
||||
// TODO(user): Refactor this file to adhere to the SWIG style guide.
|
||||
|
||||
%include util/csharp/data.swig
|
||||
%include base/base.swig
|
||||
|
||||
/* allow partial c# classes */
|
||||
%typemap(csclassmodifiers) SWIGTYPE "public partial class"
|
||||
|
||||
// Include the file we want to wrap a first time.
|
||||
%{
|
||||
@@ -22,10 +25,11 @@
|
||||
|
||||
%include "std_vector.i"
|
||||
|
||||
%template(KIntVector) std::vector<int>;
|
||||
%template(KInt64Vector) std::vector<int64>;
|
||||
%template(KInt64VectorVector) std::vector<std::vector<int64> >;
|
||||
|
||||
%rename (UseReduction) operations_research::KnapsackSolver::use_reduction;
|
||||
%rename (SetUseReduction) operations_research::KnapsackSolver::set_use_reduction;
|
||||
|
||||
|
||||
%include "algorithms/knapsack_solver.h"
|
||||
|
||||
@@ -37,24 +37,39 @@ public partial class KInt64Vector: IDisposable, System.Collections.IEnumerable
|
||||
}
|
||||
}
|
||||
|
||||
public partial class KIntVector: IDisposable, System.Collections.IEnumerable
|
||||
public partial class KInt64VectorVector : IDisposable, System.Collections.IEnumerable
|
||||
#if !SWIG_DOTNET_1
|
||||
, System.Collections.Generic.IList<int>
|
||||
, System.Collections.Generic.IEnumerable<KInt64Vector>
|
||||
#endif
|
||||
{
|
||||
// cast from C# int array
|
||||
public static implicit operator KIntVector(int[] inVal) {
|
||||
var outVal= new KIntVector();
|
||||
foreach (int element in inVal) {
|
||||
outVal.Add(element);
|
||||
{
|
||||
// cast from C# long matrix
|
||||
public static implicit operator KInt64VectorVector(long[,] inVal) {
|
||||
int x_size = inVal.GetLength(0);
|
||||
int y_size = inVal.GetLength(1);
|
||||
KInt64VectorVector outVal = new KInt64VectorVector();
|
||||
for (int i = 0; i < x_size; ++i)
|
||||
{
|
||||
outVal.Add(new KInt64Vector());
|
||||
for (int j = 0; j < y_size; ++j)
|
||||
{
|
||||
outVal[i].Add(inVal[i, j]);
|
||||
}
|
||||
}
|
||||
return outVal;
|
||||
}
|
||||
|
||||
// cast to C# int array
|
||||
public static implicit operator int[](KIntVector inVal) {
|
||||
var outVal= new int[inVal.Count];
|
||||
inVal.CopyTo(outVal);
|
||||
// cast to C# long matrix
|
||||
public static implicit operator long[,](KInt64VectorVector inVal) {
|
||||
int x_size = inVal.Count;
|
||||
int y_size = inVal.Count == 0 ? 0 : inVal[0].Count;
|
||||
var outVal= new long[x_size, y_size];
|
||||
for (int i = 0; i < x_size; ++i)
|
||||
{
|
||||
for (int j = 0; j < y_size; ++j)
|
||||
{
|
||||
outVal[i, j] = inVal[i][j];
|
||||
}
|
||||
}
|
||||
return outVal;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,9 +14,11 @@
|
||||
// TODO(user): Refactor this file to adhere to the SWIG style guide.
|
||||
|
||||
%include exception.i
|
||||
%include util/csharp/data.swig
|
||||
%include util/csharp/tuple_set.swig
|
||||
|
||||
/* allow partial c# classes */
|
||||
%typemap(csclassmodifiers) SWIGTYPE "public partial class"
|
||||
|
||||
// ############ BEGIN DUPLICATED CODE BLOCK ############
|
||||
// IMPORTANT: keep this code block in sync with the .swig
|
||||
// files in ../python and ../csharp.
|
||||
|
||||
@@ -65,6 +65,44 @@
|
||||
%}
|
||||
%enddef // CS_TYPEMAP_STDVECTOR
|
||||
|
||||
////////////////////////////////////////////////
|
||||
//
|
||||
// CS_TYPEMAP_STDVECTOR_IN1
|
||||
//
|
||||
// Map c# bi-dimensional arrays to c++ vectors of vectors for POD types.
|
||||
//
|
||||
////////////////////////////////////////////////
|
||||
|
||||
%define CS_TYPEMAP_STDVECTOR_IN1(TYPE, CTYPE, CSHARPTYPE)
|
||||
%typemap(ctype) const std::vector<std::vector<TYPE> >& %{
|
||||
int len$argnum_1, int len$argnum_2, CTYPE*
|
||||
%}
|
||||
%typemap(imtype) const std::vector<std::vector<TYPE> >& %{
|
||||
int len$argnum_1, int len$argnum_2, CSHARPTYPE[]
|
||||
%}
|
||||
%typemap(cstype) const std::vector<std::vector<TYPE> >& %{ CSHARPTYPE[,] %}
|
||||
%typemap(csin) const std::vector<std::vector<TYPE> >& "$csinput.GetLength(0),$csinput.GetLength(1), NestedArrayHelper.GetFlatArray($csinput)"
|
||||
%typemap(in) const std::vector<std::vector<TYPE> >& (std::vector<std::vector<TYPE> > result) %{
|
||||
const int size_x = len$argnum_1;
|
||||
const int size_y = len$argnum_2;
|
||||
|
||||
result.clear();
|
||||
result.resize(size_x);
|
||||
|
||||
TYPE* inner_array = reinterpret_cast<TYPE*>($input);
|
||||
|
||||
for (int index1 = 0; index1 < size_x; ++index1) {
|
||||
result[index1].reserve(size_y);
|
||||
for (int index2 = 0; index2 < size_y; ++index2) {
|
||||
const TYPE value = inner_array[index1 * size_y + index2];
|
||||
result[index1].emplace_back(value);
|
||||
}
|
||||
}
|
||||
|
||||
$1 = &result;
|
||||
%}
|
||||
%enddef // CS_TYPEMAP_STDVECTOR_IN1
|
||||
|
||||
CS_TYPEMAP_STDVECTOR(operations_research::RoutingModel::NodeIndex, int, int);
|
||||
CS_TYPEMAP_STDVECTOR_IN1(operations_research::RoutingModel::NodeIndex, int, int);
|
||||
|
||||
|
||||
@@ -1316,7 +1316,7 @@ class RoutingDimension {
|
||||
Solver::IndexEvaluator2* transit_evaluator(int vehicle) const {
|
||||
return transit_evaluators_[vehicle];
|
||||
}
|
||||
#endif
|
||||
#endif // SWIGCSHARP
|
||||
#endif // !defined(SWIGPYTHON) && !defined(SWIGJAVA)
|
||||
// Sets an upper bound on the dimension span on a given vehicle. This is the
|
||||
// preferred way to limit the "length" of the route of a vehicle according to
|
||||
|
||||
@@ -19,52 +19,6 @@
|
||||
using std::string;
|
||||
%}
|
||||
|
||||
%include base/base.swig
|
||||
|
||||
////////////////////////////////////////////////
|
||||
//
|
||||
// CS_TYPEMAP_STDVECTOR_IN1
|
||||
//
|
||||
// Map c# bi-dimensional arrays to c++ vectors of vectors for POD types.
|
||||
//
|
||||
////////////////////////////////////////////////
|
||||
|
||||
%define CS_TYPEMAP_STDVECTOR_IN1(TYPE, CTYPE, CSHARPTYPE)
|
||||
%typemap(ctype) const std::vector<std::vector<TYPE> >& %{
|
||||
int len$argnum_1, int len$argnum_2, CTYPE*
|
||||
%}
|
||||
%typemap(imtype) const std::vector<std::vector<TYPE> >& %{
|
||||
int len$argnum_1, int len$argnum_2, CSHARPTYPE[]
|
||||
%}
|
||||
%typemap(cstype) const std::vector<std::vector<TYPE> >& %{ CSHARPTYPE[,] %}
|
||||
%typemap(csin) const std::vector<std::vector<TYPE> >& "$csinput.GetLength(0),$csinput.GetLength(1), NestedArrayHelper.GetFlatArray($csinput)"
|
||||
%typemap(in) const std::vector<std::vector<TYPE> >& (std::vector<std::vector<TYPE> > result) %{
|
||||
const int size_x = len$argnum_1;
|
||||
const int size_y = len$argnum_2;
|
||||
|
||||
result.clear();
|
||||
result.resize(size_x);
|
||||
|
||||
TYPE* inner_array = reinterpret_cast<TYPE*>($input);
|
||||
|
||||
for (int index1 = 0; index1 < size_x; ++index1) {
|
||||
result[index1].reserve(size_y);
|
||||
for (int index2 = 0; index2 < size_y; ++index2) {
|
||||
const TYPE value = inner_array[index1 * size_y + index2];
|
||||
result[index1].emplace_back(value);
|
||||
}
|
||||
}
|
||||
|
||||
$1 = &result;
|
||||
%}
|
||||
%enddef // CS_TYPEMAP_STDVECTOR_IN1
|
||||
|
||||
/* allow partial c# classes */
|
||||
%typemap(csclassmodifiers) SWIGTYPE "public partial class"
|
||||
|
||||
CS_TYPEMAP_STDVECTOR_IN1(int64, int64, long)
|
||||
CS_TYPEMAP_STDVECTOR_IN1(int, int, int)
|
||||
|
||||
// SWIG macros to be used in generating C# wrappers for C++ protocol
|
||||
// message parameters. Each protocol message is serialized into
|
||||
// byte[] before passing into (or returning from) C++ code.
|
||||
|
||||
@@ -15,10 +15,6 @@
|
||||
|
||||
%include "base/base.swig"
|
||||
|
||||
// This .swig include provides a lot of typemap conversion tools.
|
||||
// TODO(user): see if we really need it.
|
||||
%include util/csharp/data.swig
|
||||
|
||||
%{
|
||||
// TODO(user): See if we really need <vector>.
|
||||
#include <vector>
|
||||
|
||||
Reference in New Issue
Block a user