From dbd7b64656e7b7ac2163aed85953076301baf2f2 Mon Sep 17 00:00:00 2001 From: Corentin Le Molgat Date: Fri, 15 Mar 2024 11:43:39 +0100 Subject: [PATCH] routing: Fix Java enum proto --- ortools/constraint_solver/java/routing.i | 5 +---- ortools/util/java/proto.i | 23 ++++++++++++++++++++--- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/ortools/constraint_solver/java/routing.i b/ortools/constraint_solver/java/routing.i index 4d8bc3137e..ac5ad6dc5c 100644 --- a/ortools/constraint_solver/java/routing.i +++ b/ortools/constraint_solver/java/routing.i @@ -29,10 +29,7 @@ namespace operations_research { class RoutingModelParameters; class RoutingSearchParameters; -struct RoutingSearchStatus { - enum Value {}; -}; - +class RoutingSearchStatus; } // namespace operations_research // Include the files we want to wrap a first time. diff --git a/ortools/util/java/proto.i b/ortools/util/java/proto.i index e7ece58490..f686846aba 100644 --- a/ortools/util/java/proto.i +++ b/ortools/util/java/proto.i @@ -23,9 +23,7 @@ // if the C++ function returns a protocol message: // MyProto* foo(); // Use PROTO2_RETURN macro: -// PROTO2_RETURN(MyProto, com.google.proto.protos.test.MyProto, giveOwnership) -// -> the 'giveOwnership' parameter should be true iff the C++ function -// returns a new proto which should be deleted by the client. +// PROTO2_RETURN(MyProto, com.google.proto.protos.test.MyProto) // // Passing each protocol message from Java to C++ by value. Each ProtocolMessage // is serialized into byte[] when it is passed from Java to C++, the C++ code @@ -90,3 +88,22 @@ jenv->SetByteArrayRegion($result, 0, size, buf.get()); } %enddef // PROTO2_RETURN + +// SWIG Macro for mapping protocol message enum type. +// @param CppEnumProto the C++ protocol message enum type +// @param JavaEnumProto the corresponding Java protocol message enum type +%define PROTO_ENUM_RETURN(CppEnumProto, JavaEnumProto) +%typemap(jni) CppEnumProto "jint" +%typemap(jtype) CppEnumProto "int" +%typemap(jstype) CppEnumProto "JavaEnumProto" + +// From CppEnumProto to jni (in wrap.cxx code) +%typemap(out) CppEnumProto %{ $result = $1; %} + +// From jtype to jstype (in .java code) +%typemap(javaout) CppEnumProto { + return JavaEnumProto.forNumber($jnicall); +} + +%enddef // end PROTO_ENUM_RETURN +