Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
8acd7df672683e6a502b283b3c07de0d84b93cf1
[simgrid.git] / testsuite / xbt / swag_usage.c
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include "xbt/swag.h"
4
5 typedef struct {
6   s_xbt_swag_hookup_t setA;
7   s_xbt_swag_hookup_t setB;
8   char *name;
9 } shmurtz, s_shmurtz_t, *shmurtz_t;
10
11 int main(void)
12 {
13   shmurtz_t obj1, obj2, obj;
14   xbt_swag_t setA,setB;
15
16   obj1 = calloc(1,sizeof(s_shmurtz_t));
17   obj2 = calloc(1,sizeof(s_shmurtz_t));
18
19   obj1->name="Obj 1";
20   obj2->name="Obj 2";
21
22   printf("%p %p %d\n",obj1,&(obj1->setB),
23          (char *)&(obj1->setB) - (char *)obj1);
24
25   setA = xbt_swag_new(xbt_swag_offset(*obj1,setA));
26   setB = xbt_swag_new(xbt_swag_offset(*obj1,setB));
27
28   xbt_swag_insert(obj1, setA);
29   xbt_swag_insert(obj1, setB);
30   xbt_swag_insert(obj2, setA);
31   xbt_swag_insert(obj2, setB);
32
33   xbt_swag_extract(obj1, setB);
34   //  xbt_swag_extract(obj2, setB);
35
36   xbt_swag_foreach(obj,setA) {
37     printf("\t%s\n",obj->name);
38   }
39
40   xbt_swag_foreach(obj,setB) {
41     printf("\t%s\n",obj->name);
42   }
43
44   printf("Belongs : %d\n", xbt_swag_belongs(obj2,setB));
45
46   printf("%d %d\n", xbt_swag_size(setA),xbt_swag_size(setB));
47   return 0;
48 }