24 #ifndef PPL_ppl_java_common_inlines_hh
25 #define PPL_ppl_java_common_inlines_hh 1
31 namespace Interfaces {
35 template <
typename U,
typename V>
37 jtype_to_unsigned(
const V&
value) {
39 throw std::invalid_argument(
"not an unsigned integer.");
41 if (
sizeof(U) <
sizeof(V)) {
42 if (value > static_cast<V>(std::numeric_limits<U>::max()))
43 throw std::invalid_argument(
"unsigned integer out of range.");
51 set_ptr(JNIEnv* env, jobject ppl_object,
52 const T* address,
bool to_be_marked) {
53 const T* ptr = (to_be_marked ? mark(address) : address);
54 jlong pointer_value =
reinterpret_cast<jlong
>(ptr);
55 assert(reinterpret_cast<const T*>(pointer_value) == ptr);
60 get_ptr(JNIEnv* env, jobject ppl_object) {
63 void* ptr =
reinterpret_cast<void*
>(pointer_value);
64 assert(reinterpret_cast<jlong>(ptr) == pointer_value);
69 is_java_marked(JNIEnv* env, jobject ppl_object) {
72 const void* ptr =
reinterpret_cast<const void*
>(pointer_value);
73 assert(reinterpret_cast<jlong>(ptr) == pointer_value);
78 set_coefficient(JNIEnv* env, jobject dst, jobject src) {
85 set_by_reference(JNIEnv* env, jobject by_ref_dst, jobject src) {
86 env->SetObjectField(by_ref_dst,
92 get_by_reference(JNIEnv* env, jobject by_reference) {
98 build_linear_expression(JNIEnv* env,
const R& r) {
103 while (varid < space_dimension
104 && (coefficient = r.coefficient(Variable(varid))) == 0)
106 if (varid >= space_dimension) {
107 jobject j_coefficient_zero = build_java_coeff(env,
Coefficient(0));
114 jmethodID coeff_var_init_ID
116 jobject j_coefficient = build_java_coeff(env, coefficient);
117 jobject j_variable = build_java_variable(env, Variable(varid));
119 jobject j_coeff_var = env->NewObject(j_le_times_class,
121 j_coefficient, j_variable);
126 while (varid < space_dimension
127 && (coefficient = r.coefficient(Variable(varid))) == 0)
129 if (varid >= space_dimension)
132 j_coefficient = build_java_coeff(env, coefficient);
133 j_variable = build_java_variable(env, Variable(varid));
134 j_coeff_var = env->NewObject(j_le_times_class,
136 j_coefficient, j_variable);
138 j_ret = env->CallObjectMethod(j_ret,
149 build_cxx_variable(JNIEnv* env, jobject j_var) {
154 build_java_variable(JNIEnv* env,
const Variable var) {
155 jlong j_var_id = var.id();
156 jobject ret = env->NewObject(cached_classes.
Variable,
164 build_cxx_coeff(JNIEnv* env, jobject j_coeff) {
166 = (jstring) env->CallObjectMethod(j_coeff,
169 const char *nativeString = env->GetStringUTFChars(bi_string, 0);
173 env->ReleaseStringUTFChars(bi_string, nativeString);
178 build_java_coeff(JNIEnv* env,
const Coefficient& ppl_coeff) {
179 std::ostringstream s;
181 std::string str = s.str();
182 jstring coeff_string = env->NewStringUTF(str.c_str());
184 jobject ret = env->NewObject(cached_classes.
Coefficient,
191 template <
typename System,
typename Elem_Builder>
193 build_cxx_system(JNIEnv* env, jobject j_iterable, Elem_Builder build_cxx_elem) {
204 jboolean has_next_value = env->CallBooleanMethod(j_iter, has_next_mID);
206 while (has_next_value) {
207 j_element = env->CallObjectMethod(j_iter, next_mID);
209 cxx_sys.insert(build_cxx_elem(env, j_element));
210 has_next_value = env->CallBooleanMethod(j_iter, has_next_mID);
216 inline Congruence_System
217 build_cxx_congruence_system(JNIEnv* env, jobject j_iterable) {
219 build_cxx_system<Congruence_System>(env, j_iterable, build_cxx_congruence);
222 inline Constraint_System
223 build_cxx_constraint_system(JNIEnv* env, jobject j_iterable) {
225 build_cxx_system<Constraint_System>(env, j_iterable, build_cxx_constraint);
228 inline Generator_System
229 build_cxx_generator_system(JNIEnv* env, jobject j_iterable) {
231 build_cxx_system<Generator_System>(env, j_iterable, build_cxx_generator);
234 inline Grid_Generator_System
235 build_cxx_grid_generator_system(JNIEnv* env, jobject j_iterable) {
236 return build_cxx_system<Grid_Generator_System> (env, j_iterable,
237 build_cxx_grid_generator);
246 #endif // !defined(PPL_ppl_java_common_inlines_hh)
jmethodID Coefficient_toString_ID
jmethodID Coefficient_init_from_String_ID
jmethodID Variable_init_ID
#define CHECK_RESULT_THROW(env, cond)
#define PPL_DIRTY_TEMP_COEFFICIENT(id)
jfieldID Coefficient_value_ID
#define CHECK_EXCEPTION_THROW(env)
jclass Linear_Expression_Coefficient
jmethodID Linear_Expression_sum_ID
jfieldID By_Reference_obj_ID
jmethodID Linear_Expression_Coefficient_init_ID
jmethodID Linear_Expression_Times_init_from_coeff_var_ID
PPL_COEFFICIENT_TYPE Coefficient
jfieldID PPL_Object_ptr_ID
jmethodID System_Iterator_next_ID
jfieldID Variable_varid_ID
jmethodID System_iterator_ID
jclass Linear_Expression_Times
#define CHECK_EXCEPTION_ASSERT(env)
jmethodID System_Iterator_has_next_ID