本文整理汇总了C++中Operand::NestingLevel方法的典型用法代码示例。如果您正苦于以下问题:C++ Operand::NestingLevel方法的具体用法?C++ Operand::NestingLevel怎么用?C++ Operand::NestingLevel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Operand
的用法示例。
在下文中一共展示了Operand::NestingLevel方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CalculateSequenceForPriority
std::vector<ExpressionItem*> CalculateSequenceForPriority(const std::vector<ExpressionItem*> i_sequence,
OperatorPriority i_priority)
{
assert(i_sequence.size() != 0);
std::vector<ExpressionItem*> result;
size_t currentLoc = 0;
while (currentLoc < i_sequence.size())
{
switch (i_sequence[currentLoc]->Type())
{
case ExpressionItemTypeOperand:
{
Operand* operand = dynamic_cast<Operand*>(i_sequence[currentLoc]);
result.push_back(new Operand(operand->GetValue(), operand->NestingLevel(), 0));
currentLoc++;
break;
}
case ExpressionItemTypeBinaryOperator:
{
BinaryOperator* bOperator = dynamic_cast<BinaryOperator*>(i_sequence[currentLoc]);
if (bOperator->Priority() == i_priority)
{
assert(result.size() != 0);
assert(result.back()->Type() == ExpressionItemTypeOperand);
assert(currentLoc < i_sequence.size() - 1);
assert(i_sequence[currentLoc + 1]->Type() == ExpressionItemTypeOperand);
Operand* left = dynamic_cast<Operand*>(result.back());
Operand* right = dynamic_cast<Operand*>(i_sequence[currentLoc + 1]);
double value = bOperator->CalculateResultForOperands(*left, *right);
delete left;
result.back() = new Operand(value, right->NestingLevel(), 0);
currentLoc += 2;
}
else
{
result.push_back(BinaryOperator::Copy(bOperator));
currentLoc++;
}
break;
}
default:
assert(false);
}
}
return result;
}
示例2: CopyItems
std::vector<ExpressionItem*> CopyItems(const std::vector<ExpressionItem*>& i_items,
size_t i_from,
size_t i_to)
{
std::vector<ExpressionItem*> result;
result.reserve(i_items.size());
for (size_t i = i_from; i < i_to; ++i)
{
switch (i_items[i]->Type())
{
case ExpressionItemTypeOperand:
{
Operand* operand = dynamic_cast<Operand*>(i_items[i]);
result.push_back(new Operand(operand->GetValue(), operand->NestingLevel(), 0));
break;
}
case ExpressionItemTypeBinaryOperator:
{
BinaryOperator* bOperator = dynamic_cast<BinaryOperator*>(i_items[i]);
result.push_back(BinaryOperator::Copy(bOperator));
break;
}
}
}
return result;
}