本文整理汇总了C++中BTreeNode::setValue方法的典型用法代码示例。如果您正苦于以下问题:C++ BTreeNode::setValue方法的具体用法?C++ BTreeNode::setValue怎么用?C++ BTreeNode::setValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BTreeNode
的用法示例。
在下文中一共展示了BTreeNode::setValue方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: compileConditional
void Expression::compileConditional( const QString & expression, Code * ifCode, Code * elseCode )
{
if( expression.contains(QRegExp("=>|=<|=!")) )
{
mistake( Microbe::InvalidComparison, expression );
return;
}
if( expression.contains(QRegExp("[^=><!][=][^=]")))
{
mistake( Microbe::InvalidEquals );
return;
}
// Make a tree to put the expression in.
BTreeBase *tree = new BTreeBase();
BTreeNode *root = new BTreeNode();
// parse the expression into the tree
buildTree(expression,tree,root,0);
// Modify the tree so it is always at the top level of the form (kwoerpkwoep) == (qwopekqpowekp)
if ( root->childOp() != equals &&
root->childOp() != notequals &&
root->childOp() != gt &&
root->childOp() != lt &&
root->childOp() != ge &&
root->childOp() != le &&
root->childOp() != pin &&
root->childOp() != notpin &&
root->childOp() != read_keypad )
{
BTreeNode *newRoot = new BTreeNode();
BTreeNode *oneNode = new BTreeNode();
oneNode->setChildOp(noop);
oneNode->setType(number);
oneNode->setValue("1");
newRoot->setLeft(root);
newRoot->setRight(oneNode);
newRoot->setType(unset);
newRoot->setChildOp(ge);
tree->setRoot(newRoot);
root = newRoot;
}
// compile the tree into assembly code
tree->setRoot(root);
tree->pruneTree(tree->root(),true);
// We might have just a constant expression, in which case we can just always do if or else depending
// on whether it is true or false.
if( root->childOp() == noop )
{
if( root->value().toInt() == 0 )
m_pic->mergeCode( elseCode );
else
m_pic->mergeCode( ifCode );
return;
}
// traverse tree with argument conditionalRoot true
// so that 3 == x gets integrated with code for if, repeat until etc...
m_ifCode = ifCode;
m_elseCode = elseCode;
traverseTree(tree->root(),true);
// Note deleting the tree deletes all nodes, so the root
// doesn't need deleting separately.
delete tree;
}
示例2: pruneTree
void BTreeBase::pruneTree(BTreeNode *root, bool /*conditionalRoot*/)
{
Traverser t(root);
t.descendLeftwardToTerminal();
bool done = false;
while(!done)
{
//t.descendLeftwardToTerminal();
if( t.current()->parent() )
{
if( t.oppositeNode()->hasChildren() ) pruneTree(t.oppositeNode());
}
t.moveToParent();
if( !t.current()->hasChildren() )
{
//if(t.current() == t.root()) done = true;
if(!t.current()->parent()) done = true;
continue;
}
BTreeNode *l = t.current()->left();
BTreeNode *r = t.current()->right();
BTreeNode *n = 0;
BTreeNode *z = 0;
// Deal with situations where there are two constants so we want
// to evaluate at compile time
if( (l->type() == number && r->type() == number) ) // && !(t.current()==root&&conditionalRoot) )
{
if(t.current()->childOp() == Expression::division && r->value() == "0" )
{
t.current()->setChildOp(Expression::divbyzero);
return;
}
QString value = QString::number(Parser::doArithmetic(l->value().toInt(),r->value().toInt(),t.current()->childOp()));
t.current()->deleteChildren();
t.current()->setChildOp(Expression::noop);
t.current()->setType(number);
t.current()->setValue(value);
}
// Addition and subtraction
else if(t.current()->childOp() == Expression::addition || t.current()->childOp() == Expression::subtraction)
{
// See if one of the nodes is 0, and set n to the node that actually has data,
// z to the one containing zero.
bool zero = false;
if( l->value() == "0" )
{
zero = true;
n = r;
z = l;
}
else if( r->value() == "0" )
{
zero = true;
n = l;
z = r;
}
// Now get rid of the useless nodes
if(zero)
{
BTreeNode *p = t.current(); // save in order to delete after
replaceNode(p,n);
t.setCurrent(n);
// Delete the old nodes
delete p;
delete z;
}
}
// Multiplication and division
else if(t.current()->childOp() == Expression::multiplication || t.current()->childOp() == Expression::division)
{
// See if one of the nodes is 0, and set n to the node that actually has data,
// z to the one containing zero.
bool zero = false;
bool one = false;
if( l->value() == "1" )
{
one = true;
n = r;
z = l;
}
else if( r->value() == "1" )
{
one = true;
n = l;
z = r;
}
if( l->value() == "0" )
{
zero = true;
n = r;
z = l;
}
//.........这里部分代码省略.........
示例3: buildTree
//.........这里部分代码省略.........
// ^
case 4:
{
int exppos = findSkipBrackets(expression, '^');
if( exppos != -1 )
{
op = exponent;
firstEnd = exppos;
secondStart = exppos + 1;
}
else op = noop;
break;
}
// AND, OR, XOR
case 5:
{
int bwAndPos = findSkipBrackets(expression, " AND ");
int bwOrPos = findSkipBrackets(expression, " OR ");
int bwXorPos = findSkipBrackets(expression, " XOR ");
if( bwAndPos != -1 )
{
op = bwand;
firstEnd = bwAndPos;
secondStart = bwAndPos + 5;
}
else if( bwOrPos != -1 )
{
op = bwor;
firstEnd = bwOrPos;
secondStart = bwOrPos + 4;
}
else if( bwXorPos != -1 )
{
op = bwxor;
firstEnd = bwXorPos;
secondStart = bwXorPos + 5;
}
else op = noop;
break;
}
// NOT
case 6:
{
int bwNotPos = findSkipBrackets(expression, " NOT ");
if( bwNotPos != -1 )
{
op = bwnot;
unary = true;
firstEnd = bwNotPos; // this line is not needed for unary things/
secondStart = bwNotPos + 5;
}
else op = noop;
break;
}
}
node->setChildOp(op);
QString tokens[2];
tokens[0] = expression.left(firstEnd).trimmed();
tokens[1] = expression.mid(secondStart).trimmed();
if( op != noop )
{
for( int j = 0; j < 2; j++ )
{
BTreeNode *newNode = new BTreeNode();
tree->addNode( node, newNode, (j == 0) );
// we need to strip any brackets from the sub-expression
// try each token again at the same level, if they
// don't have any of this level's operators, then the function
// will go to the next level as below.
// For unary opertaions, e.g NOT, we have no special
// code for nodes with only one child, so we leave the left
// hand child blank and put the rest in the right hand node.
if( unary && j == 0 )
{
newNode->setValue("");
newNode->setType(number);
}
else buildTree(tokens[j], tree, newNode, 0 );
}
}
else
{
// if there was no relevant operation i.e. " 3*4 / 6" as opposed to " 3*4 + 6"
// then just pass the node onto the next parsing level.
// unless we are at the lowest level, in which case we have reached a final value.
if( level == 6 ) expressionValue(expression,tree,node);
else
{
buildTree(expression,tree,node,level + 1);
}
}
}