Advertisement
Guest User

ccamlpart.cc part

a guest
Jul 13th, 2010
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.89 KB | None | 0 0
  1. int int_of_grouptype (value gr)
  2. {
  3.         CAMLparam1(gr);
  4.         if (Is_long(gr))
  5.         {
  6.                 switch(Int_val(gr))
  7.                 {
  8.                         case 0:
  9.                                 return (int)OrgGroup;
  10.                                 break;
  11.                         case 1:
  12.                                 return (int)InorgGroup;
  13.                                 break;
  14.                         default:
  15.                                 caml_failwith("Unknown group type");
  16.                 }
  17.         }
  18.         else
  19.         {
  20.                 return Int_val(Field(gr, 0)); //NeighbourGroup
  21.         }
  22. }
  23.  
  24. value grouptype_of_int (int g)
  25. {
  26.         CAMLparam0();
  27.         CAMLlocal1(cg);
  28.         if (g < 0)
  29.         {
  30.                 cg = Val_long(g+2);
  31.         }
  32.         else
  33.         {
  34.                 cg = caml_alloc(1, 0);
  35.                 Store_field(cg, 0, Val_long(g));
  36.         }
  37.         CAMLreturn(cg);
  38. }
  39.  
  40. value camlgroup_of_group (group *g)
  41. {
  42.         CAMLparam0();
  43.         CAMLlocal1(cg);
  44.         cg = caml_alloc(5, 0);
  45.         Store_field(cg, 0, caml_copy_string(g->name));
  46.         Store_field(cg, 1, Val_long((long)g->position));
  47.         Store_field(cg, 2, Val_long((long)g->cycle));
  48.         Store_field(cg, 3, grouptype_of_int(g->group_type));
  49.         Store_field(cg, 4, Val_long(g->link));
  50.         CAMLreturn(cg);
  51. }
  52.  
  53. group group_of_camlgroup (value g)
  54. {
  55.         CAMLparam1(g);
  56.         group gr;
  57.         size_t name_len = caml_string_length(Field(g, 0));
  58.         gr.name = (char*)malloc(name_len+1);
  59.         memcpy(gr.name, String_val(Field(g, 0)), name_len);
  60.         gr.name[name_len] = '\0';
  61.         gr.position = (group_position)Long_val(Field(g, 1));
  62.         gr.cycle = (cycle_type)Long_val(Field(g, 2));
  63.         gr.group_type = int_of_grouptype(Field(g, 3));
  64.         gr.link = Long_val(Field(g, 4));
  65.         CAMLreturnT(group, gr);
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement