Files
ortools-clone/ortools/util/csharp/vector.i

265 lines
10 KiB
OpenEdge ABL
Raw Normal View History

// Copyright 2010-2021 Google LLC
dotnet: Remove reference to dotnet release command - Currently not implemented... Add abseil patch - Add patches/absl-config.cmake Makefile: Add abseil-cpp on unix - Force abseil-cpp SHA1 to 45221cc note: Just before the PR #136 which break all CMake Makefile: Add abseil-cpp on windows - Force abseil-cpp SHA1 to 45221cc note: Just before the PR #136 which break all CMake CMake: Add abseil-cpp - Force abseil-cpp SHA1 to 45221cc note: Just before the PR #136 which break all CMake port to absl: C++ Part - Fix warning with the use of ABSL_MUST_USE_RESULT > The macro must appear as the very first part of a function declaration or definition: ... Note: past advice was to place the macro after the argument list. src: dependencies/sources/abseil-cpp-master/absl/base/attributes.h:418 - Rename enum after windows clash - Remove non compact table constraints - Change index type from int64 to int in routing library - Fix file_nonport compilation on windows - Fix another naming conflict with windows (NO_ERROR is a macro) - Cleanup hash containers; work on sat internals - Add optional_boolean sub-proto Sync cpp examples with internal code - reenable issue173 after reducing number of loops port to absl: Python Part - Add back cp_model.INT32_MIN|MAX for examples Update Python examples - Add random_tsp.py - Run words_square example - Run magic_square in python tests port to absl: Java Part - Fix compilation of the new routing parameters in java - Protect some code from SWIG parsing Update Java Examples port to absl: .Net Part Update .Net examples work on sat internals; Add C++ CP-SAT CpModelBuilder API; update sample code and recipes to use the new API; sync with internal code Remove VS 2015 in Appveyor-CI - abseil-cpp does not support VS 2015... improve tables upgrade C++ sat examples to use the new API; work on sat internals update license dates rewrite jobshop_ft06_distance.py to use the CP-SAT solver rename last example revert last commit more work on SAT internals fix
2018-10-31 16:18:18 +01:00
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
2020-03-09 17:52:25 +01:00
dotnet: Remove reference to dotnet release command - Currently not implemented... Add abseil patch - Add patches/absl-config.cmake Makefile: Add abseil-cpp on unix - Force abseil-cpp SHA1 to 45221cc note: Just before the PR #136 which break all CMake Makefile: Add abseil-cpp on windows - Force abseil-cpp SHA1 to 45221cc note: Just before the PR #136 which break all CMake CMake: Add abseil-cpp - Force abseil-cpp SHA1 to 45221cc note: Just before the PR #136 which break all CMake port to absl: C++ Part - Fix warning with the use of ABSL_MUST_USE_RESULT > The macro must appear as the very first part of a function declaration or definition: ... Note: past advice was to place the macro after the argument list. src: dependencies/sources/abseil-cpp-master/absl/base/attributes.h:418 - Rename enum after windows clash - Remove non compact table constraints - Change index type from int64 to int in routing library - Fix file_nonport compilation on windows - Fix another naming conflict with windows (NO_ERROR is a macro) - Cleanup hash containers; work on sat internals - Add optional_boolean sub-proto Sync cpp examples with internal code - reenable issue173 after reducing number of loops port to absl: Python Part - Add back cp_model.INT32_MIN|MAX for examples Update Python examples - Add random_tsp.py - Run words_square example - Run magic_square in python tests port to absl: Java Part - Fix compilation of the new routing parameters in java - Protect some code from SWIG parsing Update Java Examples port to absl: .Net Part Update .Net examples work on sat internals; Add C++ CP-SAT CpModelBuilder API; update sample code and recipes to use the new API; sync with internal code Remove VS 2015 in Appveyor-CI - abseil-cpp does not support VS 2015... improve tables upgrade C++ sat examples to use the new API; work on sat internals update license dates rewrite jobshop_ft06_distance.py to use the CP-SAT solver rename last example revert last commit more work on SAT internals fix
2018-10-31 16:18:18 +01:00
%include "ortools/base/base.i"
%{
#include <vector>
#include "ortools/base/integral_types.h"
%}
// Typemaps to represent arguments of types:
// - "const std::vector<TYPE>&" or
// - "std::vector<TYPE>"
// as CSHARPTYPE[].
2019-03-13 13:50:23 +01:00
// note: TYPE must be a primitive data type (PDT).
2019-03-04 15:00:38 +01:00
%define VECTOR_AS_CSHARP_ARRAY(TYPE, CTYPE, CSHARPTYPE, ARRAYTYPE)
2019-03-13 13:50:23 +01:00
// This part is for const std::vector<>&.
2019-03-04 15:00:38 +01:00
%typemap(cstype) const std::vector<TYPE>& %{ CSHARPTYPE[] %}
%typemap(csin) const std::vector<TYPE>& %{ $csinput.Length, $csinput %}
%typemap(imtype, out="global::System.IntPtr") const std::vector<TYPE>& %{ int length$argnum, CSHARPTYPE[] %}
%typemap(ctype, out="void*") const std::vector<TYPE>& %{ int length$argnum, CTYPE* %}
%typemap(in) const std::vector<TYPE>& %{
dotnet: Remove reference to dotnet release command - Currently not implemented... Add abseil patch - Add patches/absl-config.cmake Makefile: Add abseil-cpp on unix - Force abseil-cpp SHA1 to 45221cc note: Just before the PR #136 which break all CMake Makefile: Add abseil-cpp on windows - Force abseil-cpp SHA1 to 45221cc note: Just before the PR #136 which break all CMake CMake: Add abseil-cpp - Force abseil-cpp SHA1 to 45221cc note: Just before the PR #136 which break all CMake port to absl: C++ Part - Fix warning with the use of ABSL_MUST_USE_RESULT > The macro must appear as the very first part of a function declaration or definition: ... Note: past advice was to place the macro after the argument list. src: dependencies/sources/abseil-cpp-master/absl/base/attributes.h:418 - Rename enum after windows clash - Remove non compact table constraints - Change index type from int64 to int in routing library - Fix file_nonport compilation on windows - Fix another naming conflict with windows (NO_ERROR is a macro) - Cleanup hash containers; work on sat internals - Add optional_boolean sub-proto Sync cpp examples with internal code - reenable issue173 after reducing number of loops port to absl: Python Part - Add back cp_model.INT32_MIN|MAX for examples Update Python examples - Add random_tsp.py - Run words_square example - Run magic_square in python tests port to absl: Java Part - Fix compilation of the new routing parameters in java - Protect some code from SWIG parsing Update Java Examples port to absl: .Net Part Update .Net examples work on sat internals; Add C++ CP-SAT CpModelBuilder API; update sample code and recipes to use the new API; sync with internal code Remove VS 2015 in Appveyor-CI - abseil-cpp does not support VS 2015... improve tables upgrade C++ sat examples to use the new API; work on sat internals update license dates rewrite jobshop_ft06_distance.py to use the CP-SAT solver rename last example revert last commit more work on SAT internals fix
2018-10-31 16:18:18 +01:00
$1 = new std::vector<TYPE>;
$1->reserve(length$argnum);
for(int i = 0; i < length$argnum; ++i) {
$1->emplace_back($input[i]);
}
%}
2019-03-04 15:00:38 +01:00
%typemap(freearg) const std::vector<TYPE>& { delete $1; }
%typemap(out) const std::vector<TYPE>& %{
$result = new std::vector< CTYPE >((const std::vector< CTYPE> &)*$1);
%}
%typemap(csout, excode=SWIGEXCODE) const std::vector<TYPE>& {
global::System.IntPtr cPtr = $imcall;$excode
ARRAYTYPE tmpVector = null;
if (cPtr != global::System.IntPtr.Zero) {
tmpVector = new ARRAYTYPE(cPtr, true);
CSHARPTYPE[] outArray = new CSHARPTYPE[tmpVector.Count];
tmpVector.CopyTo(outArray);
return outArray;
}
return null;
}
2019-03-13 13:50:23 +01:00
// Now, we do it for std::vector<>.
2019-03-04 15:00:38 +01:00
%typemap(cstype) std::vector<TYPE> %{ CSHARPTYPE[] %}
%typemap(csin) std::vector<TYPE> %{ $csinput.Length, $csinput %}
%typemap(imtype, out="global::System.IntPtr") std::vector<TYPE> %{ int length$argnum, CSHARPTYPE[] %}
%typemap(ctype, out="void*") std::vector<TYPE> %{ int length$argnum, CTYPE* %}
2019-01-17 13:14:55 +01:00
%typemap(in) std::vector<TYPE> %{
$1.clear();
$1.reserve(length$argnum);
for(int i = 0; i < length$argnum; ++i) {
$1.emplace_back($input[i]);
}
%}
%typemap(out) std::vector<TYPE> %{
$result = new std::vector< CTYPE >((const std::vector< CTYPE> &)$1);
%}
%typemap(csout, excode=SWIGEXCODE) std::vector<TYPE> {
global::System.IntPtr cPtr = $imcall;$excode
ARRAYTYPE tmpVector = null;
if (cPtr != global::System.IntPtr.Zero) {
tmpVector = new ARRAYTYPE(cPtr, true);
CSHARPTYPE[] outArray = new CSHARPTYPE[tmpVector.Count];
tmpVector.CopyTo(outArray);
return outArray;
}
return null;
}
dotnet: Remove reference to dotnet release command - Currently not implemented... Add abseil patch - Add patches/absl-config.cmake Makefile: Add abseil-cpp on unix - Force abseil-cpp SHA1 to 45221cc note: Just before the PR #136 which break all CMake Makefile: Add abseil-cpp on windows - Force abseil-cpp SHA1 to 45221cc note: Just before the PR #136 which break all CMake CMake: Add abseil-cpp - Force abseil-cpp SHA1 to 45221cc note: Just before the PR #136 which break all CMake port to absl: C++ Part - Fix warning with the use of ABSL_MUST_USE_RESULT > The macro must appear as the very first part of a function declaration or definition: ... Note: past advice was to place the macro after the argument list. src: dependencies/sources/abseil-cpp-master/absl/base/attributes.h:418 - Rename enum after windows clash - Remove non compact table constraints - Change index type from int64 to int in routing library - Fix file_nonport compilation on windows - Fix another naming conflict with windows (NO_ERROR is a macro) - Cleanup hash containers; work on sat internals - Add optional_boolean sub-proto Sync cpp examples with internal code - reenable issue173 after reducing number of loops port to absl: Python Part - Add back cp_model.INT32_MIN|MAX for examples Update Python examples - Add random_tsp.py - Run words_square example - Run magic_square in python tests port to absl: Java Part - Fix compilation of the new routing parameters in java - Protect some code from SWIG parsing Update Java Examples port to absl: .Net Part Update .Net examples work on sat internals; Add C++ CP-SAT CpModelBuilder API; update sample code and recipes to use the new API; sync with internal code Remove VS 2015 in Appveyor-CI - abseil-cpp does not support VS 2015... improve tables upgrade C++ sat examples to use the new API; work on sat internals update license dates rewrite jobshop_ft06_distance.py to use the CP-SAT solver rename last example revert last commit more work on SAT internals fix
2018-10-31 16:18:18 +01:00
%enddef // VECTOR_AS_CSHARP_ARRAY
// Typemaps to represent arguments of types:
// - "const std::vector<std::vector<TYPE> >&" or
// - "std::vector<std::vector<TYPE> >*" or
// - "std::vector<std::vector<TYPE> >" or
// as CSHARPTYPE[][].
2019-03-13 13:50:23 +01:00
// note: TYPE must be a primitive data type (PDT).
%define JAGGED_MATRIX_AS_CSHARP_ARRAY(TYPE, CTYPE, CSHARPTYPE, ARRAYTYPE)
// This part is for const std::vector<std::vector<TYPE> >&.
2019-03-04 15:01:29 +01:00
%typemap(cstype) const std::vector<std::vector<TYPE> >& %{ CSHARPTYPE[][] %}
%typemap(csin) const std::vector<std::vector<TYPE> >& %{
$csinput.GetLength(0),
NestedArrayHelper.GetArraySecondSize($csinput),
NestedArrayHelper.GetFlatArray($csinput)
dotnet: Remove reference to dotnet release command - Currently not implemented... Add abseil patch - Add patches/absl-config.cmake Makefile: Add abseil-cpp on unix - Force abseil-cpp SHA1 to 45221cc note: Just before the PR #136 which break all CMake Makefile: Add abseil-cpp on windows - Force abseil-cpp SHA1 to 45221cc note: Just before the PR #136 which break all CMake CMake: Add abseil-cpp - Force abseil-cpp SHA1 to 45221cc note: Just before the PR #136 which break all CMake port to absl: C++ Part - Fix warning with the use of ABSL_MUST_USE_RESULT > The macro must appear as the very first part of a function declaration or definition: ... Note: past advice was to place the macro after the argument list. src: dependencies/sources/abseil-cpp-master/absl/base/attributes.h:418 - Rename enum after windows clash - Remove non compact table constraints - Change index type from int64 to int in routing library - Fix file_nonport compilation on windows - Fix another naming conflict with windows (NO_ERROR is a macro) - Cleanup hash containers; work on sat internals - Add optional_boolean sub-proto Sync cpp examples with internal code - reenable issue173 after reducing number of loops port to absl: Python Part - Add back cp_model.INT32_MIN|MAX for examples Update Python examples - Add random_tsp.py - Run words_square example - Run magic_square in python tests port to absl: Java Part - Fix compilation of the new routing parameters in java - Protect some code from SWIG parsing Update Java Examples port to absl: .Net Part Update .Net examples work on sat internals; Add C++ CP-SAT CpModelBuilder API; update sample code and recipes to use the new API; sync with internal code Remove VS 2015 in Appveyor-CI - abseil-cpp does not support VS 2015... improve tables upgrade C++ sat examples to use the new API; work on sat internals update license dates rewrite jobshop_ft06_distance.py to use the CP-SAT solver rename last example revert last commit more work on SAT internals fix
2018-10-31 16:18:18 +01:00
%}
2019-03-04 15:01:29 +01:00
%typemap(imtype, out="global::System.IntPtr") const std::vector<std::vector<TYPE> >& %{
int len$argnum##_1, int[] len$argnum##_2, CSHARPTYPE[]
dotnet: Remove reference to dotnet release command - Currently not implemented... Add abseil patch - Add patches/absl-config.cmake Makefile: Add abseil-cpp on unix - Force abseil-cpp SHA1 to 45221cc note: Just before the PR #136 which break all CMake Makefile: Add abseil-cpp on windows - Force abseil-cpp SHA1 to 45221cc note: Just before the PR #136 which break all CMake CMake: Add abseil-cpp - Force abseil-cpp SHA1 to 45221cc note: Just before the PR #136 which break all CMake port to absl: C++ Part - Fix warning with the use of ABSL_MUST_USE_RESULT > The macro must appear as the very first part of a function declaration or definition: ... Note: past advice was to place the macro after the argument list. src: dependencies/sources/abseil-cpp-master/absl/base/attributes.h:418 - Rename enum after windows clash - Remove non compact table constraints - Change index type from int64 to int in routing library - Fix file_nonport compilation on windows - Fix another naming conflict with windows (NO_ERROR is a macro) - Cleanup hash containers; work on sat internals - Add optional_boolean sub-proto Sync cpp examples with internal code - reenable issue173 after reducing number of loops port to absl: Python Part - Add back cp_model.INT32_MIN|MAX for examples Update Python examples - Add random_tsp.py - Run words_square example - Run magic_square in python tests port to absl: Java Part - Fix compilation of the new routing parameters in java - Protect some code from SWIG parsing Update Java Examples port to absl: .Net Part Update .Net examples work on sat internals; Add C++ CP-SAT CpModelBuilder API; update sample code and recipes to use the new API; sync with internal code Remove VS 2015 in Appveyor-CI - abseil-cpp does not support VS 2015... improve tables upgrade C++ sat examples to use the new API; work on sat internals update license dates rewrite jobshop_ft06_distance.py to use the CP-SAT solver rename last example revert last commit more work on SAT internals fix
2018-10-31 16:18:18 +01:00
%}
2019-03-04 15:01:29 +01:00
%typemap(ctype, out="void*") const std::vector<std::vector<TYPE> >& %{
int len$argnum##_1, int len$argnum##_2[], CTYPE*
%}
%typemap(in) const std::vector<std::vector<TYPE> >& (std::vector<std::vector<TYPE> > result) %{
dotnet: Remove reference to dotnet release command - Currently not implemented... Add abseil patch - Add patches/absl-config.cmake Makefile: Add abseil-cpp on unix - Force abseil-cpp SHA1 to 45221cc note: Just before the PR #136 which break all CMake Makefile: Add abseil-cpp on windows - Force abseil-cpp SHA1 to 45221cc note: Just before the PR #136 which break all CMake CMake: Add abseil-cpp - Force abseil-cpp SHA1 to 45221cc note: Just before the PR #136 which break all CMake port to absl: C++ Part - Fix warning with the use of ABSL_MUST_USE_RESULT > The macro must appear as the very first part of a function declaration or definition: ... Note: past advice was to place the macro after the argument list. src: dependencies/sources/abseil-cpp-master/absl/base/attributes.h:418 - Rename enum after windows clash - Remove non compact table constraints - Change index type from int64 to int in routing library - Fix file_nonport compilation on windows - Fix another naming conflict with windows (NO_ERROR is a macro) - Cleanup hash containers; work on sat internals - Add optional_boolean sub-proto Sync cpp examples with internal code - reenable issue173 after reducing number of loops port to absl: Python Part - Add back cp_model.INT32_MIN|MAX for examples Update Python examples - Add random_tsp.py - Run words_square example - Run magic_square in python tests port to absl: Java Part - Fix compilation of the new routing parameters in java - Protect some code from SWIG parsing Update Java Examples port to absl: .Net Part Update .Net examples work on sat internals; Add C++ CP-SAT CpModelBuilder API; update sample code and recipes to use the new API; sync with internal code Remove VS 2015 in Appveyor-CI - abseil-cpp does not support VS 2015... improve tables upgrade C++ sat examples to use the new API; work on sat internals update license dates rewrite jobshop_ft06_distance.py to use the CP-SAT solver rename last example revert last commit more work on SAT internals fix
2018-10-31 16:18:18 +01:00
result.clear();
2019-03-04 15:01:29 +01:00
result.resize(len$argnum##_1);
dotnet: Remove reference to dotnet release command - Currently not implemented... Add abseil patch - Add patches/absl-config.cmake Makefile: Add abseil-cpp on unix - Force abseil-cpp SHA1 to 45221cc note: Just before the PR #136 which break all CMake Makefile: Add abseil-cpp on windows - Force abseil-cpp SHA1 to 45221cc note: Just before the PR #136 which break all CMake CMake: Add abseil-cpp - Force abseil-cpp SHA1 to 45221cc note: Just before the PR #136 which break all CMake port to absl: C++ Part - Fix warning with the use of ABSL_MUST_USE_RESULT > The macro must appear as the very first part of a function declaration or definition: ... Note: past advice was to place the macro after the argument list. src: dependencies/sources/abseil-cpp-master/absl/base/attributes.h:418 - Rename enum after windows clash - Remove non compact table constraints - Change index type from int64 to int in routing library - Fix file_nonport compilation on windows - Fix another naming conflict with windows (NO_ERROR is a macro) - Cleanup hash containers; work on sat internals - Add optional_boolean sub-proto Sync cpp examples with internal code - reenable issue173 after reducing number of loops port to absl: Python Part - Add back cp_model.INT32_MIN|MAX for examples Update Python examples - Add random_tsp.py - Run words_square example - Run magic_square in python tests port to absl: Java Part - Fix compilation of the new routing parameters in java - Protect some code from SWIG parsing Update Java Examples port to absl: .Net Part Update .Net examples work on sat internals; Add C++ CP-SAT CpModelBuilder API; update sample code and recipes to use the new API; sync with internal code Remove VS 2015 in Appveyor-CI - abseil-cpp does not support VS 2015... improve tables upgrade C++ sat examples to use the new API; work on sat internals update license dates rewrite jobshop_ft06_distance.py to use the CP-SAT solver rename last example revert last commit more work on SAT internals fix
2018-10-31 16:18:18 +01:00
TYPE* inner_array = reinterpret_cast<TYPE*>($input);
int actualIndex = 0;
2019-03-04 15:01:29 +01:00
for (int index1 = 0; index1 < len$argnum##_1; ++index1) {
result[index1].reserve(len$argnum##_2[index1]);
for (int index2 = 0; index2 < len$argnum##_2[index1]; ++index2) {
dotnet: Remove reference to dotnet release command - Currently not implemented... Add abseil patch - Add patches/absl-config.cmake Makefile: Add abseil-cpp on unix - Force abseil-cpp SHA1 to 45221cc note: Just before the PR #136 which break all CMake Makefile: Add abseil-cpp on windows - Force abseil-cpp SHA1 to 45221cc note: Just before the PR #136 which break all CMake CMake: Add abseil-cpp - Force abseil-cpp SHA1 to 45221cc note: Just before the PR #136 which break all CMake port to absl: C++ Part - Fix warning with the use of ABSL_MUST_USE_RESULT > The macro must appear as the very first part of a function declaration or definition: ... Note: past advice was to place the macro after the argument list. src: dependencies/sources/abseil-cpp-master/absl/base/attributes.h:418 - Rename enum after windows clash - Remove non compact table constraints - Change index type from int64 to int in routing library - Fix file_nonport compilation on windows - Fix another naming conflict with windows (NO_ERROR is a macro) - Cleanup hash containers; work on sat internals - Add optional_boolean sub-proto Sync cpp examples with internal code - reenable issue173 after reducing number of loops port to absl: Python Part - Add back cp_model.INT32_MIN|MAX for examples Update Python examples - Add random_tsp.py - Run words_square example - Run magic_square in python tests port to absl: Java Part - Fix compilation of the new routing parameters in java - Protect some code from SWIG parsing Update Java Examples port to absl: .Net Part Update .Net examples work on sat internals; Add C++ CP-SAT CpModelBuilder API; update sample code and recipes to use the new API; sync with internal code Remove VS 2015 in Appveyor-CI - abseil-cpp does not support VS 2015... improve tables upgrade C++ sat examples to use the new API; work on sat internals update license dates rewrite jobshop_ft06_distance.py to use the CP-SAT solver rename last example revert last commit more work on SAT internals fix
2018-10-31 16:18:18 +01:00
const TYPE value = inner_array[actualIndex];
result[index1].emplace_back(value);
actualIndex++;
}
}
$1 = &result;
%}
// Now, we do it for std::vector<std::vector<TYPE> >*.
2019-03-04 15:01:29 +01:00
%typemap(cstype) std::vector<std::vector<TYPE> >* %{ CSHARPTYPE[][] %}
%typemap(csin) std::vector<std::vector<TYPE> >* %{
$csinput.GetLength(0),
NestedArrayHelper.GetArraySecondSize($csinput),
NestedArrayHelper.GetFlatArray($csinput)
%}
%typemap(imtype, out="global::System.IntPtr") std::vector<std::vector<TYPE> >* %{
int len$argnum##_1, int[] len$argnum##_2, CSHARPTYPE[]
%}
%typemap(ctype, out="void*") std::vector<std::vector<TYPE> >* %{
int len$argnum##_1, int len$argnum##_2[], CTYPE*
%}
%typemap(in) std::vector<std::vector<TYPE> >* (std::vector<std::vector<TYPE> > result) %{
result.clear();
result.resize(len$argnum##_1);
TYPE* flat_array = reinterpret_cast<TYPE*>($input);
int actualIndex = 0;
for (int index1 = 0; index1 < len$argnum##_1; ++index1) {
result[index1].reserve(len$argnum##_2[index1]);
for (int index2 = 0; index2 < len$argnum##_2[index1]; ++index2) {
const TYPE value = flat_array[actualIndex];
result[index1].emplace_back(value);
actualIndex++;
}
}
$1 = &result;
%}
// Now, we do it for std::vector<std::vector<TYPE> >.
%typemap(cstype) std::vector<std::vector<TYPE> > %{ CSHARPTYPE[][] %}
%typemap(csin) std::vector<std::vector<TYPE> > %{
$csinput.GetLength(0),
NestedArrayHelper.GetArraySecondSize($csinput),
NestedArrayHelper.GetFlatArray($csinput)
%}
%typemap(imtype, out="global::System.IntPtr") std::vector<std::vector<TYPE> > %{
int len$argnum##_1, int[] len$argnum##_2, CSHARPTYPE[]
%}
%typemap(ctype, out="void*") std::vector<std::vector<TYPE> > %{
int len$argnum##_1, int len$argnum##_2[], CTYPE*
%}
%typemap(in) std::vector<std::vector<TYPE> > %{
$1.clear();
$1.resize(len$argnum##_1);
TYPE* inner_array = reinterpret_cast<TYPE*>($input);
int actualIndex = 0;
for (int index1 = 0; index1 < len$argnum##_1; ++index1) {
$1[index1].reserve(len$argnum##_2[index1]);
for (int index2 = 0; index2 < len$argnum##_2[index1]; ++index2) {
const TYPE value = inner_array[actualIndex];
$1[index1].emplace_back(value);
actualIndex++;
}
}
%}
%enddef // JAGGED_MATRIX_AS_CSHARP_ARRAY
2019-03-04 15:01:29 +01:00
// Typemaps to represent arguments of types:
// - "const std::vector<std::vector<TYPE> >&" or
// - "std::vector<std::vector<TYPE> >*" or
// as CSHARPTYPE[,].
// note: TYPE must be a primitive data type (PDT).
%define REGULAR_MATRIX_AS_CSHARP_ARRAY(TYPE, CTYPE, CSHARPTYPE, ARRAYTYPE)
// This part is for const std::vector<std::vector<>>&.
%typemap(cstype) const std::vector<std::vector<TYPE> >& %{ CSHARPTYPE[,] %}
%typemap(csin) const std::vector<std::vector<TYPE> >& %{
$csinput.GetLength(0),
$csinput.GetLength(1),
NestedArrayHelper.GetFlatArrayFromMatrix($csinput)
%}
%typemap(imtype, out="global::System.IntPtr") const std::vector<std::vector<TYPE> >& %{
int len$argnum##_1, int len$argnum##_2, CSHARPTYPE[]
%}
%typemap(ctype, out="void*") const std::vector<std::vector<TYPE> >& %{
int len$argnum##_1, int len$argnum##_2, CTYPE*
%}
%typemap(in) const std::vector<std::vector<TYPE> >& (std::vector<std::vector<TYPE> > result) %{
result.clear();
result.resize(len$argnum##_1);
TYPE* inner_array = reinterpret_cast<TYPE*>($input);
int actualIndex = 0;
for (int index1 = 0; index1 < len$argnum##_1; ++index1) {
result[index1].reserve(len$argnum##_2);
for (int index2 = 0; index2 < len$argnum##_2; ++index2) {
const TYPE value = inner_array[actualIndex];
result[index1].emplace_back(value);
actualIndex++;
}
}
$1 = &result;
%}
// Now, we do it for std::vector<std::vector<>>*.
%typemap(cstype) std::vector<std::vector<TYPE> >* %{ CSHARPTYPE[,] %}
%typemap(csin) std::vector<std::vector<TYPE> >* %{
$csinput.GetLength(0),
$csinput.GetLength(1),
NestedArrayHelper.GetFlatArrayFromMatrix($csinput)
%}
%typemap(imtype, out="global::System.IntPtr") std::vector<std::vector<TYPE> >* %{
int len$argnum##_1, int len$argnum##_2, CSHARPTYPE[]
%}
%typemap(ctype, out="void*") std::vector<std::vector<TYPE> >* %{
int len$argnum##_1, int len$argnum##_2, CTYPE*
%}
%typemap(in) std::vector<std::vector<TYPE> >* (std::vector<std::vector<TYPE> > result) %{
result.clear();
result.resize(len$argnum##_1);
TYPE* flat_array = reinterpret_cast<TYPE*>($input);
int actualIndex = 0;
for (int index1 = 0; index1 < len$argnum##_1; ++index1) {
result[index1].reserve(len$argnum##_2);
for (int index2 = 0; index2 < len$argnum##_2; ++index2) {
const TYPE value = flat_array[actualIndex];
result[index1].emplace_back(value);
actualIndex++;
}
}
$1 = &result;
%}
%enddef // REGULAR_MATRIX_AS_CSHARP_ARRAY
2020-02-14 10:26:40 +01:00
// SWIG Macros to use std::vector<Type> and const std::vector<Type>& in .Net as
// regular .Net array, where Type is an integral numeric type.
// see: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/integral-numeric-types
// By default vector<vector<Type>> is mapped to a jagged array i.e. .Net type[][]
// If you want a regular matrix i.e. .Net type[,] use REGULAR_MATRIX_AS_CSHARP_ARRAY instead.
%include "std_vector.i"
%template(IntVector) std::vector<int>;
%template(IntVectorVector) std::vector<std::vector<int> >;
VECTOR_AS_CSHARP_ARRAY(int, int, int, IntVector);
JAGGED_MATRIX_AS_CSHARP_ARRAY(int, int, int, IntVectorVector);
//REGULAR_MATRIX_AS_CSHARP_ARRAY(int, int, int, IntVectorVector);
2021-04-01 12:13:35 +02:00
%template(Int64Vector) std::vector<int64_t>;
%template(Int64VectorVector) std::vector<std::vector<int64_t> >;
VECTOR_AS_CSHARP_ARRAY(int64_t, int64_t, long, Int64Vector);
JAGGED_MATRIX_AS_CSHARP_ARRAY(int64_t, int64_t, long, Int64VectorVector);
//REGULAR_MATRIX_AS_CSHARP_ARRAY(int64_t, int64_t, long, Int64VectorVector);