1 /* Domain-independent part of the Java interface: declarations.
2    Copyright (C) 2001-2010 Roberto Bagnara <bagnara@cs.unipr.it>
3    Copyright (C) 2010-2016 BUGSENG srl (http://bugseng.com)
4 
5 This file is part of the Parma Polyhedra Library (PPL).
6 
7 The PPL is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 The PPL is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software Foundation,
19 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA.
20 
21 For the most up-to-date information see the Parma Polyhedra Library
22 site: http://bugseng.com/products/ppl/ . */
23 
24 #ifndef PPL_ppl_java_common_defs_hh
25 #define PPL_ppl_java_common_defs_hh 1
26 
27 #define PPL_NO_AUTOMATIC_INITIALIZATION
28 #include "ppl.hh"
29 
30 #include <jni.h>
31 #include "interfaced_boxes.hh"
32 #include "marked_pointers.hh"
33 
34 #define PPL_JAVA_UNEXPECTED \
35   throw std::runtime_error("PPL Java interface internal error")
36 
37 #define CATCH_ALL \
38   catch(const Java_ExceptionOccurred& e) { \
39   } \
40   catch(const std::overflow_error& e) { \
41     handle_exception(env, e); \
42   } \
43   catch(const std::length_error& e) { \
44     handle_exception(env, e); \
45   } \
46   catch (const std::bad_alloc& e) { \
47     handle_exception(env, e); \
48   } \
49   catch (const std::domain_error& e) { \
50     handle_exception(env, e); \
51   } \
52  catch (const std::invalid_argument& e) { \
53     handle_exception(env, e); \
54   } \
55  catch(const std::logic_error& e) { \
56     handle_exception(env, e); \
57   } \
58   catch (const std::exception& e) { \
59     handle_exception(env, e); \
60   } \
61   catch (const timeout_exception& e) { \
62     handle_exception(env, e); \
63   } \
64   catch (const deterministic_timeout_exception& e) { \
65     handle_exception(env, e); \
66   } \
67   catch (...) { \
68     handle_exception(env); \
69   }
70 
71 #define CHECK_EXCEPTION_ASSERT(env)      \
72   assert(!env->ExceptionOccurred())
73 #define CHECK_EXCEPTION_THROW(env)       \
74   do {                                   \
75     if (env->ExceptionOccurred())        \
76       throw Java_ExceptionOccurred();    \
77   } while (0)
78 #define CHECK_EXCEPTION_RETURN(env, val) \
79   do {                                   \
80     if (env->ExceptionOccurred())        \
81       return val;                        \
82   } while (0)
83 #define CHECK_EXCEPTION_RETURN_VOID(env) \
84   do {                                   \
85     if (env->ExceptionOccurred())        \
86       return;                            \
87   } while (0)
88 #define CHECK_RESULT_ABORT(env, cond)    \
89   do {                                   \
90     if (!(cond))                         \
91       abort();                           \
92   } while (0)
93 #define CHECK_RESULT_ASSERT(env, cond)   \
94   assert(cond)
95 #define CHECK_RESULT_THROW(env, cond)    \
96   do {                                   \
97     if (!(cond))                         \
98       throw Java_ExceptionOccurred();    \
99   } while (0)
100 #define CHECK_RESULT_RETURN(env, cond, val)   \
101   do {                                        \
102     if (!(cond))                              \
103       return val;                             \
104   } while (0)
105 #define CHECK_RESULT_RETURN_VOID(env, cond)   \
106   do {                                        \
107     if (!(cond))                              \
108       return;                                 \
109   } while (0)
110 
111 
112 namespace Parma_Polyhedra_Library {
113 
114 namespace Interfaces {
115 
116 namespace Java {
117 
118 struct Java_ExceptionOccurred : public std::exception {
119 };
120 
121 class timeout_exception
122   : public Parma_Polyhedra_Library::Throwable {
123 public:
throw_me() const124   void throw_me() const {
125     throw *this;
126   }
priority() const127   int priority() const {
128     return 0;
129   }
130 };
131 
132 class deterministic_timeout_exception
133   : public Parma_Polyhedra_Library::Throwable {
134 public:
throw_me() const135   void throw_me() const {
136     throw *this;
137   }
priority() const138   int priority() const {
139     return 0;
140   }
141 };
142 
143 extern Parma_Polyhedra_Library::Watchdog* p_timeout_object;
144 
145 typedef
146 Parma_Polyhedra_Library::Threshold_Watcher
147 <Parma_Polyhedra_Library::Weightwatch_Traits> Weightwatch;
148 
149 extern Weightwatch* p_deterministic_timeout_object;
150 
151 void reset_timeout();
152 
153 void reset_deterministic_timeout();
154 
155 void
156 handle_exception(JNIEnv* env, const std::logic_error& e);
157 
158 void
159 handle_exception(JNIEnv* env, const std::invalid_argument& e);
160 
161 void
162 handle_exception(JNIEnv* env, const std::domain_error& e);
163 
164 void
165 handle_exception(JNIEnv* env, const std::overflow_error& e);
166 
167 void
168 handle_exception(JNIEnv* env, const std::length_error& e);
169 
170 void
171 handle_exception(JNIEnv* env, const std::bad_alloc&);
172 
173 void
174 handle_exception(JNIEnv* env, const std::exception& e);
175 
176 void
177 handle_exception(JNIEnv* env, const timeout_exception& e);
178 
179 void
180 handle_exception(JNIEnv* env, const deterministic_timeout_exception& e);
181 
182 void
183 handle_exception(JNIEnv* env);
184 
185 //! A cache for global references to Java classes.
186 /*!
187   The cache is loaded by \c Parma_Polyhedra_Library.initialize_library();
188   It is cleared by \c Parma_Polyhedra_Library.finalize_library().
189 */
190 class Java_Class_Cache {
191 public:
192   // The Java VM pointer (not a class, but sometimes needed).
193   JavaVM* jvm;
194   // Non-PPL types.
195   jclass Boolean;
196   jclass Integer;
197   jclass Long;
198   jclass Iterator;
199   // PPL types.
200   jclass Artificial_Parameter;
201   jclass Artificial_Parameter_Sequence;
202   jclass Bounded_Integer_Type_Overflow;
203   jclass Bounded_Integer_Type_Representation;
204   jclass Bounded_Integer_Type_Width;
205   jclass By_Reference;
206   jclass Coefficient;
207   jclass Congruence;
208   jclass Constraint;
209   jclass Generator;
210   jclass Grid_Generator;
211   jclass Generator_Type;
212   jclass Grid_Generator_Type;
213   jclass Constraint_System;
214   jclass Congruence_System;
215   jclass Generator_System;
216   jclass Grid_Generator_System;
217   jclass Linear_Expression;
218   jclass Linear_Expression_Coefficient;
219   jclass Linear_Expression_Difference;
220   jclass Linear_Expression_Sum;
221   jclass Linear_Expression_Times;
222   jclass Linear_Expression_Unary_Minus;
223   jclass Linear_Expression_Variable;
224   jclass MIP_Problem_Status;
225   jclass Optimization_Mode;
226   jclass Pair;
227   jclass PIP_Problem_Control_Parameter_Name;
228   jclass PIP_Problem_Control_Parameter_Value;
229   jclass PIP_Problem_Status;
230   jclass Poly_Con_Relation;
231   jclass Poly_Gen_Relation;
232   jclass PPL_Object;
233   jclass Relation_Symbol;
234   jclass Variable;
235   jclass Variable_Stringifier;
236   jclass Variables_Set;
237 
238   //! Default constructor.
239   Java_Class_Cache();
240 
241   //! Initializes all cache fields.
242   void init_cache(JNIEnv* env);
243 
244   //! Resets all fields to \c NULL.
245   void clear_cache(JNIEnv* env);
246 
247 private:
248   //! Sets \p field to a global reference to Java class called \p name.
249   void init_cache(JNIEnv* env, jclass& field, const char* name);
250 
251   //! Resets \p field to \c NULL, deleting the global reference (if any).
252   void clear_cache(JNIEnv* env, jclass& field);
253 
254   // Private and not implemented: copy construction not allowed.
255   Java_Class_Cache(const Java_Class_Cache&);
256   // Private and not implemented: copy assignment not allowed.
257   Java_Class_Cache& operator=(const Java_Class_Cache&);
258 };
259 
260 //! A cache for field and method IDs of Java classes.
261 /*!
262   The IDs for fields and methods of PPL Java classes are automatically
263   by the static initializer of the corresponding Java class.
264   The static initializers of some PPL Java class also stores the IDs
265   for fields and methods of non-PPL classes (e.g., Boolean, Long, etc.).
266 */
267 struct Java_FMID_Cache {
268   // Non-PPL type method IDs: stored when loading Coefficient.
269   jmethodID Boolean_valueOf_ID;
270   jmethodID Boolean_boolValue_ID;
271   jmethodID Integer_valueOf_ID;
272   jmethodID Integer_intValue_ID;
273   jmethodID Long_valueOf_ID;
274   jmethodID Long_longValue_ID;
275 
276   // PPL type field and method IDs.
277   // Artificial_Parameter.
278   jfieldID Artificial_Parameter_le_ID;
279   jfieldID Artificial_Parameter_den_ID;
280   jmethodID Artificial_Parameter_init_ID;
281   jmethodID Artificial_Parameter_Sequence_init_ID;
282   jmethodID Artificial_Parameter_Sequence_add_ID;
283   // Bounded_Integer_Type_Overflow.
284   jfieldID Bounded_Integer_Type_Overflow_OVERFLOW_WRAPS_ID;
285   jfieldID Bounded_Integer_Type_Overflow_OVERFLOW_UNDEFINED_ID;
286   jfieldID Bounded_Integer_Type_Overflow_OVERFLOW_IMPOSSIBLE_ID;
287   jmethodID Bounded_Integer_Type_Overflow_ordinal_ID;
288   // Bounded_Integer_Type_Representation.
289   jfieldID Bounded_Integer_Type_Representation_UNSIGNED_ID;
290   jfieldID Bounded_Integer_Type_Representation_SIGNED_2_COMPLEMENT_ID;
291   jmethodID Bounded_Integer_Type_Representation_ordinal_ID;
292   // Bounded_Integer_Type_Width.
293   jfieldID Bounded_Integer_Type_Width_BITS_8_ID;
294   jfieldID Bounded_Integer_Type_Width_BITS_16_ID;
295   jfieldID Bounded_Integer_Type_Width_BITS_32_ID;
296   jfieldID Bounded_Integer_Type_Width_BITS_64_ID;
297   jfieldID Bounded_Integer_Type_Width_BITS_128_ID;
298   jmethodID Bounded_Integer_Type_Width_ordinal_ID;
299   // By_Reference.
300   jfieldID By_Reference_obj_ID;
301   jmethodID By_Reference_init_ID;
302   // Coefficient.
303   jfieldID Coefficient_value_ID;
304   jmethodID Coefficient_init_from_String_ID;
305   jmethodID Coefficient_toString_ID;
306   // Complexity_Class.
307   jmethodID Complexity_Class_ordinal_ID;
308   // Congruence.
309   jfieldID Congruence_mod_ID;
310   jfieldID Congruence_lhs_ID;
311   jfieldID Congruence_rhs_ID;
312   jmethodID Congruence_init_ID;
313   // Constraint.
314   jfieldID Constraint_lhs_ID;
315   jfieldID Constraint_rhs_ID;
316   jfieldID Constraint_kind_ID;
317   jmethodID Constraint_init_ID;
318   // Degenerate_Element.
319   jmethodID Degenerate_Element_ordinal_ID;
320   // Generator.
321   jfieldID Generator_gt_ID;
322   jfieldID Generator_le_ID;
323   jfieldID Generator_div_ID;
324   jmethodID Generator_line_ID;
325   jmethodID Generator_ray_ID;
326   jmethodID Generator_point_ID;
327   jmethodID Generator_closure_point_ID;
328   // Grid_Generator.
329   jfieldID Grid_Generator_gt_ID;
330   jfieldID Grid_Generator_le_ID;
331   jfieldID Grid_Generator_div_ID;
332   jmethodID Grid_Generator_grid_line_ID;
333   jmethodID Grid_Generator_parameter_ID;
334   jmethodID Grid_Generator_grid_point_ID;
335   // (Grid_) Generator_Type.
336   jmethodID Generator_Type_ordinal_ID;
337   jmethodID Grid_Generator_Type_ordinal_ID;
338   // Systems of Constraint, Congruence, Generator and Grid_Generator.
339   jmethodID Constraint_System_init_ID;
340   jmethodID Constraint_System_add_ID;
341   jmethodID Congruence_System_init_ID;
342   jmethodID Congruence_System_add_ID;
343   jmethodID Generator_System_init_ID;
344   jmethodID Generator_System_add_ID;
345   jmethodID Grid_Generator_System_init_ID;
346   jmethodID Grid_Generator_System_add_ID;
347   // System_Iterator: stored when loading Constraint_System.
348   jmethodID System_iterator_ID;
349   jmethodID System_Iterator_has_next_ID;
350   jmethodID System_Iterator_next_ID;
351   // Linear_Expression.
352   jmethodID Linear_Expression_sum_ID;
353   jmethodID Linear_Expression_times_ID;
354   // Classes extending Linear_Expression.
355   jfieldID Linear_Expression_Coefficient_coeff_ID;
356   jmethodID Linear_Expression_Coefficient_init_ID;
357   jfieldID Linear_Expression_Difference_lhs_ID;
358   jfieldID Linear_Expression_Difference_rhs_ID;
359   jfieldID Linear_Expression_Sum_lhs_ID;
360   jfieldID Linear_Expression_Sum_rhs_ID;
361   jfieldID Linear_Expression_Times_coeff_ID;
362   jfieldID Linear_Expression_Times_lin_expr_ID;
363   jmethodID Linear_Expression_Times_init_from_coeff_var_ID;
364   jfieldID Linear_Expression_Unary_Minus_arg_ID;
365   jmethodID Linear_Expression_Variable_init_ID;
366   jmethodID Linear_Expression_Variable_var_id_ID;
367   // MIP_Problem_Status.
368   jfieldID MIP_Problem_Status_UNFEASIBLE_MIP_PROBLEM_ID;
369   jfieldID MIP_Problem_Status_UNBOUNDED_MIP_PROBLEM_ID;
370   jfieldID MIP_Problem_Status_OPTIMIZED_MIP_PROBLEM_ID;
371   jmethodID MIP_Problem_Status_ordinal_ID;
372   // Optmization_Mode.
373   jfieldID Optimization_Mode_MAXIMIZATION_ID;
374   jfieldID Optimization_Mode_MINIMIZATION_ID;
375   jmethodID Optimization_Mode_ordinal_ID;
376   // PIP_Problem_Control_Parameter_Name.
377   jfieldID PIP_Problem_Control_Parameter_Name_CUTTING_STRATEGY_ID;
378   jfieldID PIP_Problem_Control_Parameter_Name_PIVOT_ROW_STRATEGY;
379   jmethodID PIP_Problem_Control_Parameter_Name_ordinal_ID;
380   // PIP_Problem_Control_Parameter_Value.
381   jfieldID PIP_Problem_Control_Parameter_Value_CUTTING_STRATEGY_FIRST_ID;
382   jfieldID PIP_Problem_Control_Parameter_Value_CUTTING_STRATEGY_DEEPEST_ID;
383   jfieldID PIP_Problem_Control_Parameter_Value_CUTTING_STRATEGY_ALL_ID;
384   jfieldID PIP_Problem_Control_Parameter_Value_PIVOT_ROW_STRATEGY_FIRST_ID;
385   jfieldID PIP_Problem_Control_Parameter_Value_PIVOT_ROW_STRATEGY_MAX_COLUMN_ID;
386   jmethodID PIP_Problem_Control_Parameter_Value_ordinal_ID;
387   // PIP_Problem_Status.
388   jfieldID PIP_Problem_Status_UNFEASIBLE_PIP_PROBLEM_ID;
389   jfieldID PIP_Problem_Status_OPTIMIZED_PIP_PROBLEM_ID;
390   jmethodID PIP_Problem_Status_ordinal_ID;
391   // Pair.
392   jfieldID Pair_first_ID;
393   jfieldID Pair_second_ID;
394   // Poly_Con_Relation and Poly_Gen_Relation.
395   jmethodID Poly_Con_Relation_init_ID;
396   jmethodID Poly_Gen_Relation_init_ID;
397   // PPL_Object.
398   jfieldID PPL_Object_ptr_ID;
399   // Relation_Symbol.
400   jfieldID Relation_Symbol_EQUAL_ID;
401   jfieldID Relation_Symbol_GREATER_OR_EQUAL_ID;
402   jfieldID Relation_Symbol_GREATER_THAN_ID;
403   jmethodID Relation_Symbol_ordinal_ID;
404   // Variable.
405   jfieldID Variable_varid_ID;
406   jfieldID Variable_stringifier_ID;
407   jmethodID Variable_init_ID;
408   // Variable_Stringifier.
409   jmethodID Variable_Stringifier_stringify_ID;
410   // Variables_Set.
411   jmethodID Variables_Set_init_ID;
412   jmethodID Variables_Set_add_ID;
413   jmethodID Variables_Set_iterator_ID;
414   // Iterators on Variables_Set.
415   jmethodID Variables_Set_Iterator_has_next_ID;
416   jmethodID Variables_Set_Iterator_next_ID;
417 };
418 
419 //! The cached class references.
420 extern Java_Class_Cache cached_classes;
421 
422 //! The field and method ID cache.
423 extern Java_FMID_Cache cached_FMIDs;
424 
425 
426 /*! \brief
427   Builds an unsigned C++ number from the Java native number \p value.
428 
429   \param value
430   The Java native number of type V to be converted.
431 
432   \exception std::invalid_argument
433   Thrown if \p value is negative.
434 */
435 template <typename U, typename V>
436 U
437 jtype_to_unsigned(const V& value);
438 
439 //! Builds a Java Boolean from C++ bool \p value.
440 jobject
441 bool_to_j_boolean_class(JNIEnv* env, const bool value);
442 
443 //! Returns the Java int stored in Java Integer \p j_integer.
444 jint
445 j_integer_to_j_int(JNIEnv* env, jobject j_integer);
446 
447 //! Builds a Java Integer from Java int \p value.
448 jobject
449 j_int_to_j_integer(JNIEnv* env, jint value);
450 
451 //! Returns the Java long stored in Java Long \p j_long.
452 jlong
453 j_long_class_to_j_long(JNIEnv* env, jobject j_long);
454 
455 //! Builds a Java Long from Java long \p value.
456 jobject
457 j_long_to_j_long_class(JNIEnv* env, jlong value);
458 
459 /*! \brief
460   Returns \c true if and only if the Java object \p ppl_object
461   refers to a C++ object.
462 */
463 bool
464 is_java_marked(JNIEnv* env, jobject ppl_object);
465 
466 
467 /*! \brief
468   Builds a Java parma_polyhedra_library::Poly_Gen_Relation
469   from C++ Poly_Gen_Relation \p r.
470 */
471 jobject
472 build_java_poly_gen_relation(JNIEnv* env, Poly_Gen_Relation& r);
473 
474 /*! \brief
475   Builds a Java parma_polyhedra_library::Poly_Con_Relation
476   from C++ Poly_Con_Relation \p r.
477 */
478 jobject
479 build_java_poly_con_relation(JNIEnv* env, Poly_Con_Relation& r);
480 
481 /*! \brief
482   Builds a C++ Variables_Set
483   from Java parma_polyhedra_library::Variables_Set \p v_set.
484 */
485 Variables_Set
486 build_cxx_variables_set(JNIEnv* env, jobject v_set);
487 
488 /*! \brief
489   Builds a Java parma_polyhedra_library::Variables_Set
490   from C++ Variables_Set \p v_set.
491 */
492 jobject
493 build_java_variables_set(JNIEnv* env, const Variables_Set& v_set);
494 
495 /*! \brief
496   Builds a C++ Relation_Symbol
497   from Java parma_polyhedra_library::Relation_Symbol \p j_relsym.
498 */
499 Relation_Symbol
500 build_cxx_relsym(JNIEnv* env, jobject j_relsym);
501 
502 /*! \brief
503   Builds a C++ Bounded_Integer_Type_Overflow
504   from Java parma_polyhedra_library::Bounded_Integer_Type_Overflow
505   \p j_bounded_overflow.
506 */
507 Bounded_Integer_Type_Overflow
508 build_cxx_bounded_overflow(JNIEnv* env, jobject j_bounded_overflow);
509 
510 /*! \brief
511   Builds a C++ Bounded_Integer_Type_Width
512   from Java parma_polyhedra_library::Bounded_Integer_Type_Width
513   \p j_bounded_width.
514 */
515 Bounded_Integer_Type_Width
516 build_cxx_bounded_width(JNIEnv* env, jobject j_bounded_width);
517 
518 /*! \brief
519   Builds a C++ Bounded_Integer_Type_Representation
520   from Java parma_polyhedra_library::Bounded_Integer_Type_Representation
521   \p j_bounded_rep.
522 */
523 Bounded_Integer_Type_Representation
524 build_cxx_bounded_rep(JNIEnv* env, jobject j_bounded_rep);
525 
526 /*! \brief
527   Builds a C++ Optimization_Mode
528   from Java parma_polyhedra_library::Optimization_Mode \p j_opt_mode.
529 */
530 Optimization_Mode
531 build_cxx_optimization_mode(JNIEnv* env, jobject j_opt_mode);
532 
533 /*! \brief
534   Builds a Java parma_polyhedra_library::Optimization_Mode
535   from C++ Optimization_Mode \p opt_mode.
536 */
537 jobject
538 build_java_optimization_mode(JNIEnv* env, const Optimization_Mode& opt_mode);
539 
540 /*! \brief
541   Builds a C++ MIP_Problem::Control_Parameter_Name
542   from Java parma_polyhedra_library::Control_Parameter_Name \p j_cp_name.
543 */
544 MIP_Problem::Control_Parameter_Name
545 build_cxx_control_parameter_name(JNIEnv* env, jobject j_cp_name);
546 
547 /*! \brief
548   Builds a Java parma_polyhedra_library::Control_Parameter_Name
549   from C++ MIP_Problem::Control_Parameter_Name \p cp_name.
550 */
551 jobject
552 build_java_control_parameter_name
553 (JNIEnv* env, const MIP_Problem::Control_Parameter_Name& cp_name);
554 
555 /*! \brief
556   Builds a C++ MIP_Problem::Control_Parameter_Value
557   from Java parma_polyhedra_library::Control_Parameter_Value \p j_cp_value.
558 */
559 MIP_Problem::Control_Parameter_Value
560 build_cxx_control_parameter_value(JNIEnv* env, jobject j_cp_value);
561 
562 /*! \brief
563   Builds a Java parma_polyhedra_library::Control_Parameter_Value
564   from C++ MIP_Problem::Control_Parameter_Value \p cp_value.
565 */
566 jobject
567 build_java_control_parameter_value
568 (JNIEnv* env, const MIP_Problem::Control_Parameter_Value& cp_value);
569 
570 /*! \brief
571   Builds a C++ PIP_Problem::Control_Parameter_Name
572   from Java parma_polyhedra_library::PIP_Problem_Control_Parameter_Name
573   \p j_cp_name.
574 */
575 PIP_Problem::Control_Parameter_Name
576 build_cxx_pip_problem_control_parameter_name(JNIEnv* env, jobject j_cp_name);
577 
578 /*! \brief
579   Builds a Java parma_polyhedra_library::PIP_Problem_Control_Parameter_Name
580   from C++ PIP_Problem::Control_Parameter_Name \p cp_name.
581 */
582 jobject
583 build_java_pip_problem_control_parameter_name
584 (JNIEnv* env, const PIP_Problem::Control_Parameter_Name& cp_name);
585 
586 /*! \brief
587   Builds a C++ PIP_Problem::Control_Parameter_Value
588   from Java parma_polyhedra_library::PIP_Problem_Control_Parameter_Value
589   \p j_cp_value.
590 */
591 PIP_Problem::Control_Parameter_Value
592 build_cxx_pip_problem_control_parameter_value(JNIEnv* env, jobject j_cp_value);
593 
594 /*! \brief
595   Builds a Java parma_polyhedra_library::Control_Parameter_Value
596   from C++ PIP_Problem::Control_Parameter_Value \p cp_value.
597 */
598 jobject
599 build_java_pip_problem_control_parameter_value
600 (JNIEnv* env, const PIP_Problem::Control_Parameter_Value& cp_value);
601 
602 /*! \brief
603   Builds a Java parma_polyhedra_library::MIP_Problem_Status
604   from C++ MIP_Problem_Status \p mip_status.
605 */
606 jobject
607 build_java_mip_status(JNIEnv* env, const MIP_Problem_Status& mip_status);
608 
609 /*! \brief
610   Builds a Java parma_polyhedra_library::PIP_Problem_Status
611   from C++ PIP_Problem_Status \p pip_status.
612 */
613 jobject
614 build_java_pip_status(JNIEnv* env, const PIP_Problem_Status& pip_status);
615 
616 /*! \brief
617   Builds a C++ Variable
618   from Java parma_polyhedra_library::Variable \p j_var.
619 */
620 Variable
621 build_cxx_variable(JNIEnv* env, jobject j_var);
622 
623 /*! \brief
624   Builds a Java parma_polyhedra_library::Variable
625   from C++ Variable \p var.
626 */
627 jobject
628 build_java_variable(JNIEnv* env, const Variable var);
629 
630 /*! \brief
631   The customizable variable output function for Java interface.
632 
633   Customization is obtained by providing an object implementing interface
634   <CODE>Variable_Stringifier</CODE> and attaching it to class
635   <CODE>Variable</CODE> using static method <CODE>setStringifier</CODE>.
636 */
637 void
638 Java_Variable_output_function(std::ostream& s, Variable v);
639 
640 /*! \brief
641   Builds a C++ Coefficient
642   from Java parma_polyhedra_library::Coefficient \p j_coeff.
643 */
644 Coefficient
645 build_cxx_coeff(JNIEnv* env, jobject j_coeff);
646 
647 /*! \brief
648   Builds a Java parma_polyhedra_library::Coefficient
649   from C++ Coefficient \p ppl_coeff.
650 */
651 jobject
652 build_java_coeff(JNIEnv* env, const Coefficient& ppl_coeff);
653 
654 /*! \brief
655   Builds a C++ Constraint
656   from Java parma_polyhedra_library::Constraint \p j_constraint.
657 */
658 Constraint
659 build_cxx_constraint(JNIEnv* env, jobject j_constraint);
660 
661 /*! \brief
662   Builds a C++ Artificial_Parameter
663   from Java parma_polyhedra_library::Artificial_Parameter
664   \p j_artificial_parameter.
665 */
666 PIP_Tree_Node::Artificial_Parameter
667 build_cxx_artificial_parameter(JNIEnv* env, jobject j_ap);
668 
669 /*! \brief
670   Builds a C++ Linear_Expression
671   from Java parma_polyhedra_library::Linear_Expression \p j_le.
672 */
673 Linear_Expression
674 build_cxx_linear_expression(JNIEnv* env, jobject j_le);
675 
676 /*! \brief
677   Builds a C++ Congruence
678   from Java parma_polyhedra_library::Congruence \p j_cg.
679 */
680 Congruence
681 build_cxx_congruence(JNIEnv* env, jobject j_cg);
682 
683 /*! \brief
684   Builds a C++ Generator
685   from Java parma_polyhedra_library::Generator \p j_g.
686 */
687 Generator
688 build_cxx_generator(JNIEnv* env, jobject j_g);
689 
690 /*! \brief
691   Builds a C++ Grid_Generator
692   from Java parma_polyhedra_library::Grid_Generator \p j_g.
693 */
694 Grid_Generator
695 build_cxx_grid_generator(JNIEnv* env, jobject j_g);
696 
697 /*! \brief
698   Builds a C++ Grid_Generator_System
699   from Java parma_polyhedra_library::Grid_Generator_System \p j_gs.
700 */
701 Grid_Generator_System
702 build_cxx_grid_generator_system(JNIEnv* env, jobject j_gs);
703 
704 /*! \brief
705   Builds a C++ Constraint_System
706   from Java parma_polyhedra_library::Constraint_System \p j_cs.
707 */
708 Constraint_System
709 build_cxx_constraint_system(JNIEnv* env, jobject j_cs);
710 
711 /*! \brief
712   Builds a C++ Artificial_Parameter
713   from Java parma_polyhedra_library::Artificial_Parameter \p j_art_param.
714 */
715 PIP_Tree_Node::Artificial_Parameter
716 build_cxx_artificial_parameter(JNIEnv* env, jobject j_art_param);
717 
718 /*! \brief
719   Builds a C++ Artificial_Parameter_Sequence
720   from Java parma_polyhedra_library::Artificial_Parameter_Sequence \p j_aps.
721 */
722 PIP_Tree_Node::Artificial_Parameter_Sequence
723 build_cxx_artificial_parameter_sequence(JNIEnv* env, jobject j_aps);
724 
725 /*! \brief
726   Builds a C++ Generator_System
727   from Java parma_polyhedra_library::Generator_System \p j_gs.
728 */
729 Generator_System
730 build_cxx_generator_system(JNIEnv* env, jobject j_gs);
731 
732 /*! \brief
733   Builds a C++ Congruence_System
734   from Java parma_polyhedra_library::Congruence_System \p j_cgs.
735 */
736 Congruence_System
737 build_cxx_congruence_system(JNIEnv* env, jobject j_cgs);
738 
739 /*! \brief
740   Builds a Java parma_polyhedra_library::Constraint
741   from C++ Constraint \p c.
742 */
743 jobject
744 build_java_constraint(JNIEnv* env, const Constraint& c);
745 
746 /*! \brief
747   Builds a Java parma_polyhedra_library::Artificial_Parameter
748   from C++ Artificial_Parameter \p ap.
749 */
750 jobject
751 build_java_artificial_parameter(JNIEnv* env,
752                                 const PIP_Tree_Node::Artificial_Parameter& ap);
753 
754 /*! \brief
755   Builds a Java parma_polyhedra_library::Congruence
756   from C++ Congruence \p cg.
757 */
758 jobject
759 build_java_congruence(JNIEnv* env, const Congruence& cg);
760 
761 /*! \brief
762   Builds a Java parma_polyhedra_library::Generator
763   from C++ Generator \p g.
764 */
765 jobject
766 build_java_generator(JNIEnv* env, const Generator& g);
767 
768 /*! \brief
769   Builds a Java parma_polyhedra_library::Grid_Generator
770   from C++ Grid_Generator \p g.
771 */
772 jobject
773 build_java_grid_generator(JNIEnv* env, const Grid_Generator& g);
774 
775 /*! \brief
776   Builds a Java parma_polyhedra_library::Constraint_System
777   from C++ Constraint_System \p cs.
778 */
779 jobject
780 build_java_constraint_system(JNIEnv* env, const Constraint_System& cs);
781 
782 /*! \brief
783   Builds a Java parma_polyhedra_library::Artificial_Parameter_Sequence
784   from C++ Artificial_Parameter_Sequence \p aps.
785 */
786 jobject
787 build_java_artificial_parameter_sequence
788 (JNIEnv* env, const PIP_Tree_Node::Artificial_Parameter_Sequence& aps);
789 
790 /*! \brief
791   Builds a Java parma_polyhedra_library::Grid_Generator_System
792   from C++ Grid_Generator_System \p gs.
793 */
794 jobject
795 build_java_grid_generator_system(JNIEnv* env, const Grid_Generator_System& gs);
796 
797 /*! \brief
798   Builds a Java parma_polyhedra_library::Generator_System
799   from C++ Generator_System \p gs.
800 */
801 jobject
802 build_java_generator_system(JNIEnv* env, const Generator_System& gs);
803 
804 /*! \brief
805   Builds a Java parma_polyhedra_library::Congruence_System
806   from C++ Congruence_System \p cgs.
807 */
808 jobject
809 build_java_congruence_system(JNIEnv* env, const Congruence_System& cgs);
810 
811 /*! \brief
812   Builds a Java parma_polyhedra_library::Linear_Expression_Coefficient
813   from C++ Coefficient \p coeff.
814 */
815 jobject
816 build_java_linear_expression_coefficient(JNIEnv* env, const Coefficient& coeff);
817 
818 /*! \brief
819   Sets Java parma_polyhedra_library::Generator \p dst
820   to have the same value as \p src.
821 */
822 void
823 set_generator(JNIEnv* env, jobject dst, jobject src);
824 
825 /*! \brief
826   Sets Java Coefficient \p dst to have the same value as \p src.
827 */
828 void
829 set_coefficient(JNIEnv* env, jobject dst, jobject src);
830 
831 /*! \brief
832   Modifies parma_polyhedra_library::By_Reference object \p by_ref_dst
833   so that it references object \p src.
834 */
835 void
836 set_by_reference(JNIEnv* env, jobject by_ref_dst, jobject src);
837 
838 /*! \brief
839   Returns the object referenced by
840   parma_polyhedra_library::By_Reference object \p by_reference.
841 */
842 jobject
843 get_by_reference(JNIEnv* env, jobject by_reference);
844 
845 
846 /*! \brief
847   Assigns \p src to one of the fields of
848   parma_polyhedra_library::Pair object \p dst_pair.
849 
850   If \p arg is 0, the first element of \p dst_pair is overwritten;
851   if \p arg is 1, the second element of \p dst_pair is overwritten.
852 
853   \exception std::runtime_error
854   Thrown if \p arg is neither 0 nor 1.
855 */
856 void
857 set_pair_element(JNIEnv* env, jobject dst_pair, int arg, jobject src);
858 
859 /*! \brief
860   Returns one of the fields of the
861   parma_polyhedra_library::Pair object \p pair.
862 
863   If \p arg is 0, the first element of \p pair is returned;
864   if \p arg is 1, the second element of \p pair is returned.
865 
866   \exception std::runtime_error
867   Thrown if \p arg is neither 0 nor 1.
868 */
869 jobject
870 get_pair_element(JNIEnv* env, int arg, jobject pair);
871 
872 //! Returns a pointer to the C++ object wrapped by \p ppl_object.
873 void*
874 get_ptr(JNIEnv* env, jobject ppl_object);
875 
876 //! Sets the pointer of the underlying C++ object in the Java object.
877 template <typename T>
878 void
879 set_ptr(JNIEnv* env, jobject ppl_object,
880         const T* address, bool to_be_marked = false);
881 
882 /*! \brief
883   Builds a Java parma_polyhedra_library::Linear_Expression
884   from the C++ constraint/congruence \p r.
885 */
886 template <typename R>
887 jobject
888 build_linear_expression(JNIEnv* env, const R& r);
889 
890 } // namespace Java
891 
892 } // namespace Interfaces
893 
894 } // namespace Parma_Polyhedra_Library
895 
896 
897 #include "ppl_java_common_inlines.hh"
898 
899 #endif // !defined(PPL_ppl_prolog_common_defs_hh)
900