OR-Tools  9.0
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.2
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  JNIEnv *jenv_;
789  jobject jref_;
790  // non-copyable
791  GlobalRefGuard(const GlobalRefGuard &) = delete;
792  GlobalRefGuard &operator=(const GlobalRefGuard &) = delete;
793  public:
794  GlobalRefGuard(JNIEnv *jenv, jobject jref): jenv_(jenv), jref_(jref) {}
795  ~GlobalRefGuard() { jenv_->DeleteGlobalRef(jref_); }
796 };
797 
798 
799 
800 /* ---------------------------------------------------
801  * C++ director class methods
802  * --------------------------------------------------- */
803 
804 #include "sat_java_wrap.h"
805 
806 SwigDirector_SolutionCallback::SwigDirector_SolutionCallback(JNIEnv *jenv) : operations_research::sat::SolutionCallback(), Swig::Director(jenv) {
807 }
808 
810  swig_disconnect_director_self("swigDirectorDisconnect");
811 }
812 
813 
815  JNIEnvWrapper swigjnienv(this) ;
816  JNIEnv * jenv = swigjnienv.getJNIEnv() ;
817  jobject swigjobj = (jobject) NULL ;
818 
819  if (!swig_override[0]) {
820  SWIG_JavaThrowException(JNIEnvWrapper(this).getJNIEnv(), SWIG_JavaDirectorPureVirtual, "Attempted to invoke pure virtual method operations_research::sat::SolutionCallback::OnSolutionCallback.");
821  return;
822  }
823  swigjobj = swig_get_self(jenv);
824  if (swigjobj && jenv->IsSameObject(swigjobj, NULL) == JNI_FALSE) {
825  jenv->CallStaticVoidMethod(Swig::jclass_mainJNI, Swig::director_method_ids[0], swigjobj);
826  jthrowable swigerror = jenv->ExceptionOccurred();
827  if (swigerror) {
828  Swig::DirectorException::raise(jenv, swigerror);
829  }
830 
831  } else {
832  SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null upcall object in operations_research::sat::SolutionCallback::OnSolutionCallback ");
833  }
834  if (swigjobj) jenv->DeleteLocalRef(swigjobj);
835 }
836 
837 void SwigDirector_SolutionCallback::swig_connect_director(JNIEnv *jenv, jobject jself, jclass jcls, bool swig_mem_own, bool weak_global) {
838  static struct {
839  const char *mname;
840  const char *mdesc;
841  jmethodID base_methid;
842  } methods[] = {
843  {
844  "onSolutionCallback", "()V", NULL
845  }
846  };
847 
848  static jclass baseclass = 0 ;
849 
850  if (swig_set_self(jenv, jself, swig_mem_own, weak_global)) {
851  if (!baseclass) {
852  baseclass = jenv->FindClass("com/google/ortools/sat/SolutionCallback");
853  if (!baseclass) return;
854  baseclass = (jclass) jenv->NewGlobalRef(baseclass);
855  }
856  bool derived = (jenv->IsSameObject(baseclass, jcls) ? false : true);
857  for (int i = 0; i < 1; ++i) {
858  if (!methods[i].base_methid) {
859  methods[i].base_methid = jenv->GetMethodID(baseclass, methods[i].mname, methods[i].mdesc);
860  if (!methods[i].base_methid) return;
861  }
862  swig_override[i] = false;
863  if (derived) {
864  jmethodID methid = jenv->GetMethodID(jcls, methods[i].mname, methods[i].mdesc);
865  swig_override[i] = (methid != methods[i].base_methid);
866  jenv->ExceptionClear();
867  }
868  }
869  }
870 }
871 
872 
873 
874 #ifdef __cplusplus
875 extern "C" {
876 #endif
877 
878 SWIGEXPORT void JNICALL Java_com_google_ortools_sat_mainJNI_delete_1SolutionCallback(JNIEnv *jenv, jclass jcls, jlong jarg1) {
879  operations_research::sat::SolutionCallback *arg1 = (operations_research::sat::SolutionCallback *) 0 ;
880 
881  (void)jenv;
882  (void)jcls;
883  arg1 = *(operations_research::sat::SolutionCallback **)&jarg1;
884  delete arg1;
885 }
886 
887 
888 SWIGEXPORT void JNICALL Java_com_google_ortools_sat_mainJNI_SolutionCallback_1onSolutionCallback(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) {
889  operations_research::sat::SolutionCallback *arg1 = (operations_research::sat::SolutionCallback *) 0 ;
890 
891  (void)jenv;
892  (void)jcls;
893  (void)jarg1_;
894  arg1 = *(operations_research::sat::SolutionCallback **)&jarg1;
895  ((operations_research::sat::SolutionCallback const *)arg1)->OnSolutionCallback();
896 }
897 
898 
899 SWIGEXPORT jlong JNICALL Java_com_google_ortools_sat_mainJNI_SolutionCallback_1numBooleans(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) {
900  jlong jresult = 0 ;
901  operations_research::sat::SolutionCallback *arg1 = (operations_research::sat::SolutionCallback *) 0 ;
902  int64_t result;
903 
904  (void)jenv;
905  (void)jcls;
906  (void)jarg1_;
907  arg1 = *(operations_research::sat::SolutionCallback **)&jarg1;
908  result = (int64_t)((operations_research::sat::SolutionCallback const *)arg1)->NumBooleans();
909  jresult = (jlong)result;
910  return jresult;
911 }
912 
913 
914 SWIGEXPORT jlong JNICALL Java_com_google_ortools_sat_mainJNI_SolutionCallback_1numBranches(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) {
915  jlong jresult = 0 ;
916  operations_research::sat::SolutionCallback *arg1 = (operations_research::sat::SolutionCallback *) 0 ;
917  int64_t result;
918 
919  (void)jenv;
920  (void)jcls;
921  (void)jarg1_;
922  arg1 = *(operations_research::sat::SolutionCallback **)&jarg1;
923  result = (int64_t)((operations_research::sat::SolutionCallback const *)arg1)->NumBranches();
924  jresult = (jlong)result;
925  return jresult;
926 }
927 
928 
929 SWIGEXPORT jlong JNICALL Java_com_google_ortools_sat_mainJNI_SolutionCallback_1numConflicts(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) {
930  jlong jresult = 0 ;
931  operations_research::sat::SolutionCallback *arg1 = (operations_research::sat::SolutionCallback *) 0 ;
932  int64_t result;
933 
934  (void)jenv;
935  (void)jcls;
936  (void)jarg1_;
937  arg1 = *(operations_research::sat::SolutionCallback **)&jarg1;
938  result = (int64_t)((operations_research::sat::SolutionCallback const *)arg1)->NumConflicts();
939  jresult = (jlong)result;
940  return jresult;
941 }
942 
943 
944 SWIGEXPORT jlong JNICALL Java_com_google_ortools_sat_mainJNI_SolutionCallback_1numBinaryPropagations(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) {
945  jlong jresult = 0 ;
946  operations_research::sat::SolutionCallback *arg1 = (operations_research::sat::SolutionCallback *) 0 ;
947  int64_t result;
948 
949  (void)jenv;
950  (void)jcls;
951  (void)jarg1_;
952  arg1 = *(operations_research::sat::SolutionCallback **)&jarg1;
953  result = (int64_t)((operations_research::sat::SolutionCallback const *)arg1)->NumBinaryPropagations();
954  jresult = (jlong)result;
955  return jresult;
956 }
957 
958 
959 SWIGEXPORT jlong JNICALL Java_com_google_ortools_sat_mainJNI_SolutionCallback_1numIntegerPropagations(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) {
960  jlong jresult = 0 ;
961  operations_research::sat::SolutionCallback *arg1 = (operations_research::sat::SolutionCallback *) 0 ;
962  int64_t result;
963 
964  (void)jenv;
965  (void)jcls;
966  (void)jarg1_;
967  arg1 = *(operations_research::sat::SolutionCallback **)&jarg1;
968  result = (int64_t)((operations_research::sat::SolutionCallback const *)arg1)->NumIntegerPropagations();
969  jresult = (jlong)result;
970  return jresult;
971 }
972 
973 
974 SWIGEXPORT jdouble JNICALL Java_com_google_ortools_sat_mainJNI_SolutionCallback_1wallTime(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) {
975  jdouble jresult = 0 ;
976  operations_research::sat::SolutionCallback *arg1 = (operations_research::sat::SolutionCallback *) 0 ;
977  double result;
978 
979  (void)jenv;
980  (void)jcls;
981  (void)jarg1_;
982  arg1 = *(operations_research::sat::SolutionCallback **)&jarg1;
983  result = (double)((operations_research::sat::SolutionCallback const *)arg1)->WallTime();
984  jresult = (jdouble)result;
985  return jresult;
986 }
987 
988 
989 SWIGEXPORT jdouble JNICALL Java_com_google_ortools_sat_mainJNI_SolutionCallback_1userTime(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) {
990  jdouble jresult = 0 ;
991  operations_research::sat::SolutionCallback *arg1 = (operations_research::sat::SolutionCallback *) 0 ;
992  double result;
993 
994  (void)jenv;
995  (void)jcls;
996  (void)jarg1_;
997  arg1 = *(operations_research::sat::SolutionCallback **)&jarg1;
998  result = (double)((operations_research::sat::SolutionCallback const *)arg1)->UserTime();
999  jresult = (jdouble)result;
1000  return jresult;
1001 }
1002 
1003 
1004 SWIGEXPORT jdouble JNICALL Java_com_google_ortools_sat_mainJNI_SolutionCallback_1objectiveValue(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) {
1005  jdouble jresult = 0 ;
1006  operations_research::sat::SolutionCallback *arg1 = (operations_research::sat::SolutionCallback *) 0 ;
1007  double result;
1008 
1009  (void)jenv;
1010  (void)jcls;
1011  (void)jarg1_;
1012  arg1 = *(operations_research::sat::SolutionCallback **)&jarg1;
1013  result = (double)((operations_research::sat::SolutionCallback const *)arg1)->ObjectiveValue();
1014  jresult = (jdouble)result;
1015  return jresult;
1016 }
1017 
1018 
1019 SWIGEXPORT jdouble JNICALL Java_com_google_ortools_sat_mainJNI_SolutionCallback_1bestObjectiveBound(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) {
1020  jdouble jresult = 0 ;
1021  operations_research::sat::SolutionCallback *arg1 = (operations_research::sat::SolutionCallback *) 0 ;
1022  double result;
1023 
1024  (void)jenv;
1025  (void)jcls;
1026  (void)jarg1_;
1027  arg1 = *(operations_research::sat::SolutionCallback **)&jarg1;
1028  result = (double)((operations_research::sat::SolutionCallback const *)arg1)->BestObjectiveBound();
1029  jresult = (jdouble)result;
1030  return jresult;
1031 }
1032 
1033 
1034 SWIGEXPORT jlong JNICALL Java_com_google_ortools_sat_mainJNI_SolutionCallback_1solutionIntegerValue(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jint jarg2) {
1035  jlong jresult = 0 ;
1036  operations_research::sat::SolutionCallback *arg1 = (operations_research::sat::SolutionCallback *) 0 ;
1037  int arg2 ;
1038  int64_t result;
1039 
1040  (void)jenv;
1041  (void)jcls;
1042  (void)jarg1_;
1043  arg1 = *(operations_research::sat::SolutionCallback **)&jarg1;
1044  arg2 = (int)jarg2;
1045  result = (int64_t)(arg1)->SolutionIntegerValue(arg2);
1046  jresult = (jlong)result;
1047  return jresult;
1048 }
1049 
1050 
1051 SWIGEXPORT jboolean JNICALL Java_com_google_ortools_sat_mainJNI_SolutionCallback_1solutionBooleanValue(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jint jarg2) {
1052  jboolean jresult = 0 ;
1053  operations_research::sat::SolutionCallback *arg1 = (operations_research::sat::SolutionCallback *) 0 ;
1054  int arg2 ;
1055  bool result;
1056 
1057  (void)jenv;
1058  (void)jcls;
1059  (void)jarg1_;
1060  arg1 = *(operations_research::sat::SolutionCallback **)&jarg1;
1061  arg2 = (int)jarg2;
1062  result = (bool)(arg1)->SolutionBooleanValue(arg2);
1063  jresult = (jboolean)result;
1064  return jresult;
1065 }
1066 
1067 
1068 SWIGEXPORT void JNICALL Java_com_google_ortools_sat_mainJNI_SolutionCallback_1stopSearch(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) {
1069  operations_research::sat::SolutionCallback *arg1 = (operations_research::sat::SolutionCallback *) 0 ;
1070 
1071  (void)jenv;
1072  (void)jcls;
1073  (void)jarg1_;
1074  arg1 = *(operations_research::sat::SolutionCallback **)&jarg1;
1075  (arg1)->StopSearch();
1076 }
1077 
1078 
1080  jlong jresult = 0 ;
1081  operations_research::sat::SolutionCallback *result = 0 ;
1082 
1083  (void)jenv;
1084  (void)jcls;
1085  result = (operations_research::sat::SolutionCallback *)new SwigDirector_SolutionCallback(jenv);
1086  *(operations_research::sat::SolutionCallback **)&jresult = result;
1087  return jresult;
1088 }
1089 
1090 
1091 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) {
1092  operations_research::sat::SolutionCallback *obj = *((operations_research::sat::SolutionCallback **)&objarg);
1093  (void)jcls;
1094  SwigDirector_SolutionCallback *director = static_cast<SwigDirector_SolutionCallback *>(obj);
1095  director->swig_connect_director(jenv, jself, jenv->GetObjectClass(jself), (jswig_mem_own == JNI_TRUE), (jweak_global == JNI_TRUE));
1096 }
1097 
1098 
1099 SWIGEXPORT void JNICALL Java_com_google_ortools_sat_mainJNI_SolutionCallback_1change_1ownership(JNIEnv *jenv, jclass jcls, jobject jself, jlong objarg, jboolean jtake_or_release) {
1100  operations_research::sat::SolutionCallback *obj = *((operations_research::sat::SolutionCallback **)&objarg);
1101  SwigDirector_SolutionCallback *director = dynamic_cast<SwigDirector_SolutionCallback *>(obj);
1102  (void)jcls;
1103  if (director) {
1104  director->swig_java_change_ownership(jenv, jself, jtake_or_release ? true : false);
1105  }
1106 }
1107 
1108 
1109 SWIGEXPORT void JNICALL Java_com_google_ortools_sat_mainJNI_SolveWrapper_1setParameters(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jbyteArray jarg2) {
1110  operations_research::sat::SolveWrapper *arg1 = (operations_research::sat::SolveWrapper *) 0 ;
1111  operations_research::sat::SatParameters *arg2 = 0 ;
1112  operations_research::sat::SatParameters temp2 ;
1113 
1114  (void)jenv;
1115  (void)jcls;
1116  (void)jarg1_;
1117  arg1 = *(operations_research::sat::SolveWrapper **)&jarg1;
1118  {
1119  int proto_size = 0;
1120  std::unique_ptr<char[]> proto_buffer(
1121  JNIUtil::MakeCharArray(jenv, jarg2, &proto_size));
1122  bool parsed_ok = temp2.ParseFromArray(proto_buffer.get(), proto_size);
1123  if (!parsed_ok) {
1126  "Unable to parse operations_research::sat::SatParameters protocol message.");
1127  }
1128  arg2 = &temp2;
1129  }
1130  (arg1)->SetParameters((operations_research::sat::SatParameters const &)*arg2);
1131 }
1132 
1133 
1134 SWIGEXPORT void JNICALL Java_com_google_ortools_sat_mainJNI_SolveWrapper_1addSolutionCallback(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jlong jarg2, jobject jarg2_) {
1135  operations_research::sat::SolveWrapper *arg1 = (operations_research::sat::SolveWrapper *) 0 ;
1136  operations_research::sat::SolutionCallback *arg2 = 0 ;
1137 
1138  (void)jenv;
1139  (void)jcls;
1140  (void)jarg1_;
1141  (void)jarg2_;
1142  arg1 = *(operations_research::sat::SolveWrapper **)&jarg1;
1143  arg2 = *(operations_research::sat::SolutionCallback **)&jarg2;
1144  if (!arg2) {
1145  SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "operations_research::sat::SolutionCallback const & reference is null");
1146  return ;
1147  }
1148  (arg1)->AddSolutionCallback((operations_research::sat::SolutionCallback const &)*arg2);
1149 }
1150 
1151 
1152 SWIGEXPORT void JNICALL Java_com_google_ortools_sat_mainJNI_SolveWrapper_1clearSolutionCallback(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jlong jarg2, jobject jarg2_) {
1153  operations_research::sat::SolveWrapper *arg1 = (operations_research::sat::SolveWrapper *) 0 ;
1154  operations_research::sat::SolutionCallback *arg2 = 0 ;
1155 
1156  (void)jenv;
1157  (void)jcls;
1158  (void)jarg1_;
1159  (void)jarg2_;
1160  arg1 = *(operations_research::sat::SolveWrapper **)&jarg1;
1161  arg2 = *(operations_research::sat::SolutionCallback **)&jarg2;
1162  if (!arg2) {
1163  SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "operations_research::sat::SolutionCallback const & reference is null");
1164  return ;
1165  }
1166  (arg1)->ClearSolutionCallback((operations_research::sat::SolutionCallback const &)*arg2);
1167 }
1168 
1169 
1170 SWIGEXPORT void JNICALL Java_com_google_ortools_sat_mainJNI_SolveWrapper_1addLogCallback(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jobject jarg2) {
1171  operations_research::sat::SolveWrapper *arg1 = (operations_research::sat::SolveWrapper *) 0 ;
1172  SwigValueWrapper< std::function< void (std::string const &) > > arg2 ;
1173 
1174  (void)jenv;
1175  (void)jcls;
1176  (void)jarg1_;
1177  arg1 = *(operations_research::sat::SolveWrapper **)&jarg1;
1178 
1179  jclass jarg2_object_class = jenv->GetObjectClass(jarg2);
1180  if (nullptr == jarg2_object_class) return ;
1181 
1182 
1183  jmethodID jarg2_method_id = jenv->GetMethodID(
1184  jarg2_object_class, "accept", "(Ljava/lang/Object;)V");
1185  assert(jarg2_method_id != nullptr);
1186  // jarg2 will be deleted once this function return.
1187  jobject jarg2_object = jenv->NewGlobalRef(jarg2);
1188 
1189  // Global JNI reference deleter
1190  auto jarg2_guard = std::make_shared<GlobalRefGuard>(jenv, jarg2_object);
1191  arg2 = [jenv, jarg2_object, jarg2_method_id, jarg2_guard](
1192  const std::string& message) -> void {
1193  return jenv->CallVoidMethod(jarg2_object, jarg2_method_id,
1194  (jenv)->NewStringUTF(message.c_str()));
1195  };
1196 
1197  (arg1)->AddLogCallback(arg2);
1198 }
1199 
1200 
1201 SWIGEXPORT jbyteArray JNICALL Java_com_google_ortools_sat_mainJNI_SolveWrapper_1solve(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jbyteArray jarg2) {
1202  jbyteArray jresult = 0 ;
1203  operations_research::sat::SolveWrapper *arg1 = (operations_research::sat::SolveWrapper *) 0 ;
1204  operations_research::sat::CpModelProto *arg2 = 0 ;
1205  operations_research::sat::CpModelProto temp2 ;
1206  operations_research::sat::CpSolverResponse result;
1207 
1208  (void)jenv;
1209  (void)jcls;
1210  (void)jarg1_;
1211  arg1 = *(operations_research::sat::SolveWrapper **)&jarg1;
1212  {
1213  int proto_size = 0;
1214  std::unique_ptr<char[]> proto_buffer(
1215  JNIUtil::MakeCharArray(jenv, jarg2, &proto_size));
1216  bool parsed_ok = temp2.ParseFromArray(proto_buffer.get(), proto_size);
1217  if (!parsed_ok) {
1220  "Unable to parse operations_research::sat::CpModelProto protocol message.");
1221  }
1222  arg2 = &temp2;
1223  }
1224  result = (arg1)->Solve((operations_research::sat::CpModelProto const &)*arg2);
1225  {
1226  const long size = (&result)->ByteSizeLong();
1227  std::unique_ptr<char[]> buf(new char[size]);
1228  (&result)->SerializeWithCachedSizesToArray(reinterpret_cast<uint8_t*>(buf.get()));
1229  jresult = JNIUtil::MakeJByteArray(jenv, buf.get(), size);
1230  }
1231  return jresult;
1232 }
1233 
1234 
1235 SWIGEXPORT void JNICALL Java_com_google_ortools_sat_mainJNI_SolveWrapper_1stopSearch(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) {
1236  operations_research::sat::SolveWrapper *arg1 = (operations_research::sat::SolveWrapper *) 0 ;
1237 
1238  (void)jenv;
1239  (void)jcls;
1240  (void)jarg1_;
1241  arg1 = *(operations_research::sat::SolveWrapper **)&jarg1;
1242  (arg1)->StopSearch();
1243 }
1244 
1245 
1246 SWIGEXPORT jlong JNICALL Java_com_google_ortools_sat_mainJNI_new_1SolveWrapper(JNIEnv *jenv, jclass jcls) {
1247  jlong jresult = 0 ;
1248  operations_research::sat::SolveWrapper *result = 0 ;
1249 
1250  (void)jenv;
1251  (void)jcls;
1252  result = (operations_research::sat::SolveWrapper *)new operations_research::sat::SolveWrapper();
1253  *(operations_research::sat::SolveWrapper **)&jresult = result;
1254  return jresult;
1255 }
1256 
1257 
1258 SWIGEXPORT void JNICALL Java_com_google_ortools_sat_mainJNI_delete_1SolveWrapper(JNIEnv *jenv, jclass jcls, jlong jarg1) {
1259  operations_research::sat::SolveWrapper *arg1 = (operations_research::sat::SolveWrapper *) 0 ;
1260 
1261  (void)jenv;
1262  (void)jcls;
1263  arg1 = *(operations_research::sat::SolveWrapper **)&jarg1;
1264  delete arg1;
1265 }
1266 
1267 
1268 SWIGEXPORT jstring JNICALL Java_com_google_ortools_sat_mainJNI_CpSatHelper_1modelStats(JNIEnv *jenv, jclass jcls, jbyteArray jarg1) {
1269  jstring jresult = 0 ;
1270  operations_research::sat::CpModelProto *arg1 = 0 ;
1271  operations_research::sat::CpModelProto temp1 ;
1272  std::string result;
1273 
1274  (void)jenv;
1275  (void)jcls;
1276  {
1277  int proto_size = 0;
1278  std::unique_ptr<char[]> proto_buffer(
1279  JNIUtil::MakeCharArray(jenv, jarg1, &proto_size));
1280  bool parsed_ok = temp1.ParseFromArray(proto_buffer.get(), proto_size);
1281  if (!parsed_ok) {
1284  "Unable to parse operations_research::sat::CpModelProto protocol message.");
1285  }
1286  arg1 = &temp1;
1287  }
1288  result = operations_research::sat::CpSatHelper::ModelStats((operations_research::sat::CpModelProto const &)*arg1);
1289  jresult = jenv->NewStringUTF((&result)->c_str());
1290  return jresult;
1291 }
1292 
1293 
1294 SWIGEXPORT jstring JNICALL Java_com_google_ortools_sat_mainJNI_CpSatHelper_1solverResponseStats(JNIEnv *jenv, jclass jcls, jbyteArray jarg1) {
1295  jstring jresult = 0 ;
1296  operations_research::sat::CpSolverResponse *arg1 = 0 ;
1297  operations_research::sat::CpSolverResponse temp1 ;
1298  std::string result;
1299 
1300  (void)jenv;
1301  (void)jcls;
1302  {
1303  int proto_size = 0;
1304  std::unique_ptr<char[]> proto_buffer(
1305  JNIUtil::MakeCharArray(jenv, jarg1, &proto_size));
1306  bool parsed_ok = temp1.ParseFromArray(proto_buffer.get(), proto_size);
1307  if (!parsed_ok) {
1310  "Unable to parse operations_research::sat::CpSolverResponse protocol message.");
1311  }
1312  arg1 = &temp1;
1313  }
1314  result = operations_research::sat::CpSatHelper::SolverResponseStats((operations_research::sat::CpSolverResponse const &)*arg1);
1315  jresult = jenv->NewStringUTF((&result)->c_str());
1316  return jresult;
1317 }
1318 
1319 
1320 SWIGEXPORT jstring JNICALL Java_com_google_ortools_sat_mainJNI_CpSatHelper_1validateModel(JNIEnv *jenv, jclass jcls, jbyteArray jarg1) {
1321  jstring jresult = 0 ;
1322  operations_research::sat::CpModelProto *arg1 = 0 ;
1323  operations_research::sat::CpModelProto temp1 ;
1324  std::string result;
1325 
1326  (void)jenv;
1327  (void)jcls;
1328  {
1329  int proto_size = 0;
1330  std::unique_ptr<char[]> proto_buffer(
1331  JNIUtil::MakeCharArray(jenv, jarg1, &proto_size));
1332  bool parsed_ok = temp1.ParseFromArray(proto_buffer.get(), proto_size);
1333  if (!parsed_ok) {
1336  "Unable to parse operations_research::sat::CpModelProto protocol message.");
1337  }
1338  arg1 = &temp1;
1339  }
1340  result = operations_research::sat::CpSatHelper::ValidateModel((operations_research::sat::CpModelProto const &)*arg1);
1341  jresult = jenv->NewStringUTF((&result)->c_str());
1342  return jresult;
1343 }
1344 
1345 
1346 SWIGEXPORT jlong JNICALL Java_com_google_ortools_sat_mainJNI_CpSatHelper_1variableDomain(JNIEnv *jenv, jclass jcls, jbyteArray jarg1) {
1347  jlong jresult = 0 ;
1348  operations_research::sat::IntegerVariableProto *arg1 = 0 ;
1349  operations_research::sat::IntegerVariableProto temp1 ;
1351 
1352  (void)jenv;
1353  (void)jcls;
1354  {
1355  int proto_size = 0;
1356  std::unique_ptr<char[]> proto_buffer(
1357  JNIUtil::MakeCharArray(jenv, jarg1, &proto_size));
1358  bool parsed_ok = temp1.ParseFromArray(proto_buffer.get(), proto_size);
1359  if (!parsed_ok) {
1362  "Unable to parse operations_research::sat::IntegerVariableProto protocol message.");
1363  }
1364  arg1 = &temp1;
1365  }
1366  result = operations_research::sat::CpSatHelper::VariableDomain((operations_research::sat::IntegerVariableProto const &)*arg1);
1368  return jresult;
1369 }
1370 
1371 
1372 SWIGEXPORT jboolean JNICALL Java_com_google_ortools_sat_mainJNI_CpSatHelper_1writeModelToFile(JNIEnv *jenv, jclass jcls, jbyteArray jarg1, jstring jarg2) {
1373  jboolean jresult = 0 ;
1374  operations_research::sat::CpModelProto *arg1 = 0 ;
1375  std::string *arg2 = 0 ;
1376  operations_research::sat::CpModelProto temp1 ;
1377  bool result;
1378 
1379  (void)jenv;
1380  (void)jcls;
1381  {
1382  int proto_size = 0;
1383  std::unique_ptr<char[]> proto_buffer(
1384  JNIUtil::MakeCharArray(jenv, jarg1, &proto_size));
1385  bool parsed_ok = temp1.ParseFromArray(proto_buffer.get(), proto_size);
1386  if (!parsed_ok) {
1389  "Unable to parse operations_research::sat::CpModelProto protocol message.");
1390  }
1391  arg1 = &temp1;
1392  }
1393  if(!jarg2) {
1395  return 0;
1396  }
1397  const char *arg2_pstr = (const char *)jenv->GetStringUTFChars(jarg2, 0);
1398  if (!arg2_pstr) return 0;
1399  std::string arg2_str(arg2_pstr);
1400  arg2 = &arg2_str;
1401  jenv->ReleaseStringUTFChars(jarg2, arg2_pstr);
1402  result = (bool)operations_research::sat::CpSatHelper::WriteModelToFile((operations_research::sat::CpModelProto const &)*arg1,(std::string const &)*arg2);
1403  jresult = (jboolean)result;
1404  return jresult;
1405 }
1406 
1407 
1408 SWIGEXPORT jlong JNICALL Java_com_google_ortools_sat_mainJNI_new_1CpSatHelper(JNIEnv *jenv, jclass jcls) {
1409  jlong jresult = 0 ;
1410  operations_research::sat::CpSatHelper *result = 0 ;
1411 
1412  (void)jenv;
1413  (void)jcls;
1414  result = (operations_research::sat::CpSatHelper *)new operations_research::sat::CpSatHelper();
1415  *(operations_research::sat::CpSatHelper **)&jresult = result;
1416  return jresult;
1417 }
1418 
1419 
1420 SWIGEXPORT void JNICALL Java_com_google_ortools_sat_mainJNI_delete_1CpSatHelper(JNIEnv *jenv, jclass jcls, jlong jarg1) {
1421  operations_research::sat::CpSatHelper *arg1 = (operations_research::sat::CpSatHelper *) 0 ;
1422 
1423  (void)jenv;
1424  (void)jcls;
1425  arg1 = *(operations_research::sat::CpSatHelper **)&jarg1;
1426  delete arg1;
1427 }
1428 
1429 
1431  int i;
1432 
1433  static struct {
1434  const char *method;
1435  const char *signature;
1436  } methods[1] = {
1437  {
1438  "SwigDirector_SolutionCallback_onSolutionCallback", "(Lcom/google/ortools/sat/SolutionCallback;)V"
1439  }
1440  };
1441  Swig::jclass_mainJNI = (jclass) jenv->NewGlobalRef(jcls);
1442  if (!Swig::jclass_mainJNI) return;
1443  for (i = 0; i < (int) (sizeof(methods)/sizeof(methods[0])); ++i) {
1444  Swig::director_method_ids[i] = jenv->GetStaticMethodID(jcls, methods[i].method, methods[i].signature);
1445  if (!Swig::director_method_ids[i]) return;
1446  }
1447 }
1448 
1449 
1450 #ifdef __cplusplus
1451 }
1452 #endif
1453 
GlobalRefGuard(JNIEnv *jenv, jobject jref)
static jbyteArray MakeJByteArray(JNIEnv *env, const char *a, int size)
Definition: jniutil.h:59
static char * MakeCharArray(JNIEnv *env, jbyteArray a, int *size)
Definition: jniutil.h:47
bool & operator[](size_t n)
bool operator[](size_t n) const
JNIEnvWrapper(const Director *director)
static void raise(JNIEnv *jenv, jthrowable throwable)
void raiseJavaException(JNIEnv *jenv) const
const char * what() const
DirectorException(const char *msg)
DirectorException(JNIEnv *jenv, jthrowable throwable)
void throwException(JNIEnv *jenv) const
PyObject * swig_get_self() const
virtual ~Director()
jobject swig_get_self(JNIEnv *jenv) const
bool swig_set_self(JNIEnv *jenv, jobject jself, bool mem_own, bool weak_global)
void swig_disconnect_director_self(const char *disconn_method)
void swig_java_change_ownership(JNIEnv *jenv, jobject jself, bool take_or_release)
void release(JNIEnv *jenv)
bool set(JNIEnv *jenv, jobject jobj, bool mem_own, bool weak_global)
void java_change_ownership(JNIEnv *jenv, jobject jself, bool take_or_release)
jobject get(JNIEnv *jenv) const
JavaExceptionMessage(JNIEnv *jenv, jthrowable throwable)
const char * message(const char *null_string="Could not get exception message in JavaExceptionMessage") const
JavaString(JNIEnv *jenv, jstring jstr)
const char * c_str(const char *null_string="null JavaString") const
LocalRefGuard(JNIEnv *jenv, jobject jobj)
void swig_connect_director(SWIG_Callback0_t callbackOnSolutionCallback)
virtual void OnSolutionCallback() const
Swig::BoolArray< 1 > swig_override
Definition: sat_java_wrap.h:26
We call domain any subset of Int64 = [kint64min, kint64max].
const std::string name
SWIGINTERN bool ExceptionMatches(JNIEnv *jenv, jthrowable throwable, const char *classname)
absl::Status ValidateModel(const ModelProto &model, const bool check_names)
CpSolverResponse Solve(const CpModelProto &model_proto)
Solves the given CpModelProto and returns an instance of CpSolverResponse.
Collection of objects used to extend the Constraint Solver library.
SWIGEXPORT void JNICALL Java_com_google_ortools_sat_mainJNI_delete_1SolveWrapper(JNIEnv *jenv, jclass jcls, jlong jarg1)
SWIGEXPORT jstring JNICALL Java_com_google_ortools_sat_mainJNI_CpSatHelper_1validateModel(JNIEnv *jenv, jclass jcls, jbyteArray jarg1)
SWIGEXPORT void JNICALL Java_com_google_ortools_sat_mainJNI_SolveWrapper_1setParameters(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jbyteArray jarg2)
SWIGEXPORT jboolean JNICALL Java_com_google_ortools_sat_mainJNI_CpSatHelper_1writeModelToFile(JNIEnv *jenv, jclass jcls, jbyteArray jarg1, jstring jarg2)
SWIGEXPORT jstring JNICALL Java_com_google_ortools_sat_mainJNI_CpSatHelper_1modelStats(JNIEnv *jenv, jclass jcls, jbyteArray jarg1)
SWIGEXPORT void JNICALL Java_com_google_ortools_sat_mainJNI_SolutionCallback_1stopSearch(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_)
SWIGEXPORT jlong JNICALL Java_com_google_ortools_sat_mainJNI_new_1CpSatHelper(JNIEnv *jenv, jclass jcls)
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_SolutionCallback_1solutionIntegerValue(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jint jarg2)
SWIGEXPORT jdouble JNICALL Java_com_google_ortools_sat_mainJNI_SolutionCallback_1userTime(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_)
SWIGEXPORT jlong JNICALL Java_com_google_ortools_sat_mainJNI_CpSatHelper_1variableDomain(JNIEnv *jenv, jclass jcls, jbyteArray jarg1)
SWIGEXPORT jstring JNICALL Java_com_google_ortools_sat_mainJNI_CpSatHelper_1solverResponseStats(JNIEnv *jenv, jclass jcls, jbyteArray jarg1)
SWIGEXPORT void JNICALL Java_com_google_ortools_sat_mainJNI_SolveWrapper_1addLogCallback(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jobject jarg2)
#define SWIGUNUSED
static void SWIGUNUSED SWIG_JavaThrowException(JNIEnv *jenv, SWIG_JavaExceptionCodes code, const char *msg)
SWIG_JavaExceptionCodes
@ SWIG_JavaIOException
@ SWIG_JavaArithmeticException
@ SWIG_JavaUnknownError
@ SWIG_JavaRuntimeException
@ SWIG_JavaNullPointerException
@ SWIG_JavaDirectorPureVirtual
@ SWIG_JavaOutOfMemoryError
@ SWIG_JavaIllegalStateException
@ SWIG_JavaIllegalArgumentException
@ SWIG_JavaIndexOutOfBoundsException
SWIGEXPORT jlong JNICALL Java_com_google_ortools_sat_mainJNI_SolutionCallback_1numBranches(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_)
SWIGEXPORT jlong JNICALL Java_com_google_ortools_sat_mainJNI_SolutionCallback_1numConflicts(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_)
SWIGEXPORT void JNICALL Java_com_google_ortools_sat_mainJNI_SolutionCallback_1onSolutionCallback(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_)
#define SWIGINTERN
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_new_1SolutionCallback(JNIEnv *jenv, jclass jcls)
SWIGEXPORT void JNICALL Java_com_google_ortools_sat_mainJNI_SolveWrapper_1addSolutionCallback(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jlong jarg2, jobject jarg2_)
SWIGEXPORT jlong JNICALL Java_com_google_ortools_sat_mainJNI_new_1SolveWrapper(JNIEnv *jenv, jclass jcls)
SWIGEXPORT void JNICALL Java_com_google_ortools_sat_mainJNI_delete_1CpSatHelper(JNIEnv *jenv, jclass jcls, jlong jarg1)
SWIGEXPORT jlong JNICALL Java_com_google_ortools_sat_mainJNI_SolutionCallback_1numIntegerPropagations(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_)
SWIGEXPORT void JNICALL Java_com_google_ortools_sat_mainJNI_delete_1SolutionCallback(JNIEnv *jenv, jclass jcls, jlong jarg1)
SWIGEXPORT jboolean JNICALL Java_com_google_ortools_sat_mainJNI_SolutionCallback_1solutionBooleanValue(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jint jarg2)
SWIGEXPORT void JNICALL Java_com_google_ortools_sat_mainJNI_SolveWrapper_1clearSolutionCallback(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jlong jarg2, jobject jarg2_)
#define SWIGEXPORT
SWIGEXPORT jbyteArray JNICALL Java_com_google_ortools_sat_mainJNI_SolveWrapper_1solve(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jbyteArray jarg2)
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_swig_1module_1init(JNIEnv *jenv, jclass jcls)
SWIGEXPORT jlong JNICALL Java_com_google_ortools_sat_mainJNI_SolutionCallback_1numBinaryPropagations(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_)
SWIGEXPORT jdouble JNICALL Java_com_google_ortools_sat_mainJNI_SolutionCallback_1objectiveValue(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_)
SWIGEXPORT void JNICALL Java_com_google_ortools_sat_mainJNI_SolutionCallback_1change_1ownership(JNIEnv *jenv, jclass jcls, jobject jself, jlong objarg, jboolean jtake_or_release)
SWIGEXPORT jdouble JNICALL Java_com_google_ortools_sat_mainJNI_SolutionCallback_1wallTime(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_)
SWIG_JavaExceptionCodes code
std::string message
Definition: trace.cc:398