3 #include "textfile.h"
\r
5 unsigned Tree::GetAnyNonLeafNode() const
\r
7 for (unsigned uNodeIndex = 0; uNodeIndex < m_uNodeCount; ++uNodeIndex)
\r
8 if (!IsLeaf(uNodeIndex))
\r
10 return NULL_NEIGHBOR;
\r
13 void Tree::ToFile(TextFile &File) const
\r
17 ToFileNodeRooted(File, m_uRootNodeIndex);
\r
18 File.PutString(";\n");
\r
23 unsigned uNodeIndex = GetAnyNonLeafNode();
\r
25 File.PutString("(\n");
\r
26 ToFileNodeUnrooted(File, m_uNeighbor1[uNodeIndex], uNodeIndex);
\r
27 File.PutString(",\n");
\r
28 ToFileNodeUnrooted(File, m_uNeighbor2[uNodeIndex], uNodeIndex);
\r
29 File.PutString(",\n");
\r
30 ToFileNodeUnrooted(File, m_uNeighbor3[uNodeIndex], uNodeIndex);
\r
31 File.PutString(");\n");
\r
34 void Tree::ToFileNodeUnrooted(TextFile &File, unsigned uNodeIndex, unsigned uParent) const
\r
36 assert(!IsRooted());
\r
38 bool bGroup = !IsLeaf(uNodeIndex);
\r
40 File.PutString("(\n");
\r
42 if (IsLeaf(uNodeIndex))
\r
43 File.PutString(GetName(uNodeIndex));
\r
46 ToFileNodeUnrooted(File, GetFirstNeighbor(uNodeIndex, uParent), uNodeIndex);
\r
47 File.PutString(",\n");
\r
48 ToFileNodeUnrooted(File, GetSecondNeighbor(uNodeIndex, uParent), uNodeIndex);
\r
52 File.PutString(")");
\r
54 if (HasEdgeLength(uNodeIndex, uParent))
\r
55 File.PutFormat(":%g", GetEdgeLength(uNodeIndex, uParent));
\r
56 File.PutString("\n");
\r
59 void Tree::ToFileNodeRooted(TextFile &File, unsigned uNodeIndex) const
\r
63 bool bGroup = !IsLeaf(uNodeIndex) || IsRoot(uNodeIndex);
\r
65 File.PutString("(\n");
\r
67 if (IsLeaf(uNodeIndex))
\r
68 File.PutString(GetName(uNodeIndex));
\r
71 ToFileNodeRooted(File, GetLeft(uNodeIndex));
\r
72 File.PutString(",\n");
\r
73 ToFileNodeRooted(File, GetRight(uNodeIndex));
\r
77 File.PutString(")");
\r
79 if (!IsRoot(uNodeIndex))
\r
81 unsigned uParent = GetParent(uNodeIndex);
\r
82 if (HasEdgeLength(uNodeIndex, uParent))
\r
83 File.PutFormat(":%g", GetEdgeLength(uNodeIndex, uParent));
\r
85 File.PutString("\n");
\r