| 1 | // =============================================================== // |
|---|
| 2 | // // |
|---|
| 3 | // File : AP_buffer.cxx // |
|---|
| 4 | // Purpose : // |
|---|
| 5 | // // |
|---|
| 6 | // Institute of Microbiology (Technical University Munich) // |
|---|
| 7 | // http://www.arb-home.de/ // |
|---|
| 8 | // // |
|---|
| 9 | // =============================================================== // |
|---|
| 10 | |
|---|
| 11 | #include "AP_buffer.hxx" |
|---|
| 12 | #include "ap_tree_nlen.hxx" |
|---|
| 13 | #include "ap_main.hxx" |
|---|
| 14 | |
|---|
| 15 | #include <iostream> |
|---|
| 16 | #include <fstream> |
|---|
| 17 | |
|---|
| 18 | using namespace std; |
|---|
| 19 | |
|---|
| 20 | #if defined(PROVIDE_PRINT) |
|---|
| 21 | |
|---|
| 22 | inline string space(int count) { |
|---|
| 23 | return string(count, ' '); |
|---|
| 24 | } |
|---|
| 25 | |
|---|
| 26 | void NodeState::print(ostream& out, int indentLevel) const { |
|---|
| 27 | out << space(indentLevel) |
|---|
| 28 | << "NodeState=" << this |
|---|
| 29 | << " frameNr=" << frameNr << " mode=" << mode; |
|---|
| 30 | if (mode & STRUCTURE) { |
|---|
| 31 | out << " father=" << father << " lson=" << leftson << " rson=" << rightson; |
|---|
| 32 | out << " edges={"; |
|---|
| 33 | for (int e = 0; e<3; ++e) { |
|---|
| 34 | out << " e[" << e << "]=" << edge[e] << "[" << edgeIndex[e] << "]"; |
|---|
| 35 | } |
|---|
| 36 | out << " }"; |
|---|
| 37 | } |
|---|
| 38 | if (mode & SEQUENCE) { |
|---|
| 39 | out << " sequence=" << sequence; |
|---|
| 40 | } |
|---|
| 41 | out << endl; |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | void NodeStack::print(ostream& out, int indentLevel, Level frameNr) const { |
|---|
| 45 | size_t i = count_elements(); |
|---|
| 46 | out << space(indentLevel) << "NodeStack=" << this << " size " << i << " frameNr=" << frameNr << endl; |
|---|
| 47 | for (NodeStack::const_iterator e = begin(); e != end(); ++e, --i) { |
|---|
| 48 | const AP_tree_nlen *node = *e; |
|---|
| 49 | out << space(indentLevel+1) << '[' << i << "] AP_tree_nlen*=" << node << " pushed_to_frame=" << node->get_pushed_to_frame() << endl; |
|---|
| 50 | node->get_states().print(out, indentLevel+2); |
|---|
| 51 | } |
|---|
| 52 | } |
|---|
| 53 | |
|---|
| 54 | void StateStack::print(ostream& out, int indentLevel) const { |
|---|
| 55 | size_t i = count_elements(); |
|---|
| 56 | out << space(indentLevel) << "StateStack=" << this << " size " << i << endl; |
|---|
| 57 | for (StateStack::const_iterator e = begin(); e != end(); ++e) { |
|---|
| 58 | const NodeState& state = **e; |
|---|
| 59 | state.print(out, indentLevel+1); |
|---|
| 60 | } |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | void FrameStack::print(ostream& out, int indentLevel) const { |
|---|
| 64 | size_t i = count_elements(); |
|---|
| 65 | out << space(indentLevel) << "FrameStack=" << this << " size " << i << endl; |
|---|
| 66 | |
|---|
| 67 | Level frameNr = i; |
|---|
| 68 | for (FrameStack::const_iterator e = begin(); e != end(); ++e, --frameNr) { |
|---|
| 69 | const NodeStack& nodeStack = **e; |
|---|
| 70 | nodeStack.print(out, indentLevel+1, frameNr); |
|---|
| 71 | } |
|---|
| 72 | } |
|---|
| 73 | |
|---|
| 74 | |
|---|
| 75 | void AP_tree_nlen::print(std::ostream& out, int indentLevel, const char *label) const { |
|---|
| 76 | out << space(indentLevel) |
|---|
| 77 | << label << "=" << this |
|---|
| 78 | << " father=" << get_father(); |
|---|
| 79 | for (int e = 0; e<3; ++e) { |
|---|
| 80 | out << " edge[" << e << "]=" << edge[e]; |
|---|
| 81 | if (edge[e]) { |
|---|
| 82 | const AP_tree_edge& E = *edge[e]; |
|---|
| 83 | if (E.isConnectedTo(this)) { |
|---|
| 84 | out << "->" << E.otherNode(this); |
|---|
| 85 | } |
|---|
| 86 | else { |
|---|
| 87 | out << "(not connected to 'this'!"; |
|---|
| 88 | AP_tree_nlen *son = E.sonNode(); |
|---|
| 89 | if (son) { |
|---|
| 90 | AP_tree_nlen *fath = E.otherNode(son); |
|---|
| 91 | out << " son=" << son << " father=" << fath; |
|---|
| 92 | } |
|---|
| 93 | else { |
|---|
| 94 | out << "no son node"; |
|---|
| 95 | } |
|---|
| 96 | |
|---|
| 97 | out << ')'; |
|---|
| 98 | } |
|---|
| 99 | } |
|---|
| 100 | } |
|---|
| 101 | |
|---|
| 102 | if (is_leaf) { |
|---|
| 103 | out << " name=" << name << endl; |
|---|
| 104 | } |
|---|
| 105 | else { |
|---|
| 106 | out << endl; |
|---|
| 107 | get_leftson()->print(out, indentLevel+1, "left"); |
|---|
| 108 | get_rightson()->print(out, indentLevel+1, "right"); |
|---|
| 109 | } |
|---|
| 110 | } |
|---|
| 111 | |
|---|
| 112 | |
|---|
| 113 | void AP_main::print(ostream& out) { |
|---|
| 114 | out << "AP_main tree:" << endl; |
|---|
| 115 | get_root_node()->print(out, 1, "root"); |
|---|
| 116 | |
|---|
| 117 | out << "AP_main frames:" << endl; |
|---|
| 118 | if (currFrame) { |
|---|
| 119 | out << " currFrame:" << endl; |
|---|
| 120 | currFrame->print(out, 2, frames.count_elements()+1); |
|---|
| 121 | } |
|---|
| 122 | else { |
|---|
| 123 | out << " no currFrame" << endl; |
|---|
| 124 | } |
|---|
| 125 | frames.print(out, 1); |
|---|
| 126 | } |
|---|
| 127 | |
|---|
| 128 | void AP_main::print2file(const char *file_in_ARBHOME) { |
|---|
| 129 | const char *full = GB_path_in_ARBHOME(file_in_ARBHOME); |
|---|
| 130 | std::ofstream out(full, std::ofstream::out); |
|---|
| 131 | print(out); |
|---|
| 132 | out.close(); |
|---|
| 133 | } |
|---|
| 134 | |
|---|
| 135 | #endif |
|---|
| 136 | |
|---|