source: branches/profile/PARSIMONY/AP_buffer.hxx

Last change on this file was 12936, checked in by westram, 10 years ago
  • remove artificial stack-limit (500000 pushs)
    • no idea what this was good for - maybe only to detect infinite loops or similar
    • fixes #608
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.7 KB
Line 
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
33struct AP_STACK_ELEM {
34    struct AP_STACK_ELEM * next;
35    void *                 node;
36};
37
38class 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
43public:
44    AP_STACK();
45    virtual ~AP_STACK();
46
47    void           push(void * element);
48    void          *pop();
49    void           clear();
50    void           get_init();
51    void          *get();
52    void          *get_first();
53    unsigned long  size();
54};
55
56// ----------------
57//      AP_LIST
58
59struct AP_list_elem {
60    AP_list_elem * next;
61    AP_list_elem * prev;
62    void *         node;
63};
64
65class AP_LIST : virtual Noncopyable {
66    unsigned int  list_len;
67    unsigned int  akt;
68    AP_list_elem *first, *last, *pointer;
69
70    AP_list_elem *element(void * elem);
71public:
72    AP_LIST()
73        : list_len(0),
74          akt(0),
75          first(NULL), 
76          last(NULL), 
77          pointer(NULL) 
78    {}
79
80    virtual ~AP_LIST() {}
81
82    int   len();
83    int   is_element(void * node);
84    int   eof();
85    void  insert(void * new_one);
86    void  append(void * new_one);
87    void  remove(void * object);
88    void  push(void *elem);
89    void *pop();
90    void  clear();
91};
92
93// ----------------------------------------------------------------
94//      special buffer-structures for AP_tree and AP_tree_edge
95
96class  AP_tree_edge;                                // defined in ap_tree_nlen.hxx
97struct AP_tree_buffer;
98
99struct AP_tree_edge_data
100{
101    AP_FLOAT parsValue[3];                          // the last three parsimony values (0=lowest 2=highest)
102    int      distance;                              // the distance of the last insertion
103};
104
105
106struct AP_tree_buffer {
107    unsigned long  controll;                        // used for internal buffer check
108    unsigned int   count;                           // counts how often the entry is buffered
109    AP_STACK_MODE  mode;
110    AP_sequence   *sequence;
111    AP_FLOAT       mutation_rate;
112    double         leftlen, rightlen;
113    AP_tree       *father;
114    AP_tree       *leftson;
115    AP_tree       *rightson;
116    AP_tree_root  *root;
117    GBDATA        *gb_node;
118
119    int distance;                                   // distance to border (pushed with STRUCTURE!)
120
121    // data from edges:
122    AP_tree_edge      *edge[3];
123    int                edgeIndex[3];
124    AP_tree_edge_data  edgeData[3];
125
126    void print();
127};
128
129struct AP_tree_stack : public AP_STACK {
130    AP_tree_stack() {}
131    virtual ~AP_tree_stack() OVERRIDE {}
132    void  push(AP_tree_buffer *value) { AP_STACK::push((void *)value); }
133    AP_tree_buffer * pop() { return (AP_tree_buffer *) AP_STACK::pop(); }
134    AP_tree_buffer * get() { return (AP_tree_buffer *) AP_STACK::get(); }
135    AP_tree_buffer * get_first() { return (AP_tree_buffer *) AP_STACK::get_first(); }
136    void print();
137};
138
139class AP_tree_nlen;
140
141class AP_main_stack : public AP_STACK {
142protected:
143    unsigned long last_user_buffer;
144public:
145    friend class AP_main;
146    void push(AP_tree_nlen *value) { AP_STACK::push((void *)value); }
147    AP_tree_nlen *pop() { return (AP_tree_nlen*)AP_STACK::pop(); }
148    AP_tree_nlen *get() { return (AP_tree_nlen*)AP_STACK::get(); }
149    AP_tree_nlen *get_first() { return (AP_tree_nlen*)AP_STACK::get_first(); }
150    void print();
151};
152
153
154struct AP_main_list : public AP_LIST {
155    AP_main_stack * pop() { return  (AP_main_stack *)AP_LIST::pop(); }
156    void push(AP_main_stack * stack) { AP_LIST::push((void *) stack); }
157    void insert(AP_main_stack * stack) { AP_LIST::insert((void *)stack); }
158    void append(AP_main_stack * stack) { AP_LIST::append((void *)stack); }
159};
160
161#else
162#error AP_buffer.hxx included twice
163#endif // AP_BUFFER_HXX
Note: See TracBrowser for help on using the repository browser.