1 | // =============================================================== // |
---|
2 | // // |
---|
3 | // File : ap_main.hxx // |
---|
4 | // Purpose : // |
---|
5 | // // |
---|
6 | // Institute of Microbiology (Technical University Munich) // |
---|
7 | // http://www.arb-home.de/ // |
---|
8 | // // |
---|
9 | // =============================================================== // |
---|
10 | |
---|
11 | #ifndef AP_MAIN_HXX |
---|
12 | #define AP_MAIN_HXX |
---|
13 | |
---|
14 | #ifndef AP_MAIN_TYPE_HXX |
---|
15 | #include "ap_main_type.hxx" |
---|
16 | #endif |
---|
17 | #ifndef AP_TREE_NLEN_HXX |
---|
18 | #include "ap_tree_nlen.hxx" |
---|
19 | #endif |
---|
20 | |
---|
21 | |
---|
22 | #define AWAR_ALIGNMENT "tmp/pars/alignment" |
---|
23 | #define AWAR_FILTER_NAME "tmp/pars/filter/name" |
---|
24 | #define AWAR_PARSIMONY "tmp/pars/parsimony" |
---|
25 | #define AWAR_BEST_PARSIMONY "tmp/pars/best_parsimony" |
---|
26 | #define AWAR_STACKPOINTER "tmp/pars/stackpointer" |
---|
27 | |
---|
28 | #define AWAR_PARS_TYPE "pars/pars_type" |
---|
29 | |
---|
30 | enum PARS_pars_type { |
---|
31 | PARS_WAGNER, |
---|
32 | PARS_TRANSVERSION |
---|
33 | }; |
---|
34 | |
---|
35 | struct PARS_commands { |
---|
36 | bool add_marked; |
---|
37 | bool add_selected; |
---|
38 | bool calc_branch_lengths; |
---|
39 | bool calc_bootstrap; |
---|
40 | bool quit; |
---|
41 | |
---|
42 | PARS_commands() : |
---|
43 | add_marked(false), |
---|
44 | add_selected(false), |
---|
45 | calc_branch_lengths(false), |
---|
46 | calc_bootstrap(false), |
---|
47 | quit(false) |
---|
48 | { |
---|
49 | } |
---|
50 | }; |
---|
51 | |
---|
52 | extern AP_main *ap_main; // @@@ elim |
---|
53 | |
---|
54 | inline AP_tree_nlen *rootNode() { |
---|
55 | return ap_main->get_root_node(); |
---|
56 | } |
---|
57 | |
---|
58 | inline AP_tree_edge *rootEdge() { |
---|
59 | return rootNode()->get_leftson()->edgeTo(rootNode()->get_rightson()); |
---|
60 | } |
---|
61 | |
---|
62 | // ------------------------------------------ |
---|
63 | // stack-aware resource management |
---|
64 | |
---|
65 | #define REUSE_EDGES |
---|
66 | |
---|
67 | inline AP_tree_nlen *StackFrameData::makeNode(AP_pars_root *proot) { |
---|
68 | return created.put(new AP_tree_nlen(proot)); |
---|
69 | } |
---|
70 | inline AP_tree_edge *StackFrameData::makeEdge(AP_tree_nlen *n1, AP_tree_nlen *n2) { |
---|
71 | #if defined(REUSE_EDGES) |
---|
72 | if (destroyed.has_edges()) { |
---|
73 | AP_tree_edge *reuse = destroyed.getEdge(); |
---|
74 | reuse->relink(n1, n2); |
---|
75 | return reuse; |
---|
76 | } |
---|
77 | #endif |
---|
78 | return created.put(new AP_tree_edge(n1, n2)); |
---|
79 | } |
---|
80 | |
---|
81 | inline void StackFrameData::destroyNode(AP_tree_nlen *node) { destroyed.put(node); } |
---|
82 | inline void StackFrameData::destroyEdge(AP_tree_edge *edge) { destroyed.put(edge); } |
---|
83 | |
---|
84 | inline AP_tree_nlen *AP_main::makeNode(AP_pars_root *proot) { |
---|
85 | return currFrame ? frameData->makeNode(proot) : new AP_tree_nlen(proot); |
---|
86 | } |
---|
87 | inline AP_tree_edge *AP_main::makeEdge(AP_tree_nlen *n1, AP_tree_nlen *n2) { |
---|
88 | return currFrame ? frameData->makeEdge(n1, n2) : new AP_tree_edge(n1, n2); |
---|
89 | } |
---|
90 | inline void AP_main::destroyNode(AP_tree_nlen *node) { |
---|
91 | if (currFrame) { |
---|
92 | ap_assert(!node->rightson && !node->leftson); // node needs to be unlinked from neighbours |
---|
93 | frameData->destroyNode(node); |
---|
94 | } |
---|
95 | else { |
---|
96 | ap_assert(!node->may_be_recollected()); |
---|
97 | delete node; // here child nodes are destroyed |
---|
98 | } |
---|
99 | } |
---|
100 | inline void AP_main::destroyEdge(AP_tree_edge *edge) { |
---|
101 | ap_assert(!edge->is_linked()); |
---|
102 | if (currFrame) { |
---|
103 | frameData->destroyEdge(edge); |
---|
104 | } |
---|
105 | else { |
---|
106 | delete edge; |
---|
107 | } |
---|
108 | } |
---|
109 | |
---|
110 | inline TreeNode *AP_pars_root::makeNode() const { |
---|
111 | return ap_main->makeNode(const_cast<AP_pars_root*>(this)); |
---|
112 | } |
---|
113 | inline void AP_pars_root::destroyNode(TreeNode *node) const { |
---|
114 | ap_main->destroyNode(DOWNCAST(AP_tree_nlen*, node)); |
---|
115 | } |
---|
116 | |
---|
117 | inline AP_tree_edge *makeEdge(AP_tree_nlen *n1, AP_tree_nlen *n2) { |
---|
118 | return ap_main->makeEdge(n1, n2); |
---|
119 | } |
---|
120 | inline void destroyEdge(AP_tree_edge *edge) { |
---|
121 | ap_main->destroyEdge(edge); |
---|
122 | } |
---|
123 | |
---|
124 | |
---|
125 | #else |
---|
126 | #error ap_main.hxx included twice |
---|
127 | #endif // AP_MAIN_HXX |
---|