OR-Tools  9.2
sat_java_wrap.cc
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2  * This file was automatically generated by SWIG (http://www.swig.org).
3  * Version 4.0.1
4  *
5  * This file is not intended to be easily readable and contains a number of
6  * coding conventions designed to improve portability and efficiency. Do not make
7  * changes to this file unless you know what you are doing--modify the SWIG
8  * interface file instead.
9  * ----------------------------------------------------------------------------- */
10 
11 
12 #ifndef SWIGJAVA
13 #define SWIGJAVA
14 #endif
15 
16 #define SWIG_DIRECTORS
17 
18 
19 #ifdef __cplusplus
20 /* SwigValueWrapper is described in swig.swg */
21 template<typename T> class SwigValueWrapper {
22  struct SwigMovePointer {
23  T *ptr;
24  SwigMovePointer(T *p) : ptr(p) { }
25  ~SwigMovePointer() { delete ptr; }
26  SwigMovePointer& operator=(SwigMovePointer& rhs) { T* oldptr = ptr; ptr = 0; delete oldptr; ptr = rhs.ptr; rhs.ptr = 0; return *this; }
27  } pointer;
28  SwigValueWrapper& operator=(const SwigValueWrapper<T>& rhs);
29  SwigValueWrapper(const SwigValueWrapper<T>& rhs);
30 public:
31  SwigValueWrapper() : pointer(0) { }
32  SwigValueWrapper& operator=(const T& t) { SwigMovePointer tmp(new T(t)); pointer = tmp; return *this; }
33  operator T&() const { return *pointer.ptr; }
34  T *operator&() { return pointer.ptr; }
35 };
36 
37 template <typename T> T SwigValueInit() {
38  return T();
39 }
40 #endif
41 
42 /* -----------------------------------------------------------------------------
43  * This section contains generic SWIG labels for method/variable
44  * declarations/attributes, and other compiler dependent labels.
45  * ----------------------------------------------------------------------------- */
46 
47 /* template workaround for compilers that cannot correctly implement the C++ standard */
48 #ifndef SWIGTEMPLATEDISAMBIGUATOR
49 # if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x560)
50 # define SWIGTEMPLATEDISAMBIGUATOR template
51 # elif defined(__HP_aCC)
52 /* Needed even with `aCC -AA' when `aCC -V' reports HP ANSI C++ B3910B A.03.55 */
53 /* If we find a maximum version that requires this, the test would be __HP_aCC <= 35500 for A.03.55 */
54 # define SWIGTEMPLATEDISAMBIGUATOR template
55 # else
56 # define SWIGTEMPLATEDISAMBIGUATOR
57 # endif
58 #endif
59 
60 /* inline attribute */
61 #ifndef SWIGINLINE
62 # if defined(__cplusplus) || (defined(__GNUC__) && !defined(__STRICT_ANSI__))
63 # define SWIGINLINE inline
64 # else
65 # define SWIGINLINE
66 # endif
67 #endif
68 
69 /* attribute recognised by some compilers to avoid 'unused' warnings */
70 #ifndef SWIGUNUSED
71 # if defined(__GNUC__)
72 # if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
73 # define SWIGUNUSED __attribute__ ((__unused__))
74 # else
75 # define SWIGUNUSED
76 # endif
77 # elif defined(__ICC)
78 # define SWIGUNUSED __attribute__ ((__unused__))
79 # else
80 # define SWIGUNUSED
81 # endif
82 #endif
83 
84 #ifndef SWIG_MSC_UNSUPPRESS_4505
85 # if defined(_MSC_VER)
86 # pragma warning(disable : 4505) /* unreferenced local function has been removed */
87 # endif
88 #endif
89 
90 #ifndef SWIGUNUSEDPARM
91 # ifdef __cplusplus
92 # define SWIGUNUSEDPARM(p)
93 # else
94 # define SWIGUNUSEDPARM(p) p SWIGUNUSED
95 # endif
96 #endif
97 
98 /* internal SWIG method */
99 #ifndef SWIGINTERN
100 # define SWIGINTERN static SWIGUNUSED
101 #endif
102 
103 /* internal inline SWIG method */
104 #ifndef SWIGINTERNINLINE
105 # define SWIGINTERNINLINE SWIGINTERN SWIGINLINE
106 #endif
107 
108 /* exporting methods */
109 #if defined(__GNUC__)
110 # if (__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
111 # ifndef GCC_HASCLASSVISIBILITY
112 # define GCC_HASCLASSVISIBILITY
113 # endif
114 # endif
115 #endif
116 
117 #ifndef SWIGEXPORT
118 # if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
119 # if defined(STATIC_LINKED)
120 # define SWIGEXPORT
121 # else
122 # define SWIGEXPORT __declspec(dllexport)
123 # endif
124 # else
125 # if defined(__GNUC__) && defined(GCC_HASCLASSVISIBILITY)
126 # define SWIGEXPORT __attribute__ ((visibility("default")))
127 # else
128 # define SWIGEXPORT
129 # endif
130 # endif
131 #endif
132 
133 /* calling conventions for Windows */
134 #ifndef SWIGSTDCALL
135 # if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
136 # define SWIGSTDCALL __stdcall
137 # else
138 # define SWIGSTDCALL
139 # endif
140 #endif
141 
142 /* Deal with Microsoft's attempt at deprecating C standard runtime functions */
143 #if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE)
144 # define _CRT_SECURE_NO_DEPRECATE
145 #endif
146 
147 /* Deal with Microsoft's attempt at deprecating methods in the standard C++ library */
148 #if !defined(SWIG_NO_SCL_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_SCL_SECURE_NO_DEPRECATE)
149 # define _SCL_SECURE_NO_DEPRECATE
150 #endif
151 
152 /* Deal with Apple's deprecated 'AssertMacros.h' from Carbon-framework */
153 #if defined(__APPLE__) && !defined(__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES)
154 # define __ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES 0
155 #endif
156 
157 /* Intel's compiler complains if a variable which was never initialised is
158  * cast to void, which is a common idiom which we use to indicate that we
159  * are aware a variable isn't used. So we just silence that warning.
160  * See: https://github.com/swig/swig/issues/192 for more discussion.
161  */
162 #ifdef __INTEL_COMPILER
163 # pragma warning disable 592
164 #endif
165 
166 
167 /* Fix for jlong on some versions of gcc on Windows */
168 #if defined(__GNUC__) && !defined(__INTEL_COMPILER)
169  typedef long long __int64;
170 #endif
171 
172 /* Fix for jlong on 64-bit x86 Solaris */
173 #if defined(__x86_64)
174 # ifdef _LP64
175 # undef _LP64
176 # endif
177 #endif
178 
179 #include <jni.h>
180 #include <stdlib.h>
181 #include <string.h>
182 
183 
184 /* Support for throwing Java exceptions */
185 typedef enum {
197 
198 typedef struct {
200  const char *java_exception;
202 
203 
204 static void SWIGUNUSED SWIG_JavaThrowException(JNIEnv *jenv, SWIG_JavaExceptionCodes code, const char *msg) {
205  jclass excep;
206  static const SWIG_JavaExceptions_t java_exceptions[] = {
207  { SWIG_JavaOutOfMemoryError, "java/lang/OutOfMemoryError" },
208  { SWIG_JavaIOException, "java/io/IOException" },
209  { SWIG_JavaRuntimeException, "java/lang/RuntimeException" },
210  { SWIG_JavaIndexOutOfBoundsException, "java/lang/IndexOutOfBoundsException" },
211  { SWIG_JavaArithmeticException, "java/lang/ArithmeticException" },
212  { SWIG_JavaIllegalArgumentException, "java/lang/IllegalArgumentException" },
213  { SWIG_JavaNullPointerException, "java/lang/NullPointerException" },
214  { SWIG_JavaDirectorPureVirtual, "java/lang/RuntimeException" },
215  { SWIG_JavaUnknownError, "java/lang/UnknownError" },
216  { SWIG_JavaIllegalStateException, "java/lang/IllegalStateException" },
217  { (SWIG_JavaExceptionCodes)0, "java/lang/UnknownError" }
218  };
219  const SWIG_JavaExceptions_t *except_ptr = java_exceptions;
220 
221  while (except_ptr->code != code && except_ptr->code)
222  except_ptr++;
223 
224  jenv->ExceptionClear();
225  excep = jenv->FindClass(except_ptr->java_exception);
226  if (excep)
227  jenv->ThrowNew(excep, msg);
228 }
229 
230 
231 /* Contract support */
232 
233 #define SWIG_contract_assert(nullreturn, expr, msg) if (!(expr)) {SWIG_JavaThrowException(jenv, SWIG_JavaIllegalArgumentException, msg); return nullreturn; } else
234 
235 /* -----------------------------------------------------------------------------
236  * director_common.swg
237  *
238  * This file contains support for director classes which is common between
239  * languages.
240  * ----------------------------------------------------------------------------- */
241 
242 /*
243  Use -DSWIG_DIRECTOR_STATIC if you prefer to avoid the use of the
244  'Swig' namespace. This could be useful for multi-modules projects.
245 */
246 #ifdef SWIG_DIRECTOR_STATIC
247 /* Force anonymous (static) namespace */
248 #define Swig
249 #endif
250 /* -----------------------------------------------------------------------------
251  * director.swg
252  *
253  * This file contains support for director classes so that Java proxy
254  * methods can be called from C++.
255  * ----------------------------------------------------------------------------- */
256 
257 #if defined(DEBUG_DIRECTOR_OWNED) || defined(DEBUG_DIRECTOR_EXCEPTION) || defined(DEBUG_DIRECTOR_THREAD_NAME)
258 #include <iostream>
259 #endif
260 
261 #include <exception>
262 
263 #if defined(SWIG_JAVA_USE_THREAD_NAME)
264 
265 #if !defined(SWIG_JAVA_GET_THREAD_NAME)
266 namespace Swig {
267  SWIGINTERN int GetThreadName(char *name, size_t len);
268 }
269 
270 #if defined(__linux__)
271 
272 #include <sys/prctl.h>
273 SWIGINTERN int Swig::GetThreadName(char *name, size_t len) {
274  (void)len;
275 #if defined(PR_GET_NAME)
276  return prctl(PR_GET_NAME, (unsigned long)name, 0, 0, 0);
277 #else
278  (void)name;
279  return 1;
280 #endif
281 }
282 
283 #elif defined(__unix__) || defined(__APPLE__)
284 
285 #include <pthread.h>
286 SWIGINTERN int Swig::GetThreadName(char *name, size_t len) {
287  return pthread_getname_np(pthread_self(), name, len);
288 }
289 
290 #else
291 
292 SWIGINTERN int Swig::GetThreadName(char *name, size_t len) {
293  (void)len;
294  (void)name;
295  return 1;
296 }
297 #endif
298 
299 #endif
300 
301 #endif
302 
303 namespace Swig {
304 
305  /* Java object wrapper */
306  class JObjectWrapper {
307  public:
308  JObjectWrapper() : jthis_(NULL), weak_global_(true) {
309  }
310 
312  jthis_ = NULL;
313  weak_global_ = true;
314  }
315 
316  bool set(JNIEnv *jenv, jobject jobj, bool mem_own, bool weak_global) {
317  if (!jthis_) {
318  weak_global_ = weak_global || !mem_own; // hold as weak global if explicitly requested or not owned
319  if (jobj)
320  jthis_ = weak_global_ ? jenv->NewWeakGlobalRef(jobj) : jenv->NewGlobalRef(jobj);
321 #if defined(DEBUG_DIRECTOR_OWNED)
322  std::cout << "JObjectWrapper::set(" << jobj << ", " << (weak_global ? "weak_global" : "global_ref") << ") -> " << jthis_ << std::endl;
323 #endif
324  return true;
325  } else {
326 #if defined(DEBUG_DIRECTOR_OWNED)
327  std::cout << "JObjectWrapper::set(" << jobj << ", " << (weak_global ? "weak_global" : "global_ref") << ") -> already set" << std::endl;
328 #endif
329  return false;
330  }
331  }
332 
333  jobject get(JNIEnv *jenv) const {
334 #if defined(DEBUG_DIRECTOR_OWNED)
335  std::cout << "JObjectWrapper::get(";
336  if (jthis_)
337  std::cout << jthis_;
338  else
339  std::cout << "null";
340  std::cout << ") -> return new local ref" << std::endl;
341 #endif
342  return (jthis_ ? jenv->NewLocalRef(jthis_) : jthis_);
343  }
344 
345  void release(JNIEnv *jenv) {
346 #if defined(DEBUG_DIRECTOR_OWNED)
347  std::cout << "JObjectWrapper::release(" << jthis_ << "): " << (weak_global_ ? "weak global ref" : "global ref") << std::endl;
348 #endif
349  if (jthis_) {
350  if (weak_global_) {
351  if (jenv->IsSameObject(jthis_, NULL) == JNI_FALSE)
352  jenv->DeleteWeakGlobalRef((jweak)jthis_);
353  } else
354  jenv->DeleteGlobalRef(jthis_);
355  }
356 
357  jthis_ = NULL;
358  weak_global_ = true;
359  }
360 
361  /* Only call peek if you know what you are doing wrt to weak/global references */
362  jobject peek() {
363  return jthis_;
364  }
365 
366  /* Java proxy releases ownership of C++ object, C++ object is now
367  responsible for destruction (creates NewGlobalRef to pin Java proxy) */
368  void java_change_ownership(JNIEnv *jenv, jobject jself, bool take_or_release) {
369  if (take_or_release) { /* Java takes ownership of C++ object's lifetime. */
370  if (!weak_global_) {
371  jenv->DeleteGlobalRef(jthis_);
372  jthis_ = jenv->NewWeakGlobalRef(jself);
373  weak_global_ = true;
374  }
375  } else {
376  /* Java releases ownership of C++ object's lifetime */
377  if (weak_global_) {
378  jenv->DeleteWeakGlobalRef((jweak)jthis_);
379  jthis_ = jenv->NewGlobalRef(jself);
380  weak_global_ = false;
381  }
382  }
383  }
384 
385  private:
386  /* pointer to Java object */
387  jobject jthis_;
388  /* Local or global reference flag */
389  bool weak_global_;
390  };
391 
392  /* Local JNI reference deleter */
393  class LocalRefGuard {
394  JNIEnv *jenv_;
395  jobject jobj_;
396 
397  // non-copyable
398  LocalRefGuard(const LocalRefGuard &);
399  LocalRefGuard &operator=(const LocalRefGuard &);
400  public:
401  LocalRefGuard(JNIEnv *jenv, jobject jobj): jenv_(jenv), jobj_(jobj) {}
403  if (jobj_)
404  jenv_->DeleteLocalRef(jobj_);
405  }
406  };
407 
408  /* director base class */
409  class Director {
410  /* pointer to Java virtual machine */
411  JavaVM *swig_jvm_;
412 
413  protected:
414 #if defined (_MSC_VER) && (_MSC_VER<1300)
415  class JNIEnvWrapper;
416  friend class JNIEnvWrapper;
417 #endif
418  /* Utility class for managing the JNI environment */
419  class JNIEnvWrapper {
420  const Director *director_;
421  JNIEnv *jenv_;
422  int env_status;
423  public:
424  JNIEnvWrapper(const Director *director) : director_(director), jenv_(0), env_status(0) {
425 #if defined(__ANDROID__)
426  JNIEnv **jenv = &jenv_;
427 #else
428  void **jenv = (void **)&jenv_;
429 #endif
430  env_status = director_->swig_jvm_->GetEnv((void **)&jenv_, JNI_VERSION_1_2);
431  JavaVMAttachArgs args;
432  args.version = JNI_VERSION_1_2;
433  args.group = NULL;
434  args.name = NULL;
435 #if defined(SWIG_JAVA_USE_THREAD_NAME)
436  char thread_name[64]; // MAX_TASK_COMM_LEN=16 is hard-coded in the Linux kernel and MacOS has MAXTHREADNAMESIZE=64.
437  if (Swig::GetThreadName(thread_name, sizeof(thread_name)) == 0) {
438  args.name = thread_name;
439 #if defined(DEBUG_DIRECTOR_THREAD_NAME)
440  std::cout << "JNIEnvWrapper: thread name: " << thread_name << std::endl;
441  } else {
442  std::cout << "JNIEnvWrapper: Couldn't set Java thread name" << std::endl;
443 #endif
444  }
445 #endif
446 #if defined(SWIG_JAVA_ATTACH_CURRENT_THREAD_AS_DAEMON)
447  // Attach a daemon thread to the JVM. Useful when the JVM should not wait for
448  // the thread to exit upon shutdown. Only for jdk-1.4 and later.
449  director_->swig_jvm_->AttachCurrentThreadAsDaemon(jenv, &args);
450 #else
451  director_->swig_jvm_->AttachCurrentThread(jenv, &args);
452 #endif
453  }
455 #if !defined(SWIG_JAVA_NO_DETACH_CURRENT_THREAD)
456  // Some JVMs, eg jdk-1.4.2 and lower on Solaris have a bug and crash with the DetachCurrentThread call.
457  // However, without this call, the JVM hangs on exit when the thread was not created by the JVM and creates a memory leak.
458  if (env_status == JNI_EDETACHED)
459  director_->swig_jvm_->DetachCurrentThread();
460 #endif
461  }
462  JNIEnv *getJNIEnv() const {
463  return jenv_;
464  }
465  };
466 
467  /* Java object wrapper */
469 
470  /* Disconnect director from Java object */
471  void swig_disconnect_director_self(const char *disconn_method) {
472  JNIEnvWrapper jnienv(this) ;
473  JNIEnv *jenv = jnienv.getJNIEnv() ;
474  jobject jobj = swig_self_.get(jenv);
475  LocalRefGuard ref_deleter(jenv, jobj);
476 #if defined(DEBUG_DIRECTOR_OWNED)
477  std::cout << "Swig::Director::disconnect_director_self(" << jobj << ")" << std::endl;
478 #endif
479  if (jobj && jenv->IsSameObject(jobj, NULL) == JNI_FALSE) {
480  jmethodID disconn_meth = jenv->GetMethodID(jenv->GetObjectClass(jobj), disconn_method, "()V");
481  if (disconn_meth) {
482 #if defined(DEBUG_DIRECTOR_OWNED)
483  std::cout << "Swig::Director::disconnect_director_self upcall to " << disconn_method << std::endl;
484 #endif
485  jenv->CallVoidMethod(jobj, disconn_meth);
486  }
487  }
488  }
489 
490  public:
491  Director(JNIEnv *jenv) : swig_jvm_((JavaVM *) NULL), swig_self_() {
492  /* Acquire the Java VM pointer */
493  jenv->GetJavaVM(&swig_jvm_);
494  }
495 
496  virtual ~Director() {
497  JNIEnvWrapper jnienv(this) ;
498  JNIEnv *jenv = jnienv.getJNIEnv() ;
499  swig_self_.release(jenv);
500  }
501 
502  bool swig_set_self(JNIEnv *jenv, jobject jself, bool mem_own, bool weak_global) {
503  return swig_self_.set(jenv, jself, mem_own, weak_global);
504  }
505 
506  jobject swig_get_self(JNIEnv *jenv) const {
507  return swig_self_.get(jenv);
508  }
509 
510  // Change C++ object's ownership, relative to Java
511  void swig_java_change_ownership(JNIEnv *jenv, jobject jself, bool take_or_release) {
512  swig_self_.java_change_ownership(jenv, jself, take_or_release);
513  }
514  };
515 
516  // Zero initialized bool array
517  template<size_t N> class BoolArray {
518  bool array_[N];
519  public:
521  memset(array_, 0, sizeof(array_));
522  }
523  bool& operator[](size_t n) {
524  return array_[n];
525  }
526  bool operator[](size_t n) const {
527  return array_[n];
528  }
529  };
530 
531  // Utility classes and functions for exception handling.
532 
533  // Simple holder for a Java string during exception handling, providing access to a c-style string
534  class JavaString {
535  public:
536  JavaString(JNIEnv *jenv, jstring jstr) : jenv_(jenv), jstr_(jstr), cstr_(0) {
537  if (jenv_ && jstr_)
538  cstr_ = (const char *) jenv_->GetStringUTFChars(jstr_, NULL);
539  }
540 
542  if (jenv_ && jstr_ && cstr_)
543  jenv_->ReleaseStringUTFChars(jstr_, cstr_);
544  }
545 
546  const char *c_str(const char *null_string = "null JavaString") const {
547  return cstr_ ? cstr_ : null_string;
548  }
549 
550  private:
551  // non-copyable
552  JavaString(const JavaString &);
553  JavaString &operator=(const JavaString &);
554 
555  JNIEnv *jenv_;
556  jstring jstr_;
557  const char *cstr_;
558  };
559 
560  // Helper class to extract the exception message from a Java throwable
561  class JavaExceptionMessage {
562  public:
563  JavaExceptionMessage(JNIEnv *jenv, jthrowable throwable) : message_(jenv, exceptionMessageFromThrowable(jenv, throwable)) {
564  }
565 
566  // Return a C string of the exception message in the jthrowable passed in the constructor
567  // If no message is available, null_string is return instead
568  const char *message(const char *null_string = "Could not get exception message in JavaExceptionMessage") const {
569  return message_.c_str(null_string);
570  }
571 
572  private:
573  // non-copyable
575  JavaExceptionMessage &operator=(const JavaExceptionMessage &);
576 
577  // Get exception message by calling Java method Throwable.getMessage()
578  static jstring exceptionMessageFromThrowable(JNIEnv *jenv, jthrowable throwable) {
579  jstring jmsg = NULL;
580  if (jenv && throwable) {
581  jenv->ExceptionClear(); // Cannot invoke methods with any pending exceptions
582  jclass throwclz = jenv->GetObjectClass(throwable);
583  if (throwclz) {
584  // All Throwable classes have a getMessage() method, so call it to extract the exception message
585  jmethodID getMessageMethodID = jenv->GetMethodID(throwclz, "getMessage", "()Ljava/lang/String;");
586  if (getMessageMethodID)
587  jmsg = (jstring)jenv->CallObjectMethod(throwable, getMessageMethodID);
588  }
589  if (jmsg == NULL && jenv->ExceptionCheck())
590  jenv->ExceptionClear();
591  }
592  return jmsg;
593  }
594 
595  JavaString message_;
596  };
597 
598  // C++ Exception class for handling Java exceptions thrown during a director method Java upcall
599  class DirectorException : public std::exception {
600  public:
601 
602  // Construct exception from a Java throwable
603  DirectorException(JNIEnv *jenv, jthrowable throwable) : jenv_(jenv), throwable_(throwable), classname_(0), msg_(0) {
604 
605  // Call Java method Object.getClass().getName() to obtain the throwable's class name (delimited by '/')
606  if (jenv && throwable) {
607  jenv->ExceptionClear(); // Cannot invoke methods with any pending exceptions
608  jclass throwclz = jenv->GetObjectClass(throwable);
609  if (throwclz) {
610  jclass clzclz = jenv->GetObjectClass(throwclz);
611  if (clzclz) {
612  jmethodID getNameMethodID = jenv->GetMethodID(clzclz, "getName", "()Ljava/lang/String;");
613  if (getNameMethodID) {
614  jstring jstr_classname = (jstring)(jenv->CallObjectMethod(throwclz, getNameMethodID));
615  // Copy strings, since there is no guarantee that jenv will be active when handled
616  if (jstr_classname) {
617  JavaString jsclassname(jenv, jstr_classname);
618  const char *classname = jsclassname.c_str(0);
619  if (classname)
620  classname_ = copypath(classname);
621  }
622  }
623  }
624  }
625  }
626 
627  JavaExceptionMessage exceptionmsg(jenv, throwable);
628  msg_ = copystr(exceptionmsg.message(0));
629  }
630 
631  // More general constructor for handling as a java.lang.RuntimeException
632  DirectorException(const char *msg) : jenv_(0), throwable_(0), classname_(0), msg_(msg ? copystr(msg) : 0) {
633  }
634 
635  ~DirectorException() throw() {
636  delete[] classname_;
637  delete[] msg_;
638  }
639 
640  const char *what() const throw() {
641  return msg_ ? msg_ : "Unspecified DirectorException message";
642  }
643 
644  // Reconstruct and raise/throw the Java Exception that caused the DirectorException
645  // Note that any error in the JNI exception handling results in a Java RuntimeException
646  void throwException(JNIEnv *jenv) const {
647  if (jenv) {
648  if (jenv == jenv_ && throwable_) {
649  // Throw original exception if not already pending
650  jthrowable throwable = jenv->ExceptionOccurred();
651  if (throwable && jenv->IsSameObject(throwable, throwable_) == JNI_FALSE) {
652  jenv->ExceptionClear();
653  throwable = 0;
654  }
655  if (!throwable)
656  jenv->Throw(throwable_);
657  } else {
658  // Try and reconstruct original exception, but original stacktrace is not reconstructed
659  jenv->ExceptionClear();
660 
661  jmethodID ctorMethodID = 0;
662  jclass throwableclass = 0;
663  if (classname_) {
664  throwableclass = jenv->FindClass(classname_);
665  if (throwableclass)
666  ctorMethodID = jenv->GetMethodID(throwableclass, "<init>", "(Ljava/lang/String;)V");
667  }
668 
669  if (ctorMethodID) {
670  jenv->ThrowNew(throwableclass, what());
671  } else {
673  }
674  }
675  }
676  }
677 
678  // Deprecated - use throwException
679  void raiseJavaException(JNIEnv *jenv) const {
680  throwException(jenv);
681  }
682 
683  // Create and throw the DirectorException
684  static void raise(JNIEnv *jenv, jthrowable throwable) {
685  throw DirectorException(jenv, throwable);
686  }
687 
688  private:
689  static char *copypath(const char *srcmsg) {
690  char *target = copystr(srcmsg);
691  for (char *c=target; *c; ++c) {
692  if ('.' == *c)
693  *c = '/';
694  }
695  return target;
696  }
697 
698  static char *copystr(const char *srcmsg) {
699  char *target = 0;
700  if (srcmsg) {
701  size_t msglen = strlen(srcmsg) + 1;
702  target = new char[msglen];
703  strncpy(target, srcmsg, msglen);
704  }
705  return target;
706  }
707 
708  JNIEnv *jenv_;
709  jthrowable throwable_;
710  const char *classname_;
711  const char *msg_;
712  };
713 
714  // Helper method to determine if a Java throwable matches a particular Java class type
715  // Note side effect of clearing any pending exceptions
716  SWIGINTERN bool ExceptionMatches(JNIEnv *jenv, jthrowable throwable, const char *classname) {
717  bool matches = false;
718 
719  if (throwable && jenv && classname) {
720  // Exceptions need to be cleared for correct behavior.
721  // The caller of ExceptionMatches should restore pending exceptions if desired -
722  // the caller already has the throwable.
723  jenv->ExceptionClear();
724 
725  jclass clz = jenv->FindClass(classname);
726  if (clz) {
727  jclass classclz = jenv->GetObjectClass(clz);
728  jmethodID isInstanceMethodID = jenv->GetMethodID(classclz, "isInstance", "(Ljava/lang/Object;)Z");
729  if (isInstanceMethodID) {
730  matches = jenv->CallBooleanMethod(clz, isInstanceMethodID, throwable) != 0;
731  }
732  }
733 
734 #if defined(DEBUG_DIRECTOR_EXCEPTION)
735  if (jenv->ExceptionCheck()) {
736  // Typically occurs when an invalid classname argument is passed resulting in a ClassNotFoundException
737  JavaExceptionMessage exc(jenv, jenv->ExceptionOccurred());
738  std::cout << "Error: ExceptionMatches: class '" << classname << "' : " << exc.message() << std::endl;
739  }
740 #endif
741  }
742  return matches;
743  }
744 }
745 
746 namespace Swig {
747  namespace {
748  jclass jclass_mainJNI = NULL;
749  jmethodID director_method_ids[1];
750  }
751 }
752 
753 #include <stdint.h> // Use the C99 official header
754 
755 
756 #define SWIGWORDSIZE64
757 #ifndef LONG_MAX
758 #include <limits.h>
759 #endif
760 #if (__WORDSIZE == 32) || (LONG_MAX == INT_MAX)
761 # error "SWIG wrapped code invalid in 32 bit architecture, regenerate code using -DSWIGWORDSIZE32"
762 #endif
763 
764 
765 #include <cstdint>
766 #include <string>
767 #include <vector>
768 
769 #include "ortools/base/basictypes.h"
770 
771 
772 #include <string>
773 
774 
776 
777 
778 #include "ortools/base/jniutil.h"
779 
780 
781 #include "ortools/sat/cp_model.pb.h"
783 #include "ortools/sat/swig_helper.h"
785 
786 /* Global JNI reference deleter. Instantiate it via std::make_shared<> */
787 class GlobalRefGuard {
788  JavaVM *jvm_;
789  jobject jref_;
790  // non-copyable
791  GlobalRefGuard(const GlobalRefGuard &) = delete;
792  GlobalRefGuard &operator=(const GlobalRefGuard &) = delete;
793  public:
794  GlobalRefGuard(JavaVM *jvm, jobject jref): jvm_(jvm), jref_(jref) {}
796  JNIEnv *jenv = NULL;
797  JavaVMAttachArgs args;
798  args.version = JNI_VERSION_1_2;
799  args.name = NULL;
800  args.group = NULL;
801  jvm_->AttachCurrentThread((void**)&jenv, &args);
802  jenv->DeleteGlobalRef(jref_);
803  jvm_->DetachCurrentThread();
804  }
805 };
806 
807 
808 #include <memory> // std::make_shared<GlobalRefGuard>
809 
810 
811 
812 /* ---------------------------------------------------
813  * C++ director class methods
814  * --------------------------------------------------- */
815 
816 #include "sat_java_wrap.h"
817 
818 SwigDirector_SolutionCallback::SwigDirector_SolutionCallback(JNIEnv *jenv) : operations_research::sat::SolutionCallback(), Swig::Director(jenv) {
819 }
820 
822  swig_disconnect_director_self("swigDirectorDisconnect");
823 }
824 
825 
827  JNIEnvWrapper swigjnienv(this) ;
828  JNIEnv * jenv = swigjnienv.getJNIEnv() ;
829  jobject swigjobj = (jobject) NULL ;
830 
831  if (!swig_override[0]) {
832  SWIG_JavaThrowException(JNIEnvWrapper(this).getJNIEnv(), SWIG_JavaDirectorPureVirtual, "Attempted to invoke pure virtual method operations_research::sat::SolutionCallback::OnSolutionCallback.");
833  return;
834  }
835  swigjobj = swig_get_self(jenv);
836  if (swigjobj && jenv->IsSameObject(swigjobj, NULL) == JNI_FALSE) {
837  jenv->CallStaticVoidMethod(Swig::jclass_mainJNI, Swig::director_method_ids[0], swigjobj);
838  jthrowable swigerror = jenv->ExceptionOccurred();
839  if (swigerror) {
840  Swig::DirectorException::raise(jenv, swigerror);
841  }
842 
843  } else {
844  SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null upcall object in operations_research::sat::SolutionCallback::OnSolutionCallback ");
845  }
846  if (swigjobj) jenv->DeleteLocalRef(swigjobj);
847 }
848 
849 void SwigDirector_SolutionCallback::swig_connect_director(JNIEnv *jenv, jobject jself, jclass jcls, bool swig_mem_own, bool weak_global) {
850  static struct {
851  const char *mname;
852  const char *mdesc;
853  jmethodID base_methid;
854  } methods[] = {
855  {
856  "onSolutionCallback", "()V", NULL
857  }
858  };
859 
860  static jclass baseclass = 0 ;
861 
862  if (swig_set_self(jenv, jself, swig_mem_own, weak_global)) {
863  if (!baseclass) {
864  baseclass = jenv->FindClass("com/google/ortools/sat/SolutionCallback");
865  if (!baseclass) return;
866  baseclass = (jclass) jenv->NewGlobalRef(baseclass);
867  }
868  bool derived = (jenv->IsSameObject(baseclass, jcls) ? false : true);
869  for (int i = 0; i < 1; ++i) {
870  if (!methods[i].base_methid) {
871  methods[i].base_methid = jenv->GetMethodID(baseclass, methods[i].mname, methods[i].mdesc);
872  if (!methods[i].base_methid) return;
873  }
874  swig_override[i] = false;
875  if (derived) {
876  jmethodID methid = jenv->GetMethodID(jcls, methods[i].mname, methods[i].mdesc);
877  swig_override[i] = (methid != methods[i].base_methid);
878  jenv->ExceptionClear();
879  }
880  }
881  }
882 }
883 
884 
885 
886 #ifdef __cplusplus
887 extern "C" {
888 #endif
889 
890 SWIGEXPORT void JNICALL Java_com_google_ortools_sat_mainJNI_delete_1SolutionCallback(JNIEnv *jenv, jclass jcls, jlong jarg1) {
891  operations_research::sat::SolutionCallback *arg1 = (operations_research::sat::SolutionCallback *) 0 ;
892 
893  (void)jenv;
894  (void)jcls;
895  arg1 = *(operations_research::sat::SolutionCallback **)&jarg1;
896  delete arg1;
897 }
898 
899 
900 SWIGEXPORT void JNICALL Java_com_google_ortools_sat_mainJNI_SolutionCallback_1onSolutionCallback(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) {
901  operations_research::sat::SolutionCallback *arg1 = (operations_research::sat::SolutionCallback *) 0 ;
902 
903  (void)jenv;
904  (void)jcls;
905  (void)jarg1_;
906  arg1 = *(operations_research::sat::SolutionCallback **)&jarg1;
907  ((operations_research::sat::SolutionCallback const *)arg1)->OnSolutionCallback();
908 }
909 
910 
911 SWIGEXPORT jlong JNICALL Java_com_google_ortools_sat_mainJNI_SolutionCallback_1numBooleans(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) {
912  jlong jresult = 0 ;
913  operations_research::sat::SolutionCallback *arg1 = (operations_research::sat::SolutionCallback *) 0 ;
914  int64_t result;
915 
916  (void)jenv;
917  (void)jcls;
918  (void)jarg1_;
919  arg1 = *(operations_research::sat::SolutionCallback **)&jarg1;
920  result = (int64_t)((operations_research::sat::SolutionCallback const *)arg1)->NumBooleans();
921  jresult = (jlong)result;
922  return jresult;
923 }
924 
925 
926 SWIGEXPORT jlong JNICALL Java_com_google_ortools_sat_mainJNI_SolutionCallback_1numBranches(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) {
927  jlong jresult = 0 ;
928  operations_research::sat::SolutionCallback *arg1 = (operations_research::sat::SolutionCallback *) 0 ;
929  int64_t result;
930 
931  (void)jenv;
932  (void)jcls;
933  (void)jarg1_;
934  arg1 = *(operations_research::sat::SolutionCallback **)&jarg1;
935  result = (int64_t)((operations_research::sat::SolutionCallback const *)arg1)->NumBranches();
936  jresult = (jlong)result;
937  return jresult;
938 }
939 
940 
941 SWIGEXPORT jlong JNICALL Java_com_google_ortools_sat_mainJNI_SolutionCallback_1numConflicts(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) {
942  jlong jresult = 0 ;
943  operations_research::sat::SolutionCallback *arg1 = (operations_research::sat::SolutionCallback *) 0 ;
944  int64_t result;
945 
946  (void)jenv;
947  (void)jcls;
948  (void)jarg1_;
949  arg1 = *(operations_research::sat::SolutionCallback **)&jarg1;
950  result = (int64_t)((operations_research::sat::SolutionCallback const *)arg1)->NumConflicts();
951  jresult = (jlong)result;
952  return jresult;
953 }
954 
955 
956 SWIGEXPORT jlong JNICALL Java_com_google_ortools_sat_mainJNI_SolutionCallback_1numBinaryPropagations(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) {
957  jlong jresult = 0 ;
958  operations_research::sat::SolutionCallback *arg1 = (operations_research::sat::SolutionCallback *) 0 ;
959  int64_t result;
960 
961  (void)jenv;
962  (void)jcls;
963  (void)jarg1_;
964  arg1 = *(operations_research::sat::SolutionCallback **)&jarg1;
965  result = (int64_t)((operations_research::sat::SolutionCallback const *)arg1)->NumBinaryPropagations();
966  jresult = (jlong)result;
967  return jresult;
968 }
969 
970 
971 SWIGEXPORT jlong JNICALL Java_com_google_ortools_sat_mainJNI_SolutionCallback_1numIntegerPropagations(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) {
972  jlong jresult = 0 ;
973  operations_research::sat::SolutionCallback *arg1 = (operations_research::sat::SolutionCallback *) 0 ;
974  int64_t result;
975 
976  (void)jenv;
977  (void)jcls;
978  (void)jarg1_;
979  arg1 = *(operations_research::sat::SolutionCallback **)&jarg1;
980  result = (int64_t)((operations_research::sat::SolutionCallback const *)arg1)->NumIntegerPropagations();
981  jresult = (jlong)result;
982  return jresult;
983 }
984 
985 
986 SWIGEXPORT jdouble JNICALL Java_com_google_ortools_sat_mainJNI_SolutionCallback_1wallTime(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) {
987  jdouble jresult = 0 ;
988  operations_research::sat::SolutionCallback *arg1 = (operations_research::sat::SolutionCallback *) 0 ;
989  double result;
990 
991  (void)jenv;
992  (void)jcls;
993  (void)jarg1_;
994  arg1 = *(operations_research::sat::SolutionCallback **)&jarg1;
995  result = (double)((operations_research::sat::SolutionCallback const *)arg1)->WallTime();
996  jresult = (jdouble)result;
997  return jresult;
998 }
999 
1000 
1001 SWIGEXPORT jdouble JNICALL Java_com_google_ortools_sat_mainJNI_SolutionCallback_1userTime(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) {
1002  jdouble jresult = 0 ;
1003  operations_research::sat::SolutionCallback *arg1 = (operations_research::sat::SolutionCallback *) 0 ;
1004  double result;
1005 
1006  (void)jenv;
1007  (void)jcls;
1008  (void)jarg1_;
1009  arg1 = *(operations_research::sat::SolutionCallback **)&jarg1;
1010  result = (double)((operations_research::sat::SolutionCallback const *)arg1)->UserTime();
1011  jresult = (jdouble)result;
1012  return jresult;
1013 }
1014 
1015 
1016 SWIGEXPORT jdouble JNICALL Java_com_google_ortools_sat_mainJNI_SolutionCallback_1objectiveValue(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) {
1017  jdouble jresult = 0 ;
1018  operations_research::sat::SolutionCallback *arg1 = (operations_research::sat::SolutionCallback *) 0 ;
1019  double result;
1020 
1021  (void)jenv;
1022  (void)jcls;
1023  (void)jarg1_;
1024  arg1 = *(operations_research::sat::SolutionCallback **)&jarg1;
1025  result = (double)((operations_research::sat::SolutionCallback const *)arg1)->ObjectiveValue();
1026  jresult = (jdouble)result;
1027  return jresult;
1028 }
1029 
1030 
1031 SWIGEXPORT jdouble JNICALL Java_com_google_ortools_sat_mainJNI_SolutionCallback_1bestObjectiveBound(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) {
1032  jdouble jresult = 0 ;
1033  operations_research::sat::SolutionCallback *arg1 = (operations_research::sat::SolutionCallback *) 0 ;
1034  double result;
1035 
1036  (void)jenv;
1037  (void)jcls;
1038  (void)jarg1_;
1039  arg1 = *(operations_research::sat::SolutionCallback **)&jarg1;
1040  result = (double)((operations_research::sat::SolutionCallback const *)arg1)->BestObjectiveBound();
1041  jresult = (jdouble)result;
1042  return jresult;
1043 }
1044 
1045 
1046 SWIGEXPORT jlong JNICALL Java_com_google_ortools_sat_mainJNI_SolutionCallback_1solutionIntegerValue(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jint jarg2) {
1047  jlong jresult = 0 ;
1048  operations_research::sat::SolutionCallback *arg1 = (operations_research::sat::SolutionCallback *) 0 ;
1049  int arg2 ;
1050  int64_t result;
1051 
1052  (void)jenv;
1053  (void)jcls;
1054  (void)jarg1_;
1055  arg1 = *(operations_research::sat::SolutionCallback **)&jarg1;
1056  arg2 = (int)jarg2;
1057  result = (int64_t)(arg1)->SolutionIntegerValue(arg2);
1058  jresult = (jlong)result;
1059  return jresult;
1060 }
1061 
1062 
1063 SWIGEXPORT jboolean JNICALL Java_com_google_ortools_sat_mainJNI_SolutionCallback_1solutionBooleanValue(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jint jarg2) {
1064  jboolean jresult = 0 ;
1065  operations_research::sat::SolutionCallback *arg1 = (operations_research::sat::SolutionCallback *) 0 ;
1066  int arg2 ;
1067  bool result;
1068 
1069  (void)jenv;
1070  (void)jcls;
1071  (void)jarg1_;
1072  arg1 = *(operations_research::sat::SolutionCallback **)&jarg1;
1073  arg2 = (int)jarg2;
1074  result = (bool)(arg1)->SolutionBooleanValue(arg2);
1075  jresult = (jboolean)result;
1076  return jresult;
1077 }
1078 
1079 
1080 SWIGEXPORT void JNICALL Java_com_google_ortools_sat_mainJNI_SolutionCallback_1stopSearch(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) {
1081  operations_research::sat::SolutionCallback *arg1 = (operations_research::sat::SolutionCallback *) 0 ;
1082 
1083  (void)jenv;
1084  (void)jcls;
1085  (void)jarg1_;
1086  arg1 = *(operations_research::sat::SolutionCallback **)&jarg1;
1087  (arg1)->StopSearch();
1088 }
1089 
1090 
1092  jlong jresult = 0 ;
1093  operations_research::sat::SolutionCallback *result = 0 ;
1094 
1095  (void)jenv;
1096  (void)jcls;
1097  result = (operations_research::sat::SolutionCallback *)new SwigDirector_SolutionCallback(jenv);
1098  *(operations_research::sat::SolutionCallback **)&jresult = result;
1099  return jresult;
1100 }
1101 
1102 
1103 SWIGEXPORT void JNICALL Java_com_google_ortools_sat_mainJNI_SolutionCallback_1director_1connect(JNIEnv *jenv, jclass jcls, jobject jself, jlong objarg, jboolean jswig_mem_own, jboolean jweak_global) {
1104  operations_research::sat::SolutionCallback *obj = *((operations_research::sat::SolutionCallback **)&objarg);
1105  (void)jcls;
1106  SwigDirector_SolutionCallback *director = static_cast<SwigDirector_SolutionCallback *>(obj);
1107  director->swig_connect_director(jenv, jself, jenv->GetObjectClass(jself), (jswig_mem_own == JNI_TRUE), (jweak_global == JNI_TRUE));
1108 }
1109 
1110 
1111 SWIGEXPORT void JNICALL Java_com_google_ortools_sat_mainJNI_SolutionCallback_1change_1ownership(JNIEnv *jenv, jclass jcls, jobject jself, jlong objarg, jboolean jtake_or_release) {
1112  operations_research::sat::SolutionCallback *obj = *((operations_research::sat::SolutionCallback **)&objarg);
1113  SwigDirector_SolutionCallback *director = dynamic_cast<SwigDirector_SolutionCallback *>(obj);
1114  (void)jcls;
1115  if (director) {
1116  director->swig_java_change_ownership(jenv, jself, jtake_or_release ? true : false);
1117  }
1118 }
1119 
1120 
1121 SWIGEXPORT void JNICALL Java_com_google_ortools_sat_mainJNI_SolveWrapper_1setParameters(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jbyteArray jarg2) {
1122  operations_research::sat::SolveWrapper *arg1 = (operations_research::sat::SolveWrapper *) 0 ;
1125 
1126  (void)jenv;
1127  (void)jcls;
1128  (void)jarg1_;
1129  arg1 = *(operations_research::sat::SolveWrapper **)&jarg1;
1130  {
1131  int proto_size = 0;
1132  std::unique_ptr<char[]> proto_buffer(
1133  JNIUtil::MakeCharArray(jenv, jarg2, &proto_size));
1134  bool parsed_ok = temp2.ParseFromArray(proto_buffer.get(), proto_size);
1135  if (!parsed_ok) {
1138  "Unable to parse operations_research::sat::SatParameters protocol message.");
1139  }
1140  arg2 = &temp2;
1141  }
1142  (arg1)->SetParameters((operations_research::sat::SatParameters const &)*arg2);
1143 }
1144 
1145 
1146 SWIGEXPORT void JNICALL Java_com_google_ortools_sat_mainJNI_SolveWrapper_1addSolutionCallback(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jlong jarg2, jobject jarg2_) {
1147  operations_research::sat::SolveWrapper *arg1 = (operations_research::sat::SolveWrapper *) 0 ;
1148  operations_research::sat::SolutionCallback *arg2 = 0 ;
1149 
1150  (void)jenv;
1151  (void)jcls;
1152  (void)jarg1_;
1153  (void)jarg2_;
1154  arg1 = *(operations_research::sat::SolveWrapper **)&jarg1;
1155  arg2 = *(operations_research::sat::SolutionCallback **)&jarg2;
1156  if (!arg2) {
1157  SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "operations_research::sat::SolutionCallback const & reference is null");
1158  return ;
1159  }
1160  (arg1)->AddSolutionCallback((operations_research::sat::SolutionCallback const &)*arg2);
1161 }
1162 
1163 
1164 SWIGEXPORT void JNICALL Java_com_google_ortools_sat_mainJNI_SolveWrapper_1clearSolutionCallback(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jlong jarg2, jobject jarg2_) {
1165  operations_research::sat::SolveWrapper *arg1 = (operations_research::sat::SolveWrapper *) 0 ;
1166  operations_research::sat::SolutionCallback *arg2 = 0 ;
1167 
1168  (void)jenv;
1169  (void)jcls;
1170  (void)jarg1_;
1171  (void)jarg2_;
1172  arg1 = *(operations_research::sat::SolveWrapper **)&jarg1;
1173  arg2 = *(operations_research::sat::SolutionCallback **)&jarg2;
1174  if (!arg2) {
1175  SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "operations_research::sat::SolutionCallback const & reference is null");
1176  return ;
1177  }
1178  (arg1)->ClearSolutionCallback((operations_research::sat::SolutionCallback const &)*arg2);
1179 }
1180 
1181 
1182 SWIGEXPORT void JNICALL Java_com_google_ortools_sat_mainJNI_SolveWrapper_1addLogCallback(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jobject jarg2) {
1183  operations_research::sat::SolveWrapper *arg1 = (operations_research::sat::SolveWrapper *) 0 ;
1184  SwigValueWrapper< std::function< void (std::string const &) > > arg2 ;
1185 
1186  (void)jenv;
1187  (void)jcls;
1188  (void)jarg1_;
1189  arg1 = *(operations_research::sat::SolveWrapper **)&jarg1;
1190 
1191  // jarg2 will be deleted once this function return.
1192  // So we create a JNI global reference to keep it alive.
1193  jobject jarg2_object = jenv->NewGlobalRef(jarg2);
1194  // and we wrap it in a GlobalRefGuard object which will call the
1195  // JNI global reference deleter to avoid leak at destruction.
1196  JavaVM* jvm;
1197  jenv->GetJavaVM(&jvm);
1198  auto jarg2_guard = std::make_shared<GlobalRefGuard>(jvm, jarg2_object);
1199 
1200  jclass jarg2_object_class = jenv->GetObjectClass(jarg2);
1201  if (nullptr == jarg2_object_class) return ;
1202  jmethodID jarg2_method_id = jenv->GetMethodID(
1203  jarg2_object_class, "accept", "(Ljava/lang/Object;)V");
1204  assert(jarg2_method_id != nullptr);
1205 
1206  // When the lambda will be destroyed, input_guard's destructor will be called.
1207  arg2 = [jvm, jarg2_object, jarg2_method_id, jarg2_guard](
1208  const std::string& message) -> void {
1209  JNIEnv *jenv = NULL;
1210  JavaVMAttachArgs args;
1211  args.version = JNI_VERSION_1_2;
1212  args.name = NULL;
1213  args.group = NULL;
1214  jvm->AttachCurrentThread((void**)&jenv, &args);
1215  jenv->CallVoidMethod(jarg2_object, jarg2_method_id, (jenv)->NewStringUTF(message.c_str()));
1216  jvm->DetachCurrentThread();
1217  };
1218 
1219  (arg1)->AddLogCallback(arg2);
1220 }
1221 
1222 
1223 SWIGEXPORT jbyteArray JNICALL Java_com_google_ortools_sat_mainJNI_SolveWrapper_1solve(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jbyteArray jarg2) {
1224  jbyteArray jresult = 0 ;
1225  operations_research::sat::SolveWrapper *arg1 = (operations_research::sat::SolveWrapper *) 0 ;
1229 
1230  (void)jenv;
1231  (void)jcls;
1232  (void)jarg1_;
1233  arg1 = *(operations_research::sat::SolveWrapper **)&jarg1;
1234  {
1235  int proto_size = 0;
1236  std::unique_ptr<char[]> proto_buffer(
1237  JNIUtil::MakeCharArray(jenv, jarg2, &proto_size));
1238  bool parsed_ok = temp2.ParseFromArray(proto_buffer.get(), proto_size);
1239  if (!parsed_ok) {
1242  "Unable to parse operations_research::sat::CpModelProto protocol message.");
1243  }
1244  arg2 = &temp2;
1245  }
1246  result = (arg1)->Solve((operations_research::sat::CpModelProto const &)*arg2);
1247  {
1248  const long size = (&result)->ByteSizeLong();
1249  std::unique_ptr<char[]> buf(new char[size]);
1250  (&result)->SerializeWithCachedSizesToArray(reinterpret_cast<uint8_t*>(buf.get()));
1251  jresult = JNIUtil::MakeJByteArray(jenv, buf.get(), size);
1252  }
1253  return jresult;
1254 }
1255 
1256 
1257 SWIGEXPORT void JNICALL Java_com_google_ortools_sat_mainJNI_SolveWrapper_1stopSearch(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) {
1258  operations_research::sat::SolveWrapper *arg1 = (operations_research::sat::SolveWrapper *) 0 ;
1259 
1260  (void)jenv;
1261  (void)jcls;
1262  (void)jarg1_;
1263  arg1 = *(operations_research::sat::SolveWrapper **)&jarg1;
1264  (arg1)->StopSearch();
1265 }
1266 
1267 
1268 SWIGEXPORT jlong JNICALL Java_com_google_ortools_sat_mainJNI_new_1SolveWrapper(JNIEnv *jenv, jclass jcls) {
1269  jlong jresult = 0 ;
1270  operations_research::sat::SolveWrapper *result = 0 ;
1271 
1272  (void)jenv;
1273  (void)jcls;
1274  result = (operations_research::sat::SolveWrapper *)new operations_research::sat::SolveWrapper();
1275  *(operations_research::sat::SolveWrapper **)&jresult = result;
1276  return jresult;
1277 }
1278 
1279 
1280 SWIGEXPORT void JNICALL Java_com_google_ortools_sat_mainJNI_delete_1SolveWrapper(JNIEnv *jenv, jclass jcls, jlong jarg1) {
1281  operations_research::sat::SolveWrapper *arg1 = (operations_research::sat::SolveWrapper *) 0 ;
1282 
1283  (void)jenv;
1284  (void)jcls;
1285  arg1 = *(operations_research::sat::SolveWrapper **)&jarg1;
1286  delete arg1;
1287 }
1288 
1289 
1290 SWIGEXPORT jstring JNICALL Java_com_google_ortools_sat_mainJNI_CpSatHelper_1modelStats(JNIEnv *jenv, jclass jcls, jbyteArray jarg1) {
1291  jstring jresult = 0 ;
1294  std::string result;
1295 
1296  (void)jenv;
1297  (void)jcls;
1298  {
1299  int proto_size = 0;
1300  std::unique_ptr<char[]> proto_buffer(
1301  JNIUtil::MakeCharArray(jenv, jarg1, &proto_size));
1302  bool parsed_ok = temp1.ParseFromArray(proto_buffer.get(), proto_size);
1303  if (!parsed_ok) {
1306  "Unable to parse operations_research::sat::CpModelProto protocol message.");
1307  }
1308  arg1 = &temp1;
1309  }
1310  result = operations_research::sat::CpSatHelper::ModelStats((operations_research::sat::CpModelProto const &)*arg1);
1311  jresult = jenv->NewStringUTF((&result)->c_str());
1312  return jresult;
1313 }
1314 
1315 
1316 SWIGEXPORT jstring JNICALL Java_com_google_ortools_sat_mainJNI_CpSatHelper_1solverResponseStats(JNIEnv *jenv, jclass jcls, jbyteArray jarg1) {
1317  jstring jresult = 0 ;
1320  std::string result;
1321 
1322  (void)jenv;
1323  (void)jcls;
1324  {
1325  int proto_size = 0;
1326  std::unique_ptr<char[]> proto_buffer(
1327  JNIUtil::MakeCharArray(jenv, jarg1, &proto_size));
1328  bool parsed_ok = temp1.ParseFromArray(proto_buffer.get(), proto_size);
1329  if (!parsed_ok) {
1332  "Unable to parse operations_research::sat::CpSolverResponse protocol message.");
1333  }
1334  arg1 = &temp1;
1335  }
1336  result = operations_research::sat::CpSatHelper::SolverResponseStats((operations_research::sat::CpSolverResponse const &)*arg1);
1337  jresult = jenv->NewStringUTF((&result)->c_str());
1338  return jresult;
1339 }
1340 
1341 
1342 SWIGEXPORT jstring JNICALL Java_com_google_ortools_sat_mainJNI_CpSatHelper_1validateModel(JNIEnv *jenv, jclass jcls, jbyteArray jarg1) {
1343  jstring jresult = 0 ;
1346  std::string result;
1347 
1348  (void)jenv;
1349  (void)jcls;
1350  {
1351  int proto_size = 0;
1352  std::unique_ptr<char[]> proto_buffer(
1353  JNIUtil::MakeCharArray(jenv, jarg1, &proto_size));
1354  bool parsed_ok = temp1.ParseFromArray(proto_buffer.get(), proto_size);
1355  if (!parsed_ok) {
1358  "Unable to parse operations_research::sat::CpModelProto protocol message.");
1359  }
1360  arg1 = &temp1;
1361  }
1363  jresult = jenv->NewStringUTF((&result)->c_str());
1364  return jresult;
1365 }
1366 
1367 
1368 SWIGEXPORT jlong JNICALL Java_com_google_ortools_sat_mainJNI_CpSatHelper_1variableDomain(JNIEnv *jenv, jclass jcls, jbyteArray jarg1) {
1369  jlong jresult = 0 ;
1373 
1374  (void)jenv;
1375  (void)jcls;
1376  {
1377  int proto_size = 0;
1378  std::unique_ptr<char[]> proto_buffer(
1379  JNIUtil::MakeCharArray(jenv, jarg1, &proto_size));
1380  bool parsed_ok = temp1.ParseFromArray(proto_buffer.get(), proto_size);
1381  if (!parsed_ok) {
1384  "Unable to parse operations_research::sat::IntegerVariableProto protocol message.");
1385  }
1386  arg1 = &temp1;
1387  }
1388  result = operations_research::sat::CpSatHelper::VariableDomain((operations_research::sat::IntegerVariableProto const &)*arg1);
1390  return jresult;
1391 }
1392 
1393 
1394 SWIGEXPORT jboolean JNICALL Java_com_google_ortools_sat_mainJNI_CpSatHelper_1writeModelToFile(JNIEnv *jenv, jclass jcls, jbyteArray jarg1, jstring jarg2) {
1395  jboolean jresult = 0 ;
1397  std::string *arg2 = 0 ;
1399  bool result;
1400 
1401  (void)jenv;
1402  (void)jcls;
1403  {
1404  int proto_size = 0;
1405  std::unique_ptr<char[]> proto_buffer(
1406  JNIUtil::MakeCharArray(jenv, jarg1, &proto_size));
1407  bool parsed_ok = temp1.ParseFromArray(proto_buffer.get(), proto_size);
1408  if (!parsed_ok) {
1411  "Unable to parse operations_research::sat::CpModelProto protocol message.");
1412  }
1413  arg1 = &temp1;
1414  }
1415  if(!jarg2) {
1417  return 0;
1418  }
1419  const char *arg2_pstr = (const char *)jenv->GetStringUTFChars(jarg2, 0);
1420  if (!arg2_pstr) return 0;
1421  std::string arg2_str(arg2_pstr);
1422  arg2 = &arg2_str;
1423  jenv->ReleaseStringUTFChars(jarg2, arg2_pstr);
1424  result = (bool)operations_research::sat::CpSatHelper::WriteModelToFile((operations_research::sat::CpModelProto const &)*arg1,(std::string const &)*arg2);
1425  jresult = (jboolean)result;
1426  return jresult;
1427 }
1428 
1429 
1430 SWIGEXPORT jlong JNICALL Java_com_google_ortools_sat_mainJNI_new_1CpSatHelper(JNIEnv *jenv, jclass jcls) {
1431  jlong jresult = 0 ;
1432  operations_research::sat::CpSatHelper *result = 0 ;
1433 
1434  (void)jenv;
1435  (void)jcls;
1436  result = (operations_research::sat::CpSatHelper *)new operations_research::sat::CpSatHelper();
1437  *(operations_research::sat::CpSatHelper **)&jresult = result;
1438  return jresult;
1439 }
1440 
1441 
1442 SWIGEXPORT void JNICALL Java_com_google_ortools_sat_mainJNI_delete_1CpSatHelper(JNIEnv *jenv, jclass jcls, jlong jarg1) {
1443  operations_research::sat::CpSatHelper *arg1 = (operations_research::sat::CpSatHelper *) 0 ;
1444 
1445  (void)jenv;
1446  (void)jcls;
1447  arg1 = *(operations_research::sat::CpSatHelper **)&jarg1;
1448  delete arg1;
1449 }
1450 
1451 
1453  int i;
1454 
1455  static struct {
1456  const char *method;
1457  const char *signature;
1458  } methods[1] = {
1459  {
1460  "SwigDirector_SolutionCallback_onSolutionCallback", "(Lcom/google/ortools/sat/SolutionCallback;)V"
1461  }
1462  };
1463  Swig::jclass_mainJNI = (jclass) jenv->NewGlobalRef(jcls);
1464  if (!Swig::jclass_mainJNI) return;
1465  for (i = 0; i < (int) (sizeof(methods)/sizeof(methods[0])); ++i) {
1466  Swig::director_method_ids[i] = jenv->GetStaticMethodID(jcls, methods[i].method, methods[i].signature);
1467  if (!Swig::director_method_ids[i]) return;
1468  }
1469 }
1470 
1471 
1472 #ifdef __cplusplus
1473 }
1474 #endif
1475 
SWIGEXPORT jstring JNICALL Java_com_google_ortools_sat_mainJNI_CpSatHelper_1solverResponseStats(JNIEnv *jenv, jclass jcls, jbyteArray jarg1)
void throwException(JNIEnv *jenv) const
SWIGEXPORT void JNICALL Java_com_google_ortools_sat_mainJNI_delete_1CpSatHelper(JNIEnv *jenv, jclass jcls, jlong jarg1)
JNIEnvWrapper(const Director *director)
SWIGEXPORT void JNICALL Java_com_google_ortools_sat_mainJNI_SolutionCallback_1director_1connect(JNIEnv *jenv, jclass jcls, jobject jself, jlong objarg, jboolean jswig_mem_own, jboolean jweak_global)
SWIGEXPORT void JNICALL Java_com_google_ortools_sat_mainJNI_SolveWrapper_1addSolutionCallback(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jlong jarg2, jobject jarg2_)
JavaExceptionMessage(JNIEnv *jenv, jthrowable throwable)
virtual void OnSolutionCallback() const
SWIGEXPORT void JNICALL Java_com_google_ortools_sat_mainJNI_SolveWrapper_1setParameters(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jbyteArray jarg2)
jobject get(JNIEnv *jenv) const
SWIGEXPORT jlong JNICALL Java_com_google_ortools_sat_mainJNI_new_1CpSatHelper(JNIEnv *jenv, jclass jcls)
SWIGEXPORT jboolean JNICALL Java_com_google_ortools_sat_mainJNI_SolutionCallback_1solutionBooleanValue(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jint jarg2)
SWIG_JavaExceptionCodes
void swig_java_change_ownership(JNIEnv *jenv, jobject jself, bool take_or_release)
SWIGEXPORT void JNICALL Java_com_google_ortools_sat_mainJNI_swig_1module_1init(JNIEnv *jenv, jclass jcls)
#define SWIGEXPORT
PyObject * swig_get_self() const
SWIGEXPORT void JNICALL Java_com_google_ortools_sat_mainJNI_SolveWrapper_1stopSearch(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_)
SWIGEXPORT jlong JNICALL Java_com_google_ortools_sat_mainJNI_SolutionCallback_1numBooleans(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_)
static char * MakeCharArray(JNIEnv *env, jbyteArray a, int *size)
Definition: jniutil.h:47
SWIGEXPORT jlong JNICALL Java_com_google_ortools_sat_mainJNI_new_1SolveWrapper(JNIEnv *jenv, jclass jcls)
bool set(JNIEnv *jenv, jobject jobj, bool mem_own, bool weak_global)
const std::string name
const char * what() const
JavaString(JNIEnv *jenv, jstring jstr)
bool operator[](size_t n) const
const char * message(const char *null_string="Could not get exception message in JavaExceptionMessage") const
CpSolverResponse Solve(const CpModelProto &model_proto)
Solves the given CpModelProto and returns an instance of CpSolverResponse.
SWIGEXPORT jboolean JNICALL Java_com_google_ortools_sat_mainJNI_CpSatHelper_1writeModelToFile(JNIEnv *jenv, jclass jcls, jbyteArray jarg1, jstring jarg2)
void java_change_ownership(JNIEnv *jenv, jobject jself, bool take_or_release)
SWIGEXPORT void JNICALL Java_com_google_ortools_sat_mainJNI_SolutionCallback_1stopSearch(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_)
#define SWIGINTERN
SWIGEXPORT void JNICALL Java_com_google_ortools_sat_mainJNI_SolveWrapper_1addLogCallback(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jobject jarg2)
SWIGEXPORT jlong JNICALL Java_com_google_ortools_sat_mainJNI_CpSatHelper_1variableDomain(JNIEnv *jenv, jclass jcls, jbyteArray jarg1)
SWIGEXPORT void JNICALL Java_com_google_ortools_sat_mainJNI_delete_1SolveWrapper(JNIEnv *jenv, jclass jcls, jlong jarg1)
void swig_connect_director(SWIG_Callback0_t callbackOnSolutionCallback)
SWIGEXPORT jbyteArray JNICALL Java_com_google_ortools_sat_mainJNI_SolveWrapper_1solve(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jbyteArray jarg2)
SWIGEXPORT jlong JNICALL Java_com_google_ortools_sat_mainJNI_SolutionCallback_1numBinaryPropagations(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_)
SWIGEXPORT jlong JNICALL Java_com_google_ortools_sat_mainJNI_SolutionCallback_1solutionIntegerValue(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jint jarg2)
LocalRefGuard(JNIEnv *jenv, jobject jobj)
bool swig_set_self(JNIEnv *jenv, jobject jself, bool mem_own, bool weak_global)
void swig_disconnect_director_self(const char *disconn_method)
SWIGEXPORT jstring JNICALL Java_com_google_ortools_sat_mainJNI_CpSatHelper_1validateModel(JNIEnv *jenv, jclass jcls, jbyteArray jarg1)
SWIGEXPORT jdouble JNICALL Java_com_google_ortools_sat_mainJNI_SolutionCallback_1wallTime(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_)
void release(JNIEnv *jenv)
SWIGEXPORT void JNICALL Java_com_google_ortools_sat_mainJNI_delete_1SolutionCallback(JNIEnv *jenv, jclass jcls, jlong jarg1)
SWIGEXPORT jdouble JNICALL Java_com_google_ortools_sat_mainJNI_SolutionCallback_1bestObjectiveBound(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_)
SWIGEXPORT jlong JNICALL Java_com_google_ortools_sat_mainJNI_new_1SolutionCallback(JNIEnv *jenv, jclass jcls)
static void raise(JNIEnv *jenv, jthrowable throwable)
SWIGEXPORT jdouble JNICALL Java_com_google_ortools_sat_mainJNI_SolutionCallback_1userTime(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_)
SWIGINTERN bool ExceptionMatches(JNIEnv *jenv, jthrowable throwable, const char *classname)
Swig::BoolArray< 1 > swig_override
Definition: sat_java_wrap.h:26
std::string message
Definition: trace.cc:398
virtual ~Director()
SWIGEXPORT void JNICALL Java_com_google_ortools_sat_mainJNI_SolveWrapper_1clearSolutionCallback(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jlong jarg2, jobject jarg2_)
SWIGEXPORT void JNICALL Java_com_google_ortools_sat_mainJNI_SolutionCallback_1change_1ownership(JNIEnv *jenv, jclass jcls, jobject jself, jlong objarg, jboolean jtake_or_release)
We call domain any subset of Int64 = [kint64min, kint64max].
SWIGEXPORT jlong JNICALL Java_com_google_ortools_sat_mainJNI_SolutionCallback_1numIntegerPropagations(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_)
DirectorException(const char *msg)
SWIGEXPORT void JNICALL Java_com_google_ortools_sat_mainJNI_SolutionCallback_1onSolutionCallback(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_)
bool & operator[](size_t n)
SWIGEXPORT jlong JNICALL Java_com_google_ortools_sat_mainJNI_SolutionCallback_1numConflicts(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_)
absl::Status ValidateModel(const ModelProto &model, const bool check_names)
Collection of objects used to extend the Constraint Solver library.
SWIG_JavaExceptionCodes code
DirectorException(JNIEnv *jenv, jthrowable throwable)
jobject swig_get_self(JNIEnv *jenv) const
#define SWIGUNUSED
static jbyteArray MakeJByteArray(JNIEnv *env, const char *a, int size)
Definition: jniutil.h:59
SWIGEXPORT jlong JNICALL Java_com_google_ortools_sat_mainJNI_SolutionCallback_1numBranches(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_)
void raiseJavaException(JNIEnv *jenv) const
SWIGEXPORT jdouble JNICALL Java_com_google_ortools_sat_mainJNI_SolutionCallback_1objectiveValue(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_)
static void SWIGUNUSED SWIG_JavaThrowException(JNIEnv *jenv, SWIG_JavaExceptionCodes code, const char *msg)
SWIGEXPORT jstring JNICALL Java_com_google_ortools_sat_mainJNI_CpSatHelper_1modelStats(JNIEnv *jenv, jclass jcls, jbyteArray jarg1)
GlobalRefGuard(JavaVM *jvm, jobject jref)
const char * c_str(const char *null_string="null JavaString") const