本文整理汇总了C++中TNode::getValue方法的典型用法代码示例。如果您正苦于以下问题:C++ TNode::getValue方法的具体用法?C++ TNode::getValue怎么用?C++ TNode::getValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TNode
的用法示例。
在下文中一共展示了TNode::getValue方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
void bsTree<T>::remove(const T & item)
{
TNode<T> *tN = search(root, item); //Returns node of value, item.
if(!tN) //if node is not found, remove nothing.
return;
TNode<T> *pN= tN->getParent(); //Points to tN's parent.
if(tN->getLeft() == NULL && tN->getRight() == NULL) //node is leaf
{
removeLink(tN, pN, NULL);
}
else if(tN->hasOnlyLeft()) //Node has only left child
{
removeLink(tN, pN, tN->getLeft());
}
else if(tN->hasOnlyRight()) //Node has only right child
{
removeLink(tN, pN, tN->getRight());
}
else // has two children
{
if(tN->getValue() > root->getValue())
{
getSmallest(tN->getRight(), tN, tN);
}
else
{
getBiggest(tN->getLeft(), tN, tN);
}
}
}
示例2: fillResult
string QueryEvaluator::fillResult(TNode * node, int value) {
string name = node->getValue();
string type = table.getType(name);
// special case
if (type==KEYWORD_CALL) {
if (node->getNumChildren()!=0) {
TNode * attr = node->getChildAtIndex(0);
if (attr->getType()==Attr &&
attr->getValue()=="procName") {
value = PKB::getCalledProc(value);
type=KEYWORD_PROCEDURE;
}
}
}
if (type==KEYWORD_PROCEDURE) {
return PKB::getProcName(value);
} else if (type==KEYWORD_VAR) {
return PKB::getVarName(value);
} else if (type==KEYWORD_CONST) {
return PKB::getConstName(value);
} else if (type==KEYWORD_PROG_LINE || SyntaxHelper::isStmtSymbol(type)) {
return to_string((long long)value);
} else {
}
return "-1";
}
示例3: atoi
vector<int> QueryEvaluator::getAttrIndex(TNode * node, string attr_value) {
vector<int> result;
string symbol_name = node->getValue();
Symbol symbol_type = SyntaxHelper::getSymbolType(table.getType(symbol_name));
if (symbol_type==CallStmt) {
TNode * attr = node->getChildAtIndex(0);
if (attr->getValue()=="procName") {
result = PKB::getCallingStmt(PKB::getProcIndex(attr_value).front());
return result;
}
}
switch(symbol_type) {
case Procedure:
{
result.push_back(PKB::getProcIndex(attr_value).front());
break;
}
case Var:
{
result.push_back(PKB::getVarIndex(attr_value));
break;
}
case Const:
{
result.push_back(PKB::getConstIndex(attr_value));
break;
}
case Prog_line:
case Stmt:
case Assign:
case If:
case While:
case CallStmt:
{
int value = atoi(attr_value.c_str());
if ((value>0 && value<PKB::getStatTableSize()) &&
(table.getType(symbol_name)==KEYWORD_STMT ||
table.getType(symbol_name)==KEYWORD_PROG_LINE ||
table.getType(symbol_name)==PKB::getStmtName(value))) {
result.push_back(value);
}
break;
}
default:
break;
}
//remove all values = -1
if (result.size()==1 && result[0]==-1) {
result.clear();
}
return result;
}
示例4: getAttrValue
string QueryEvaluator::getAttrValue(TNode * node, int index) {
string result = "-1";
if (index==-1) return result;
string symbol_name = node->getValue();
Symbol symbol_type = SyntaxHelper::getSymbolType(table.getType(symbol_name));
switch(symbol_type) {
case Procedure:
{
result = PKB::getProcName(index);
break;
}
case Var:
{
result = PKB::getVarName(index);
break;
}
case Const:
{
result = PKB::getConstName(index);
break;
}
case Stmt:
case Prog_line:
case Assign:
case While:
case If:
case CallStmt:
{
if (symbol_type==CallStmt) {
TNode * attr = node->getChildAtIndex(0);
if (attr->getValue()=="procName") {
result = PKB::getProcName(PKB::getCalledProc(index));
} else {
result = to_string((long long)index);
}
} else {
result = to_string((long long)index);
}
break;
}
default:
break;
}
return result;
}
示例5: getSymbolsUsedBy
vector<string> QueryEvaluator::getSymbolsUsedBy(TNode * node) {
vector<string> results;
int size = node->getNumChildren();
for (int i=0; i<size; i++) {
TNode * child = node->getChildAtIndex(i);
if (child->getType()==QuerySymbol) {
results.push_back(child->getValue());
}
vector<string> sub_results = getSymbolsUsedBy(child);
for (size_t j=0; j<sub_results.size(); j++) {
if (find(results.begin(), results.end(), sub_results[j])==results.end())
results.push_back(sub_results[j]);
}
}
return results;
}