1 | // =============================================================== // |
---|
2 | // // |
---|
3 | // File : AP_buffer.hxx // |
---|
4 | // Purpose : // |
---|
5 | // // |
---|
6 | // Institute of Microbiology (Technical University Munich) // |
---|
7 | // http://www.arb-home.de/ // |
---|
8 | // // |
---|
9 | // =============================================================== // |
---|
10 | |
---|
11 | #ifndef AP_BUFFER_HXX |
---|
12 | #define AP_BUFFER_HXX |
---|
13 | |
---|
14 | #ifndef AP_TREE_HXX |
---|
15 | #include <AP_Tree.hxx> |
---|
16 | #endif |
---|
17 | |
---|
18 | /* AP_STACK dynamischer Stack fuer void * |
---|
19 | * AP_LIST allgemeine doppelt verketteten Liste |
---|
20 | * |
---|
21 | * -- Pufferstrukturen |
---|
22 | * |
---|
23 | * AP_tree_buffer Struktur die im AP_tree gepuffert wird |
---|
24 | * |
---|
25 | * -- spezielle stacks ( um casts zu vermeiden ) |
---|
26 | * |
---|
27 | * AP_tree_stack Stack fuer AP_tree_buffer * |
---|
28 | * AP_main_stack Stack fuer AP_tree * |
---|
29 | * AP_main_list Liste fuer AP_main_buffer |
---|
30 | */ |
---|
31 | |
---|
32 | |
---|
33 | struct AP_STACK_ELEM { |
---|
34 | struct AP_STACK_ELEM * next; |
---|
35 | void * node; |
---|
36 | }; |
---|
37 | |
---|
38 | class AP_STACK : virtual Noncopyable { // @@@ make typesafe (use template) |
---|
39 | struct AP_STACK_ELEM * first; |
---|
40 | struct AP_STACK_ELEM * pointer; |
---|
41 | unsigned long stacksize; |
---|
42 | unsigned long max_stacksize; |
---|
43 | |
---|
44 | public: |
---|
45 | AP_STACK(); |
---|
46 | virtual ~AP_STACK(); |
---|
47 | |
---|
48 | void push(void * element); |
---|
49 | void *pop(); |
---|
50 | void clear(); |
---|
51 | void get_init(); |
---|
52 | void *get(); |
---|
53 | void *get_first(); |
---|
54 | unsigned long size(); |
---|
55 | }; |
---|
56 | |
---|
57 | // ---------------- |
---|
58 | // AP_LIST |
---|
59 | |
---|
60 | struct AP_list_elem { |
---|
61 | AP_list_elem * next; |
---|
62 | AP_list_elem * prev; |
---|
63 | void * node; |
---|
64 | }; |
---|
65 | |
---|
66 | class AP_LIST : virtual Noncopyable { |
---|
67 | unsigned int list_len; |
---|
68 | unsigned int akt; |
---|
69 | AP_list_elem *first, *last, *pointer; |
---|
70 | |
---|
71 | AP_list_elem *element(void * elem); |
---|
72 | public: |
---|
73 | AP_LIST() |
---|
74 | : list_len(0), |
---|
75 | akt(0), |
---|
76 | first(NULL), |
---|
77 | last(NULL), |
---|
78 | pointer(NULL) |
---|
79 | {} |
---|
80 | |
---|
81 | virtual ~AP_LIST() {} |
---|
82 | |
---|
83 | int len(); |
---|
84 | int is_element(void * node); |
---|
85 | int eof(); |
---|
86 | void insert(void * new_one); |
---|
87 | void append(void * new_one); |
---|
88 | void remove(void * object); |
---|
89 | void push(void *elem); |
---|
90 | void *pop(); |
---|
91 | void clear(); |
---|
92 | }; |
---|
93 | |
---|
94 | // ---------------------------------------------------------------- |
---|
95 | // special buffer-structures for AP_tree and AP_tree_edge |
---|
96 | |
---|
97 | class AP_tree_edge; // defined in ap_tree_nlen.hxx |
---|
98 | struct AP_tree_buffer; |
---|
99 | |
---|
100 | struct AP_tree_edge_data |
---|
101 | { |
---|
102 | AP_FLOAT parsValue[3]; // the last three parsimony values (0=lowest 2=highest) |
---|
103 | int distance; // the distance of the last insertion |
---|
104 | }; |
---|
105 | |
---|
106 | |
---|
107 | struct AP_tree_buffer { |
---|
108 | unsigned long controll; // used for internal buffer check |
---|
109 | unsigned int count; // counts how often the entry is buffered |
---|
110 | AP_STACK_MODE mode; |
---|
111 | AP_sequence *sequence; |
---|
112 | AP_FLOAT mutation_rate; |
---|
113 | double leftlen, rightlen; |
---|
114 | AP_tree *father; |
---|
115 | AP_tree *leftson; |
---|
116 | AP_tree *rightson; |
---|
117 | AP_tree_root *root; |
---|
118 | GBDATA *gb_node; |
---|
119 | |
---|
120 | int distance; // distance to border (pushed with STRUCTURE!) |
---|
121 | |
---|
122 | // data from edges: |
---|
123 | AP_tree_edge *edge[3]; |
---|
124 | int edgeIndex[3]; |
---|
125 | AP_tree_edge_data edgeData[3]; |
---|
126 | |
---|
127 | void print(); |
---|
128 | }; |
---|
129 | |
---|
130 | struct AP_tree_stack : public AP_STACK { |
---|
131 | AP_tree_stack() {} |
---|
132 | virtual ~AP_tree_stack() OVERRIDE {} |
---|
133 | void push(AP_tree_buffer *value) { AP_STACK::push((void *)value); } |
---|
134 | AP_tree_buffer * pop() { return (AP_tree_buffer *) AP_STACK::pop(); } |
---|
135 | AP_tree_buffer * get() { return (AP_tree_buffer *) AP_STACK::get(); } |
---|
136 | AP_tree_buffer * get_first() { return (AP_tree_buffer *) AP_STACK::get_first(); } |
---|
137 | void print(); |
---|
138 | }; |
---|
139 | |
---|
140 | class AP_tree_nlen; |
---|
141 | |
---|
142 | class AP_main_stack : public AP_STACK { |
---|
143 | protected: |
---|
144 | unsigned long last_user_buffer; |
---|
145 | public: |
---|
146 | friend class AP_main; |
---|
147 | void push(AP_tree_nlen *value) { AP_STACK::push((void *)value); } |
---|
148 | AP_tree_nlen *pop() { return (AP_tree_nlen*)AP_STACK::pop(); } |
---|
149 | AP_tree_nlen *get() { return (AP_tree_nlen*)AP_STACK::get(); } |
---|
150 | AP_tree_nlen *get_first() { return (AP_tree_nlen*)AP_STACK::get_first(); } |
---|
151 | void print(); |
---|
152 | }; |
---|
153 | |
---|
154 | |
---|
155 | struct AP_main_list : public AP_LIST { |
---|
156 | AP_main_stack * pop() { return (AP_main_stack *)AP_LIST::pop(); } |
---|
157 | void push(AP_main_stack * stack) { AP_LIST::push((void *) stack); } |
---|
158 | void insert(AP_main_stack * stack) { AP_LIST::insert((void *)stack); } |
---|
159 | void append(AP_main_stack * stack) { AP_LIST::append((void *)stack); } |
---|
160 | }; |
---|
161 | |
---|
162 | #else |
---|
163 | #error AP_buffer.hxx included twice |
---|
164 | #endif // AP_BUFFER_HXX |
---|