本文整理汇总了C++中TreeTemplate::getLeaves方法的典型用法代码示例。如果您正苦于以下问题:C++ TreeTemplate::getLeaves方法的具体用法?C++ TreeTemplate::getLeaves怎么用?C++ TreeTemplate::getLeaves使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TreeTemplate
的用法示例。
在下文中一共展示了TreeTemplate::getLeaves方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: read
void NexusIOTree::read(std::istream& in, std::vector<Tree*>& trees) const throw (Exception)
{
// Checking the existence of specified file
if (! in) { throw IOException ("NexusIOTree::read(). Failed to read from stream"); }
//Look for the TREES block:
string line = "";
while (TextTools::toUpper(line) != "BEGIN TREES;")
{
if (in.eof())
throw Exception("NexusIOTree::read(). No trees block was found.");
line = TextTools::removeSurroundingWhiteSpaces(FileTools::getNextLine(in));
}
string cmdName = "", cmdArgs = "";
bool cmdFound = NexusTools::getNextCommand(in, cmdName, cmdArgs, false);
if (! cmdFound)
throw Exception("NexusIOTree::read(). Missing tree command.");
cmdName = TextTools::toUpper(cmdName);
//Look for the TRANSLATE command:
map<string, string> translation;
bool hasTranslation = false;
if (cmdName == "TRANSLATE")
{
//Parse translation:
StringTokenizer st(cmdArgs, ",");
while (st.hasMoreToken())
{
string tok = TextTools::removeSurroundingWhiteSpaces(st.nextToken());
NestedStringTokenizer nst(tok, "'", "'", " \t");
if (nst.numberOfRemainingTokens() != 2)
throw Exception("NexusIOTree::read(). Unvalid translation description.");
string name = nst.nextToken();
string tln = nst.nextToken();
translation[name] = tln;
}
hasTranslation = true;
cmdFound = NexusTools::getNextCommand(in, cmdName, cmdArgs, false);
if (! cmdFound)
throw Exception("NexusIOTree::read(). Missing tree command.");
else
cmdName = TextTools::toUpper(cmdName);
}
//Now parse the trees:
while (cmdFound && cmdName != "END")
{
if (cmdName != "TREE")
throw Exception("NexusIOTree::read(). Unvalid command found: " + cmdName);
string::size_type pos = cmdArgs.find("=");
if (pos == string::npos)
throw Exception("NexusIOTree::read(). unvalid format, should be tree-name=tree-description");
string description = cmdArgs.substr(pos + 1);
TreeTemplate<Node>* tree = TreeTemplateTools::parenthesisToTree(description + ";", true);
//Now translate leaf names if there is a translation:
//(we assume that all trees share the same translation! ===> check!)
if (hasTranslation)
{
vector<Node*> leaves = tree->getLeaves();
for (size_t i = 0; i < leaves.size(); i++)
{
string name = leaves[i]->getName();
if (translation.find(name) == translation.end())
{
throw Exception("NexusIOTree::read(). No translation was given for this leaf: " + name);
}
leaves[i]->setName(translation[name]);
}
}
trees.push_back(tree);
cmdFound = NexusTools::getNextCommand(in, cmdName, cmdArgs, false);
if (cmdFound) cmdName = TextTools::toUpper(cmdName);
}
}