source: tags/cvs_2_svn/PARSIMONY/AP_main.cxx

Last change on this file was 5390, checked in by westram, 16 years ago
  • TAB-Ex
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.1 KB
Line 
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
15using namespace std;
16
17/*********************************************
18AP_ERR
19*************************/
20
21int AP_ERR::modus = 0;
22
23AP_ERR::~AP_ERR()
24{
25    delete text;
26}
27
28
29AP_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
39AP_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
48AP_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    GB_CORE;
54}
55
56AP_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    GB_CORE;    // -segmantation Fault
64}
65
66const char *AP_ERR::show()
67{
68    return text;
69}
70
71void AP_ERR::set_mode(int i) {
72    modus = i;
73}
74
75/**************
76
77AP_main
78
79***************/
80
81AP_main::AP_main(void) {
82    memset((char *)this,0,sizeof(AP_main));
83}
84
85AP_main::~AP_main(void) {
86    if (use) delete use;
87    if (stack) delete stack;
88}
89
90char *AP_main::open(char *db_server)
91{
92    char *error = 0 ;
93
94    GLOBAL_gb_main = GB_open(db_server,"rwt");
95    if (!GLOBAL_gb_main) return (char *)GB_get_error();
96    if (error) return error;
97
98    return 0;
99}
100
101void AP_main::user_push(void) {
102    this->user_push_counter = stack_level + 1;
103    this->push();
104}
105
106void AP_main::user_pop(void) {
107    // checks if user_pop possible
108    if (user_push_counter == stack_level) {
109        this->pop();    // changes user_push_counter if user pop
110    } else {
111        new AP_ERR("AP_main::user_pop()","No user pop possible");
112    }
113    return;
114}
115
116void AP_main::push(void) {
117    // if count > 1 the nodes are buffered more than once
118    // WARNING:: node only has to be buffered once in the stack
119    //
120    //
121    stack_level ++;
122    if (stack) list.push(stack);
123    stack = new AP_main_stack;
124    stack->last_user_buffer = this->user_push_counter;
125}
126
127void AP_main::pop(void) {
128    AP_tree *knoten;
129    if (!stack) {
130        new AP_ERR("AP_main::pop()","Stack underflow !");
131        return;
132    }
133    while ( (knoten = stack->pop()) ) {
134        if (stack_level != knoten->stack_level) {
135            GB_internal_error("AP_main::pop: Error in stack_level");
136            cout << "Main UPD - node UPD : " << stack_level << " -- " << knoten->stack_level << " \n";
137            return;
138        }
139        knoten->pop(stack_level);
140    }
141    delete stack;
142    stack_level --;
143    stack = list.pop();
144
145    if (stack) {
146        user_push_counter = stack->last_user_buffer;
147    }else{
148        user_push_counter = 0;
149    }
150    return;
151}
152
153void AP_main::clear(void) {
154    // removes count elements from the list
155    // because the current tree is used
156    //
157    // if stack_counter greater than last user_push then
158    // moves all not previous buffered nodes in the
159    // previous stack
160
161    AP_tree * knoten;
162    AP_main_stack * new_stack;
163    if (!stack) {
164        new AP_ERR("AP_main::clear","Stack underflow !");
165        return;
166    }
167    if (user_push_counter >= stack_level) {
168        if (stack != 0) {
169            if (stack->size() > 0) {
170                while (stack->size() > 0) {
171                    knoten = stack->pop();
172                    //if (buffer_cout == AP_TRUE) knoten->printl();
173                    knoten->clear(stack_level,user_push_counter);
174                }
175            }
176            delete stack;
177            stack = list.pop();
178        }
179    } else {
180        if (stack) {
181            new_stack = list.pop();
182            while ( (knoten = stack->pop()) ) {
183                if (knoten->clear(stack_level,user_push_counter) != AP_TRUE) {
184                    // node is not cleared because buffered in previous node stack
185                    // node is instead copied in previous level
186                    if (new_stack) new_stack->push(knoten);
187                }
188            }
189            delete stack;
190            stack = new_stack;
191        } else {
192            new AP_ERR("AP_main::clear");
193        }
194    }
195    stack_level --;
196    if (stack) user_push_counter = stack->last_user_buffer;
197    else user_push_counter = 0;
198
199}
200
201void AP_main::push_node(AP_tree * node,AP_STACK_MODE mode) {
202    //
203    //  stores node
204    //
205    if (!stack) {
206        if (mode & SEQUENCE)    node->unhash_sequence();
207        return;
208    }
209
210    if ( stack_level < node->stack_level) {
211        GB_warning("AP_main::push_node: stack_level < node->stack_level");
212        return;
213    }
214
215    if (node->push(mode,stack_level))   stack->push(node);
216}
217
218
219void AP_main::set_tree_root(AP_tree *new_root) {
220    // removes old root and sets it
221    // to the father of the new_root
222    *ap_main->tree_root = new_root;
223}
Note: See TracBrowser for help on using the repository browser.