00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef PPL_ppl_ocaml_common_inlines_hh
00025 #define PPL_ppl_ocaml_common_inlines_hh 1
00026
00027 namespace Parma_Polyhedra_Library {
00028
00029 namespace Interfaces {
00030
00031 namespace OCaml {
00032
00033 template <typename U_Int>
00034 U_Int
00035 value_to_unsigned(value v) {
00036
00037 assert(std::numeric_limits<U_Int>::is_integer
00038 && !std::numeric_limits<U_Int>::is_signed);
00039 if (!Is_long(v)) {
00040 const char* what = "PPL OCaml interface invalid argument error:\n"
00041 "argument is not an integer (expecting a non-negative integer).";
00042 throw std::invalid_argument(what);
00043 }
00044 intnat vv = Long_val(v);
00045 if (vv < 0) {
00046 const char* what = "PPL OCaml interface invalid argument error:\n"
00047 "argument is negative (expecting a non-negative integer).";
00048 throw std::invalid_argument(what);
00049 }
00050 const uintnat u_max = std::numeric_limits<U_Int>::max();
00051 if (static_cast<uintnat>(vv) > u_max) {
00052 const char* what = "PPL OCaml interface invalid argument:\n"
00053 "argument value is too big (expecting a smaller non-negative integer).";
00054 throw std::invalid_argument(what);
00055 }
00056 return static_cast<U_Int>(vv);
00057 }
00058
00059 inline dimension_type
00060 value_to_ppl_dimension(value v) {
00061 return value_to_unsigned<dimension_type>(v);
00062 }
00063
00064 inline value
00065 ppl_dimension_to_value(dimension_type dim) {
00066
00067 assert(static_cast<uintnat>(dim) <= static_cast<uintnat>(Max_long));
00068 return Val_long(dim);
00069 }
00070
00071 inline Variable
00072 build_ppl_Variable(value caml_var) {
00073 return Variable(value_to_ppl_dimension(caml_var));
00074 }
00075
00076 }
00077
00078 }
00079
00080 }
00081
00082 #endif // !defined(PPL_ppl_ocaml_common_inlines_hh)