1 | #include <cstdio> |
---|
2 | #include <cmath> |
---|
3 | #include <cstring> |
---|
4 | #include <memory.h> |
---|
5 | #include <iostream> |
---|
6 | |
---|
7 | #include <arbdb.h> |
---|
8 | #include <arbdbt.h> |
---|
9 | #include <awt_tree.hxx> |
---|
10 | |
---|
11 | #include "AP_buffer.hxx" |
---|
12 | #include "parsimony.hxx" |
---|
13 | #include "AP_error.hxx" |
---|
14 | |
---|
15 | using namespace std; |
---|
16 | |
---|
17 | /********************************************* |
---|
18 | AP_ERR |
---|
19 | *************************/ |
---|
20 | |
---|
21 | int AP_ERR::modus = 0; |
---|
22 | |
---|
23 | AP_ERR::~AP_ERR() |
---|
24 | { |
---|
25 | delete text; |
---|
26 | } |
---|
27 | |
---|
28 | |
---|
29 | AP_ERR::AP_ERR (const char *pntr) |
---|
30 | // setzt den Fehlertext und zeigt ihn an |
---|
31 | { |
---|
32 | text = pntr; |
---|
33 | if (modus == 0) { |
---|
34 | cout << "\n*** WARNING *** \n" << text <<"\n"; |
---|
35 | cout.flush(); |
---|
36 | } |
---|
37 | } |
---|
38 | |
---|
39 | AP_ERR::AP_ERR (const char *pntr,const char *pntr2) |
---|
40 | { |
---|
41 | text = pntr2; |
---|
42 | if (modus == 0) { |
---|
43 | cout << "\n***** WARNING in " << pntr << "\n" << text <<"\n"; |
---|
44 | cout.flush(); |
---|
45 | } |
---|
46 | } |
---|
47 | |
---|
48 | AP_ERR::AP_ERR (const char *pntr,const char *pntr2,const int core) |
---|
49 | { |
---|
50 | text = pntr2; |
---|
51 | cout << "\n*** FATAL ERROR *** " << core << " in " <<pntr << "\n" << text <<"\n"; |
---|
52 | cout.flush(); |
---|
53 | GBK_terminate("AP_ERR[1]"); |
---|
54 | } |
---|
55 | |
---|
56 | AP_ERR::AP_ERR (const char *pntr, const int core) |
---|
57 | // setzt den Fehlertext |
---|
58 | // bricht ab |
---|
59 | { |
---|
60 | text = pntr; |
---|
61 | cout << "\n*** FATAL ERROR *** " << core << "\n" << text << "\n"; |
---|
62 | cout.flush(); |
---|
63 | GBK_terminate("AP_ERR[2]"); |
---|
64 | } |
---|
65 | |
---|
66 | const char *AP_ERR::show() |
---|
67 | { |
---|
68 | return text; |
---|
69 | } |
---|
70 | |
---|
71 | void AP_ERR::set_mode(int i) { |
---|
72 | modus = i; |
---|
73 | } |
---|
74 | |
---|
75 | /************** |
---|
76 | |
---|
77 | AP_main |
---|
78 | |
---|
79 | ***************/ |
---|
80 | |
---|
81 | AP_main::AP_main(void) { |
---|
82 | memset((char *)this,0,sizeof(AP_main)); |
---|
83 | } |
---|
84 | |
---|
85 | AP_main::~AP_main(void) { |
---|
86 | if (use) delete use; |
---|
87 | if (stack) delete stack; |
---|
88 | } |
---|
89 | |
---|
90 | GB_ERROR AP_main::open(char *db_server) { |
---|
91 | GB_ERROR error = 0; |
---|
92 | GLOBAL_gb_main = GB_open(db_server,"rwt"); |
---|
93 | if (!GLOBAL_gb_main) error = GB_await_error(); |
---|
94 | return error; |
---|
95 | } |
---|
96 | |
---|
97 | void AP_main::user_push(void) { |
---|
98 | this->user_push_counter = stack_level + 1; |
---|
99 | this->push(); |
---|
100 | } |
---|
101 | |
---|
102 | void AP_main::user_pop(void) { |
---|
103 | // checks if user_pop possible |
---|
104 | if (user_push_counter == stack_level) { |
---|
105 | this->pop(); // changes user_push_counter if user pop |
---|
106 | } else { |
---|
107 | new AP_ERR("AP_main::user_pop()","No user pop possible"); |
---|
108 | } |
---|
109 | return; |
---|
110 | } |
---|
111 | |
---|
112 | void AP_main::push(void) { |
---|
113 | // if count > 1 the nodes are buffered more than once |
---|
114 | // WARNING:: node only has to be buffered once in the stack |
---|
115 | // |
---|
116 | // |
---|
117 | stack_level ++; |
---|
118 | if (stack) list.push(stack); |
---|
119 | stack = new AP_main_stack; |
---|
120 | stack->last_user_buffer = this->user_push_counter; |
---|
121 | } |
---|
122 | |
---|
123 | void AP_main::pop(void) { |
---|
124 | AP_tree *knoten; |
---|
125 | if (!stack) { |
---|
126 | new AP_ERR("AP_main::pop()","Stack underflow !"); |
---|
127 | return; |
---|
128 | } |
---|
129 | while ( (knoten = stack->pop()) ) { |
---|
130 | if (stack_level != knoten->stack_level) { |
---|
131 | GB_internal_error("AP_main::pop: Error in stack_level"); |
---|
132 | cout << "Main UPD - node UPD : " << stack_level << " -- " << knoten->stack_level << " \n"; |
---|
133 | return; |
---|
134 | } |
---|
135 | knoten->pop(stack_level); |
---|
136 | } |
---|
137 | delete stack; |
---|
138 | stack_level --; |
---|
139 | stack = list.pop(); |
---|
140 | |
---|
141 | if (stack) { |
---|
142 | user_push_counter = stack->last_user_buffer; |
---|
143 | }else{ |
---|
144 | user_push_counter = 0; |
---|
145 | } |
---|
146 | return; |
---|
147 | } |
---|
148 | |
---|
149 | void AP_main::clear(void) { |
---|
150 | // removes count elements from the list |
---|
151 | // because the current tree is used |
---|
152 | // |
---|
153 | // if stack_counter greater than last user_push then |
---|
154 | // moves all not previous buffered nodes in the |
---|
155 | // previous stack |
---|
156 | |
---|
157 | AP_tree * knoten; |
---|
158 | AP_main_stack * new_stack; |
---|
159 | if (!stack) { |
---|
160 | new AP_ERR("AP_main::clear","Stack underflow !"); |
---|
161 | return; |
---|
162 | } |
---|
163 | if (user_push_counter >= stack_level) { |
---|
164 | if (stack != 0) { |
---|
165 | if (stack->size() > 0) { |
---|
166 | while (stack->size() > 0) { |
---|
167 | knoten = stack->pop(); |
---|
168 | //if (buffer_cout == AP_TRUE) knoten->printl(); |
---|
169 | knoten->clear(stack_level,user_push_counter); |
---|
170 | } |
---|
171 | } |
---|
172 | delete stack; |
---|
173 | stack = list.pop(); |
---|
174 | } |
---|
175 | } else { |
---|
176 | if (stack) { |
---|
177 | new_stack = list.pop(); |
---|
178 | while ( (knoten = stack->pop()) ) { |
---|
179 | if (knoten->clear(stack_level,user_push_counter) != AP_TRUE) { |
---|
180 | // node is not cleared because buffered in previous node stack |
---|
181 | // node is instead copied in previous level |
---|
182 | if (new_stack) new_stack->push(knoten); |
---|
183 | } |
---|
184 | } |
---|
185 | delete stack; |
---|
186 | stack = new_stack; |
---|
187 | } else { |
---|
188 | new AP_ERR("AP_main::clear"); |
---|
189 | } |
---|
190 | } |
---|
191 | stack_level --; |
---|
192 | if (stack) user_push_counter = stack->last_user_buffer; |
---|
193 | else user_push_counter = 0; |
---|
194 | |
---|
195 | } |
---|
196 | |
---|
197 | void AP_main::push_node(AP_tree * node,AP_STACK_MODE mode) { |
---|
198 | // |
---|
199 | // stores node |
---|
200 | // |
---|
201 | if (!stack) { |
---|
202 | if (mode & SEQUENCE) node->unhash_sequence(); |
---|
203 | return; |
---|
204 | } |
---|
205 | |
---|
206 | if ( stack_level < node->stack_level) { |
---|
207 | GB_warning("AP_main::push_node: stack_level < node->stack_level"); |
---|
208 | return; |
---|
209 | } |
---|
210 | |
---|
211 | if (node->push(mode,stack_level)) stack->push(node); |
---|
212 | } |
---|
213 | |
---|
214 | |
---|
215 | void AP_main::set_tree_root(AP_tree *new_root) { |
---|
216 | // removes old root and sets it |
---|
217 | // to the father of the new_root |
---|
218 | *ap_main->tree_root = new_root; |
---|
219 | } |
---|