Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int int_of_grouptype (value gr)
- {
- CAMLparam1(gr);
- if (Is_long(gr))
- {
- switch(Int_val(gr))
- {
- case 0:
- return (int)OrgGroup;
- break;
- case 1:
- return (int)InorgGroup;
- break;
- default:
- caml_failwith("Unknown group type");
- }
- }
- else
- {
- return Int_val(Field(gr, 0)); //NeighbourGroup
- }
- }
- value grouptype_of_int (int g)
- {
- CAMLparam0();
- CAMLlocal1(cg);
- if (g < 0)
- {
- cg = Val_long(g+2);
- }
- else
- {
- cg = caml_alloc(1, 0);
- Store_field(cg, 0, Val_long(g));
- }
- CAMLreturn(cg);
- }
- value camlgroup_of_group (group *g)
- {
- CAMLparam0();
- CAMLlocal1(cg);
- cg = caml_alloc(5, 0);
- Store_field(cg, 0, caml_copy_string(g->name));
- Store_field(cg, 1, Val_long((long)g->position));
- Store_field(cg, 2, Val_long((long)g->cycle));
- Store_field(cg, 3, grouptype_of_int(g->group_type));
- Store_field(cg, 4, Val_long(g->link));
- CAMLreturn(cg);
- }
- group group_of_camlgroup (value g)
- {
- CAMLparam1(g);
- group gr;
- size_t name_len = caml_string_length(Field(g, 0));
- gr.name = (char*)malloc(name_len+1);
- memcpy(gr.name, String_val(Field(g, 0)), name_len);
- gr.name[name_len] = '\0';
- gr.position = (group_position)Long_val(Field(g, 1));
- gr.cycle = (cycle_type)Long_val(Field(g, 2));
- gr.group_type = int_of_grouptype(Field(g, 3));
- gr.link = Long_val(Field(g, 4));
- CAMLreturnT(group, gr);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement