本文整理汇总了C++中NodePtr::absorb方法的典型用法代码示例。如果您正苦于以下问题:C++ NodePtr::absorb方法的具体用法?C++ NodePtr::absorb怎么用?C++ NodePtr::absorb使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NodePtr
的用法示例。
在下文中一共展示了NodePtr::absorb方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parse
NodeVector Parser::parse()
{
std::vector<Token> tokens = tokenize();
std::deque<NodePtr> stack;
stack.push_back(std::make_shared<Node>(CMD, "ROOT"));
NodePtr lastCompleted = nullptr;
while (tokens.size() && stack.size()) {
NodePtr node;
Token tok = tokens.front();
tokens.erase(tokens.begin());
if (tok.type == TokType::RAW) {
node = std::make_shared<Node>(TEXT, tok.str);
stack.back()->addChild(node);
} else if (tok.type == TokType::CMD_BEG) {
node = std::make_shared<Node>(CMD, tok.str);
stack.push_back(node);
} else if (tok.type == TokType::CMD_CNT) {
node = std::make_shared<TmpNode>(TMP, "");
((TmpNode*)node.get())->setParent(lastCompleted);
stack.push_back(node);
} else if (tok.type == TokType::CMD_END) {
node = stack.back();
stack.pop_back();
if (!stack.size())
throw std::runtime_error("Too many CMD_ENDs");
if (node->getType() == TMP) {
if (!lastCompleted)
throw std::runtime_error("Noone to absorb children");
NodePtr parent = ((TmpNode*)node.get())->getParent();
parent->absorb(node->getChildren(), 1);
} else {
if (node->getType() == CMD)
lastCompleted = node;
stack.back()->addChild(node);
}
}
}
if (tokens.size())
throw std::runtime_error("Unconsomed tokens");
if (stack.size() != 1)
throw std::runtime_error("Invalid format - !1 stack elems");
NodeVector vec = stack.front()->getChildren(0);
return vec;
}
示例2: renderRoot
static Surface renderRoot(NodePtr node)
{
Surface surf;
Surface root;
Surface radical;
root = render(node->getChildren(0));
NodePtr fakeSqrt = std::make_shared<Node>(CMD, "sqrt");
fakeSqrt->absorb(node->getChildren(1), 0);
radical = renderSqrt(fakeSqrt);
surf.addSurface(root.getBox().w - 1, radical);
surf.addSurface(0, root, 1);
return surf;
}