当前位置: 首页>>代码示例>>C++>>正文


C++ Operand::NestingLevel方法代码示例

本文整理汇总了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;
  }
开发者ID:DeeSee,项目名称:ExpressionParser,代码行数:48,代码来源:ExpressionParser.cpp

示例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;
  }
开发者ID:DeeSee,项目名称:ExpressionParser,代码行数:28,代码来源:ExpressionParser.cpp


注:本文中的Operand::NestingLevel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。