| 1 | // =============================================================== // |
|---|
| 2 | // // |
|---|
| 3 | // File : AP_main.cxx // |
|---|
| 4 | // Purpose : // |
|---|
| 5 | // // |
|---|
| 6 | // Institute of Microbiology (Technical University Munich) // |
|---|
| 7 | // http://www.arb-home.de/ // |
|---|
| 8 | // // |
|---|
| 9 | // =============================================================== // |
|---|
| 10 | |
|---|
| 11 | #include "AP_error.hxx" |
|---|
| 12 | #include "ap_tree_nlen.hxx" |
|---|
| 13 | |
|---|
| 14 | #include <TreeDisplay.hxx> |
|---|
| 15 | |
|---|
| 16 | using namespace std; |
|---|
| 17 | |
|---|
| 18 | // --------------- |
|---|
| 19 | // AP_ERR |
|---|
| 20 | |
|---|
| 21 | int AP_ERR::mode = 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 (mode == 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 (mode == 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 | mode = i; |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | // ---------------- |
|---|
| 76 | // AP_main |
|---|
| 77 | |
|---|
| 78 | AP_main::AP_main() { |
|---|
| 79 | memset((char *)this, 0, sizeof(AP_main)); |
|---|
| 80 | } |
|---|
| 81 | |
|---|
| 82 | AP_main::~AP_main() { |
|---|
| 83 | if (stack) delete stack; |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | GB_ERROR AP_main::open(char *db_server) { |
|---|
| 87 | GB_ERROR error = 0; |
|---|
| 88 | GLOBAL_gb_main = GB_open(db_server, "rwt"); |
|---|
| 89 | if (!GLOBAL_gb_main) error = GB_await_error(); |
|---|
| 90 | return error; |
|---|
| 91 | } |
|---|
| 92 | |
|---|
| 93 | void AP_main::user_push() { |
|---|
| 94 | this->user_push_counter = stack_level + 1; |
|---|
| 95 | this->push(); |
|---|
| 96 | } |
|---|
| 97 | |
|---|
| 98 | void AP_main::user_pop() { |
|---|
| 99 | // checks if user_pop possible |
|---|
| 100 | if (user_push_counter == stack_level) { |
|---|
| 101 | this->pop(); // changes user_push_counter if user pop |
|---|
| 102 | } |
|---|
| 103 | else { |
|---|
| 104 | new AP_ERR("AP_main::user_pop()", "No user pop possible"); |
|---|
| 105 | } |
|---|
| 106 | return; |
|---|
| 107 | } |
|---|
| 108 | |
|---|
| 109 | void AP_main::push() { |
|---|
| 110 | // if count > 1 the nodes are buffered more than once |
|---|
| 111 | // WARNING:: node only has to be buffered once in the stack |
|---|
| 112 | // |
|---|
| 113 | // |
|---|
| 114 | stack_level ++; |
|---|
| 115 | if (stack) list.push(stack); |
|---|
| 116 | stack = new AP_main_stack; |
|---|
| 117 | stack->last_user_buffer = this->user_push_counter; |
|---|
| 118 | } |
|---|
| 119 | |
|---|
| 120 | void AP_main::pop() { |
|---|
| 121 | AP_tree_nlen *knoten; |
|---|
| 122 | if (!stack) { |
|---|
| 123 | new AP_ERR("AP_main::pop()", "Stack underflow !"); |
|---|
| 124 | return; |
|---|
| 125 | } |
|---|
| 126 | while ((knoten = stack->pop())) { |
|---|
| 127 | if (stack_level != knoten->stack_level) { |
|---|
| 128 | GB_internal_error("AP_main::pop: Error in stack_level"); |
|---|
| 129 | cout << "Main UPD - node UPD : " << stack_level << " -- " << knoten->stack_level << " \n"; |
|---|
| 130 | return; |
|---|
| 131 | } |
|---|
| 132 | knoten->pop(stack_level); |
|---|
| 133 | } |
|---|
| 134 | delete stack; |
|---|
| 135 | stack_level --; |
|---|
| 136 | stack = list.pop(); |
|---|
| 137 | user_push_counter = stack ? stack->last_user_buffer : 0; |
|---|
| 138 | } |
|---|
| 139 | |
|---|
| 140 | void AP_main::clear() { |
|---|
| 141 | // removes count elements from the list |
|---|
| 142 | // because the current tree is used |
|---|
| 143 | // |
|---|
| 144 | // if stack_counter greater than last user_push then |
|---|
| 145 | // moves all not previous buffered nodes in the |
|---|
| 146 | // previous stack |
|---|
| 147 | |
|---|
| 148 | AP_tree_nlen *knoten; |
|---|
| 149 | AP_main_stack *new_stack; |
|---|
| 150 | |
|---|
| 151 | if (!stack) { |
|---|
| 152 | new AP_ERR("AP_main::clear", "Stack underflow !"); |
|---|
| 153 | return; |
|---|
| 154 | } |
|---|
| 155 | if (user_push_counter >= stack_level) { |
|---|
| 156 | if (stack != 0) { |
|---|
| 157 | if (stack->size() > 0) { |
|---|
| 158 | while (stack->size() > 0) { |
|---|
| 159 | knoten = stack->pop(); |
|---|
| 160 | knoten->clear(stack_level, user_push_counter); |
|---|
| 161 | } |
|---|
| 162 | } |
|---|
| 163 | delete stack; |
|---|
| 164 | stack = list.pop(); |
|---|
| 165 | } |
|---|
| 166 | } |
|---|
| 167 | else { |
|---|
| 168 | if (stack) { |
|---|
| 169 | new_stack = list.pop(); |
|---|
| 170 | while ((knoten = stack->pop())) { |
|---|
| 171 | if (knoten->clear(stack_level, user_push_counter) != true) { |
|---|
| 172 | // node is not cleared because buffered in previous node stack |
|---|
| 173 | // node is instead copied in previous level |
|---|
| 174 | if (new_stack) new_stack->push(knoten); |
|---|
| 175 | } |
|---|
| 176 | } |
|---|
| 177 | delete stack; |
|---|
| 178 | stack = new_stack; |
|---|
| 179 | } |
|---|
| 180 | else { |
|---|
| 181 | new AP_ERR("AP_main::clear"); |
|---|
| 182 | } |
|---|
| 183 | } |
|---|
| 184 | stack_level --; |
|---|
| 185 | if (stack) user_push_counter = stack->last_user_buffer; |
|---|
| 186 | else user_push_counter = 0; |
|---|
| 187 | |
|---|
| 188 | } |
|---|
| 189 | |
|---|
| 190 | void AP_main::push_node(AP_tree_nlen *node, AP_STACK_MODE mode) { |
|---|
| 191 | // |
|---|
| 192 | // stores node |
|---|
| 193 | // |
|---|
| 194 | if (!stack) { |
|---|
| 195 | if (mode & SEQUENCE) node->unhash_sequence(); |
|---|
| 196 | return; |
|---|
| 197 | } |
|---|
| 198 | |
|---|
| 199 | if (stack_level < node->stack_level) { |
|---|
| 200 | GB_warning("AP_main::push_node: stack_level < node->stack_level"); |
|---|
| 201 | return; |
|---|
| 202 | } |
|---|
| 203 | |
|---|
| 204 | if (node->push(mode, stack_level)) stack->push(node); |
|---|
| 205 | } |
|---|
| 206 | |
|---|
| 207 | AP_tree_nlen *AP_main::get_root_node() { |
|---|
| 208 | return DOWNCAST(AP_tree_nlen*, agt->get_root_node()); |
|---|
| 209 | } |
|---|
| 210 | |
|---|
| 211 | void AP_main::set_tree_root(AWT_graphic_tree *agt_) { |
|---|
| 212 | ap_assert(agt == 0 && agt_ != 0); // do only once |
|---|
| 213 | agt = agt_; |
|---|
| 214 | } |
|---|
| 215 | |
|---|
| 216 | const char *AP_main::get_aliname() const { |
|---|
| 217 | return agt->tree_static->get_aliview()->get_aliname(); |
|---|
| 218 | } |
|---|
| 219 | |
|---|