本文整理汇总了C++中NodeRefPtr::addNode方法的典型用法代码示例。如果您正苦于以下问题:C++ NodeRefPtr::addNode方法的具体用法?C++ NodeRefPtr::addNode怎么用?C++ NodeRefPtr::addNode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NodeRefPtr
的用法示例。
在下文中一共展示了NodeRefPtr::addNode方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: invalid_argument
/* Throws std::invalid_argument if any argument is invalid */
void
Tree::addSubNodes(NodeRefPtr parent, XMLElement &thisNode,
KVMRefCntPtr env)
{
string resName;
if(thisNode.isNamed(RESOURCE_RESULT) &&
thisNode.getAttributeValue(NAME, resName)) {
XMLElement decn;
NodeRefPtr newNode;
if(thisNode.getSubElement(POLICY_DECISION, decn)) {
PDRefCntPtr decision =
PolicyDecision::construct_policy_decision(resName, decn,
env);
newNode = new Node(parent, decision);
// If the parent is NULL, then this is the root Node.
if(parent != NULL) {
parent->addNode(newNode);
} else {
rootNode = newNode;
}
} else {
throw std::invalid_argument("Tree:addSubNodes(...) Cannot find "
"Policy Decision node under resource "
"result.");
}
XMLElement subElems;
if(thisNode.getSubElement(RESOURCE_RESULT, subElems)) {
for(;subElems.isValid(); subElems.nextSibling(RESOURCE_RESULT)) {
addSubNodes(newNode, subElems, env);
}
}
} else {
throw std::invalid_argument("Tree::addSubNodes(...) has an invalid XML as input.");
}
}
示例2: newNode
bool
Tree::insertBelow(NodeRefPtr parent, PDRefCntPtr &elem) {
std::list<NodeRefPtr>::iterator iter;
NodeRefPtr newNode(new Node(parent, elem));
// add the subordinate nodes of newNode under
// new node. In the next loop, we iterate nodes
// under new node and remove them from parent.
// Reason: if we remove nodes under parent in this
// loop, iterator becomes invalid.
ScopeLock myLock(treeLock);
for(iter = parent->begin(); iter != parent->end(); iter++) {
NodeRefPtr node = *iter;
PDRefCntPtr data = node->getPolicyDecision();
switch(compare(data->getName(), elem->getName(), false)) {
case AM_EXACT_MATCH:
case AM_SUB_RESOURCE_MATCH:
return false;
case AM_NO_MATCH:
break;
case AM_SUPER_RESOURCE_MATCH:
newNode->addNode(node);
break;
}
}
for(iter = newNode->begin(); iter != newNode->end(); iter++) {
NodeRefPtr node = *iter;
parent->remove(node);
}
parent->addNode(newNode);
return true;
}