Streamer fluid modeling - An overview of ARCoS  1.0
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
tree.h
Go to the documentation of this file.
1 
13 #ifndef _TREE_H_
14 
15 #define LEAF_FIELDS(X) \
16  X *parent; \
17  X *next; \
18  X *first_child; \
19  int level; \
20 
21 #define LEAF_ROOT 0
22 
31 #define iter_childs(ROOT, LEAF) for (LEAF = ROOT->first_child; LEAF; \
32  LEAF = LEAF->next)
33 
38 #define free_childs(ROOT, LEAF, FREE) do { \
39  grid_t *next__; \
40  for (LEAF = ROOT->first_child; LEAF; LEAF = (typeof(LEAF)) next__) { \
41  next__ = ((grid_t *) LEAF)->next; \
42  FREE (LEAF); \
43  } \
44  } while(0)
45 
47 #define set_leaf(LEAF, PARENT, NEXT, FIRST_CHILD, LEVEL) do { \
48  LEAF->parent = PARENT; \
49  LEAF->next = NEXT; \
50  LEAF->first_child = FIRST_CHILD; \
51  LEAF->level = LEVEL; \
52  } while(0)
53 
54 #define init_leaf(LEAF) set_leaf(LEAF, NULL, NULL, NULL, -1)
55 
59 #define set_childless(LEAF) (LEAF)->first_child = NULL
60 
62 #define add_child(PARENT, CHILD) do { \
63  set_leaf(CHILD, PARENT, PARENT->first_child, CHILD->first_child, \
64  PARENT->level + 1); \
65  PARENT->first_child = CHILD; \
66  } while(0)
67 
73 #define mk_recursive(func, type) \
74  void func ## _r (type *grid_) \
75  { \
76  type *child_; \
77  func (grid_); \
78  iter_childs (grid_, child_) { \
79  func ## _r (child_); \
80  } \
81  }
82 
83 #define mk_tail_recursive(func, type) \
84  void func ## _r (type *grid_) \
85  { \
86  type *child_; \
87  iter_childs (grid_, child_) { \
88  func ## _r (child_); \
89  } \
90  func (grid_); \
91  }
92 
93 #define _TREE_H_
94 #endif