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


C++ CEvaluationNode类代码示例

本文整理汇总了C++中CEvaluationNode的典型用法代码示例。如果您正苦于以下问题:C++ CEvaluationNode类的具体用法?C++ CEvaluationNode怎么用?C++ CEvaluationNode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了CEvaluationNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: type

// TODO Replace the recursive call (not critical since only used for debug)
void CEvaluationNode::printRecursively(std::ostream & os, int indent) const
{
  int i;

  os << std::endl;

  for (i = 0; i < indent; ++i) os << " ";

  os << "mData: " << mData << std::endl;

  for (i = 0; i < indent; ++i) os << " ";

  os << "mType: " << type(mType) << "  subType: " << subType(mType) << std::endl;

  for (i = 0; i < indent; ++i) os << " ";

  os << "mValue: " << mValue << std::endl;

  CEvaluationNode* tmp;

  tmp = (CEvaluationNode*)getChild();

  while (tmp)
    {
      tmp -> printRecursively(os, indent + 2);
      tmp = (CEvaluationNode*)tmp->getSibling();
    }
}
开发者ID:PriKalra,项目名称:COPASI,代码行数:29,代码来源:CEvaluationNode.cpp

示例2: if

bool CEvaluationNode::operator<(const CEvaluationNode& right) const
{
  bool result = false;

  if (this->getType() < right.getType())
    {
      result = true;
    }
  else if (this->getType() == right.getType())
    {
      switch (CEvaluationNode::type(this->getType()))
        {
          case CEvaluationNode::CONSTANT:
          case CEvaluationNode::NUMBER:
          case CEvaluationNode::OBJECT:
          case CEvaluationNode::CALL:
          case CEvaluationNode::STRUCTURE:
          case CEvaluationNode::VARIABLE:
          case CEvaluationNode::WHITESPACE:
            result = (this->getData() < right.getData());
            break;

          case CEvaluationNode::OPERATOR:
          case CEvaluationNode::FUNCTION:
          case CEvaluationNode::CHOICE:
          case CEvaluationNode::LOGICAL:
          case CEvaluationNode::MV_FUNCTION:
          case CEvaluationNode::VECTOR:
          case CEvaluationNode::DELAY:
          case CEvaluationNode::INVALID:
            break;
        }

      const CEvaluationNode* pChild1 = dynamic_cast<const CEvaluationNode*>(this->getChild());

      const CEvaluationNode* pChild2 = dynamic_cast<const CEvaluationNode*>(right.getChild());

      while (result == false)
        {
          if (pChild1 == NULL || pChild2 == NULL)
            {
              if (pChild1 == NULL && pChild2 != NULL)
                {
                  result = true;
                }
            }
          else
            {
              result = (*pChild1 < *pChild2);
            }

          pChild1 = dynamic_cast<const CEvaluationNode*>(pChild1->getSibling());
          pChild2 = dynamic_cast<const CEvaluationNode*>(pChild2->getSibling());
        }
    }

  return result;
}
开发者ID:PriKalra,项目名称:COPASI,代码行数:58,代码来源:CEvaluationNode.cpp

示例3: create

CEvaluationNode* CEvaluationNode::copyNode(const std::vector<CEvaluationNode*>& children) const
{
  CEvaluationNode *newnode = create(mType, getData());
  std::vector<CEvaluationNode*>::const_iterator it = children.begin(), endit = children.end();

  while (it != endit)
    {
      newnode->addChild(*it);
      ++it;
    }

  return newnode;
}
开发者ID:mgaldzic,项目名称:copasi_api,代码行数:13,代码来源:CEvaluationNode.cpp

示例4: while

//static
void CDerive::compileTree(CEvaluationNode* node, const CEvaluationTree * pTree)
{
  if (!node) return;

  node->compile(pTree);

  CEvaluationNode* child = dynamic_cast<CEvaluationNode*>(node->getChild());

  while (child != NULL)
    {
      compileTree(child, pTree);
      child = dynamic_cast<CEvaluationNode*>(child->getSibling());
    }
}
开发者ID:mgaldzic,项目名称:copasi_api,代码行数:15,代码来源:CDerive.cpp

示例5: if

CEvaluationNode* CEvaluationNodeNormalizer::normalizePowerNode(const CEvaluationNodeOperator* pNode)
{
  CEvaluationNode* pResult = NULL;

  if (pNode != NULL)
    {
      CEvaluationNode* pChild1 = CEvaluationNodeNormalizer::normalize(dynamic_cast<const CEvaluationNode*>(pNode->getChild()));

      if (pChild1 != NULL)
        {
          CEvaluationNode* pChild2 = CEvaluationNodeNormalizer::normalize(dynamic_cast<const CEvaluationNode*>(pNode->getChild()->getSibling()));

          if (pChild2 != NULL)
            {
              if (CEvaluationNode::type(pChild2->getType()) == CEvaluationNode::NUMBER)
                {
                  if (pChild2->value() - 1.0 < ZERO)
                    {
                      // replace it with the first child
                      pResult = pChild1;
                      delete pChild2;
                      pChild2 = NULL;
                    }
                  else if (pChild2->value() < ZERO)
                    {
                      // replace it by a number node of 1
                      pResult = new CEvaluationNodeNumber(CEvaluationNodeNumber::INTEGER, "1");
                      delete pChild1;
                      delete pChild2;
                      pChild1 = NULL;
                      pChild2 = NULL;
                    }
                }
              else
                {
                  pResult = new CEvaluationNodeOperator(CEvaluationNodeOperator::POWER, "^");
                  pResult->addChild(pChild1);
                  pResult->addChild(pChild2);
                }
            }
        }

      if (pResult == NULL) pResult = pNode->copyBranch();
    }

  return pResult;
}
开发者ID:mgaldzic,项目名称:copasi_api,代码行数:47,代码来源:CEvaluationNodeNormalizer.cpp

示例6: CEvaluationNodeOperator

CEvaluationNode * CMathExpression::createMassActionPart(const C_FLOAT64 * pK,
    const CCallParameters< C_FLOAT64 > * pSpecies)
{
  CEvaluationNode * pPart = new CEvaluationNodeOperator(CEvaluationNode::S_MULTIPLY, "*");
  pPart->addChild(createNodeFromValue(pK));

  if (pSpecies->size() == 0)
    return pPart;

  CEvaluationNode * pNode = pPart;
  CCallParameters< C_FLOAT64 >::const_iterator itSpecies = pSpecies->begin();
  CCallParameters< C_FLOAT64 >::const_iterator endSpecies = pSpecies->end();

  for (; itSpecies != endSpecies - 1; ++itSpecies)
    {
      CEvaluationNode * p = new CEvaluationNodeOperator(CEvaluationNode::S_MULTIPLY, "*");
      p->addChild(createNodeFromValue(itSpecies->value));
      pNode->addChild(p);
      pNode = p;
    }

  pNode->addChild(createNodeFromValue(itSpecies->value));

  return pPart;
}
开发者ID:,项目名称:,代码行数:25,代码来源:

示例7: deleteBranch

CEvaluationNode* CDerive::subtract(CEvaluationNode *n1, CEvaluationNode *n2, bool simplify)
{
  if (simplify)
    {
      if (isZero(n1))
        {
          if (isZero(n2))
            {
              deleteBranch(n1);
              deleteBranch(n2);
              return new CEvaluationNodeNumber(CEvaluationNodeNumber::INTEGER, "0");
            }

          //else
          //{
          //  deleteBranch(n1);
          //  return n2;
          //}
        }

      if (isZero(n2))
        {
          deleteBranch(n2);
          return n1;
        }

      // "numerical" simplification
      const CEvaluationNodeNumber * tmp1 = dynamic_cast<CEvaluationNodeNumber*>(n1);
      const CEvaluationNodeNumber * tmp2 = dynamic_cast<CEvaluationNodeNumber*>(n2);

      if (tmp1 && tmp2)
        {
          CEvaluationNode* tmpNN = new CEvaluationNodeNumber(tmp1->getValue() - tmp2->getValue());
          return tmpNN;
        }
    }

  CEvaluationNode *newNode = new CEvaluationNodeOperator(CEvaluationNodeOperator::MINUS, "-");
  newNode->addChild(n1);
  newNode->addChild(n2);

  return newNode;
}
开发者ID:jonasfoe,项目名称:COPASI,代码行数:43,代码来源:CDerive.cpp

示例8: assert

// static
CEvaluationNode * CEvaluationNodeDelay::fromAST(const ASTNode * pASTNode, const std::vector< CEvaluationNode * > & children)
{
  assert(pASTNode->getNumChildren() == children.size());

  size_t i = 0, iMax = children.size();

  SubType subType = SubType::DELAY;
  std::string data = "delay";

  CEvaluationNode * pConvertedNode = new CEvaluationNodeDelay(subType, data);

  for (i = 0; i < iMax; ++i)
    {
      pConvertedNode->addChild(children[i]);
    }

  pConvertedNode->compile(NULL);
  return pConvertedNode;
}
开发者ID:copasi,项目名称:COPASI,代码行数:20,代码来源:CEvaluationNodeDelay.cpp

示例9: switch

void CMathObject::appendDelays(CMath::DelayData & Delays) const
{
  if (mpExpression == NULL)
    {
      return;
    }

  std::vector< CEvaluationNode * >::const_iterator it = mpExpression->getNodeList().begin();
  std::vector< CEvaluationNode * >::const_iterator end = mpExpression->getNodeList().end();

  for (; it != end; ++it)
    {
      switch (CEvaluationNode::type((*it)->getType()))
        {
          case CEvaluationNode::DELAY:
          {
            CEvaluationNode * pValueExpression = static_cast< CEvaluationNode * >((*it)->getChild());
            std::string Expression = static_cast< CEvaluationNode * >(pValueExpression->getSibling())->buildInfix();

            CMath::DelayData::iterator found = Delays.find(Expression);

            if (found == Delays.end())
              {
                found = Delays.insert(std::make_pair(Expression, CMath::DelayValueData()));
              }

            Expression = pValueExpression->buildInfix();
            found->second.insert(std::make_pair(Expression, std::make_pair((*it)->buildInfix(), const_cast< CMathObject * >(this))));
          }
          break;

          default:
            break;
        }
    }

  return;
}
开发者ID:jonasfoe,项目名称:COPASI,代码行数:38,代码来源:CMathObject.cpp

示例10: mainType

bool CEvaluationNode::operator<(const CEvaluationNode& right) const
{
  if (mainType() != right.mainType())
    {
      return mainType() < right.mainType();
    }

  if (subType() != right.subType())
    {
      return subType() < right.subType();
    }

  switch (mainType())
    {
      case T_CONSTANT:
      case T_NUMBER:
      case T_OBJECT:
      case T_CALL:
      case T_STRUCTURE:
      case T_VARIABLE:
      case T_WHITESPACE:
        return getData() < right.getData();
        break;

      case T_OPERATOR:
      case T_FUNCTION:
      case T_CHOICE:
      case T_LOGICAL:
      case T_MV_FUNCTION:
      case T_VECTOR:
      case T_DELAY:
      case T_INVALID:
        break;
    }

  const CEvaluationNode* pChild1 = dynamic_cast<const CEvaluationNode*>(this->getChild());
  const CEvaluationNode* pChild2 = dynamic_cast<const CEvaluationNode*>(right.getChild());

  while (true)
    {
      if (pChild1 == NULL || pChild2 == NULL)
        {
          return pChild1 < pChild2;
        }

      if (*pChild1 < *pChild2) return true;

      pChild1 = dynamic_cast<const CEvaluationNode*>(pChild1->getSibling());
      pChild2 = dynamic_cast<const CEvaluationNode*>(pChild2->getSibling());
    }

  return false;
}
开发者ID:,项目名称:,代码行数:53,代码来源:

示例11: deriveBranch

CEvaluationNode* CDerive::deriveBranch(const CEvaluationNode* node, unsigned C_INT32 variableIndex, const CCopasiObject * pObject)
{
  CEvaluationNode * newNode = NULL;

  const CEvaluationNodeOperator * pENO = dynamic_cast<const CEvaluationNodeOperator*>(node);

  if (pENO)
    {
      if (!pENO->getLeft() || !pENO->getRight()) return NULL;

      CEvaluationNode * pLeftDeriv = deriveBranch(pENO->getLeft(), variableIndex, pObject);

      if (!pLeftDeriv) return NULL;

      CEvaluationNode * pRightDeriv = deriveBranch(pENO->getRight(), variableIndex, pObject);

      if (!pRightDeriv) {delete pLeftDeriv; return NULL;}

      // we now know that derivations of the left and right branch exist

      switch ((CEvaluationNodeOperator::SubType) CEvaluationNode::subType(pENO->getType()))
        {
          case CEvaluationNodeOperator::MULTIPLY:
          {
            CEvaluationNode * pLeftCopy = pENO->getLeft()->copyBranch();
            CEvaluationNode * pRightCopy = pENO->getRight()->copyBranch();

            newNode = new CEvaluationNodeOperator(CEvaluationNodeOperator::PLUS, "+");

            CEvaluationNodeOperator * tmpNode;
            tmpNode = new CEvaluationNodeOperator(CEvaluationNodeOperator::MULTIPLY, "*");
            tmpNode->addChild(pRightCopy);
            tmpNode->addChild(pLeftDeriv);
            //tmpNode->compile(NULL);
            newNode->addChild(tmpNode);

            tmpNode = new CEvaluationNodeOperator(CEvaluationNodeOperator::MULTIPLY, "*");
            tmpNode->addChild(pRightDeriv);
            tmpNode->addChild(pLeftCopy);
            //tmpNode->compile(NULL);
            newNode->addChild(tmpNode);

            //if (newNode) newNode->compile(NULL);
            return newNode;
          }
          break;

          case CEvaluationNodeOperator::DIVIDE:
          {
            CEvaluationNode * pLeftCopy = pENO->getLeft()->copyBranch();
            CEvaluationNode * pRightCopy = pENO->getRight()->copyBranch();

            //numerator
            CEvaluationNodeOperator * minusNode = new CEvaluationNodeOperator(CEvaluationNodeOperator::MINUS, "+");

            CEvaluationNodeOperator * tmpNode;
            tmpNode = new CEvaluationNodeOperator(CEvaluationNodeOperator::MULTIPLY, "*");
            tmpNode->addChild(pRightCopy);
            tmpNode->addChild(pLeftDeriv);
            //tmpNode->compile(NULL);
            minusNode->addChild(tmpNode);

            tmpNode = new CEvaluationNodeOperator(CEvaluationNodeOperator::MULTIPLY, "*");
            tmpNode->addChild(pRightDeriv);
            tmpNode->addChild(pLeftCopy);
            //tmpNode->compile(NULL);
            minusNode->addChild(tmpNode);

            minusNode->compile(NULL);

            //denominator
            CEvaluationNodeOperator * powerNode = new CEvaluationNodeOperator(CEvaluationNodeOperator::POWER, "^");
            pRightCopy = pENO->getRight()->copyBranch();  //new copy
            powerNode->addChild(pRightCopy);
            powerNode->addChild(new CEvaluationNodeNumber(CEvaluationNodeNumber::INTEGER, "2"));
            //powerNode->compile(NULL);

            newNode = new CEvaluationNodeOperator(CEvaluationNodeOperator::DIVIDE, "/");
            newNode->addChild(minusNode);
            newNode->addChild(powerNode);
            //if (newNode) newNode->compile(NULL);
            return newNode;
          }
          break;

          case CEvaluationNodeOperator::PLUS:
            newNode = new CEvaluationNodeOperator(CEvaluationNodeOperator::PLUS, "+");
            newNode->addChild(pLeftDeriv);
            newNode->addChild(pRightDeriv);
            //TODO check for zeros

            //if (newNode) newNode->compile(NULL);
            return newNode;
            break;

          case CEvaluationNodeOperator::MINUS:
            newNode = new CEvaluationNodeOperator(CEvaluationNodeOperator::MINUS, "-");
            newNode->addChild(pLeftDeriv);
            newNode->addChild(pRightDeriv);
            //TODO check for zeros
//.........这里部分代码省略.........
开发者ID:mgaldzic,项目名称:copasi_api,代码行数:101,代码来源:CDerive.cpp

示例12: deriveBranch

//TODO remove pModel
CEvaluationNode* CDerive::deriveBranch(const CEvaluationNode* node, const CCopasiObject * pObject,
                                       std::vector<const CEvaluationNode*>& env,
                                       //std::vector<const CCopasiObject*>& objenv,
                                       const CEvaluationTree* pTree,
                                       bool simplify)
{
  CEvaluationNode * newNode = NULL;

  const CEvaluationNodeOperator * pENO = dynamic_cast<const CEvaluationNodeOperator*>(node);

  if (pENO)
    {
      if (!pENO->getLeft() || !pENO->getRight()) return NULL;

      CEvaluationNode * pLeftDeriv = deriveBranch(pENO->getLeft(), pObject, env, pTree, simplify);

      if (!pLeftDeriv) return NULL;

      CEvaluationNode * pRightDeriv = deriveBranch(pENO->getRight(), pObject, env, pTree, simplify);

      if (!pRightDeriv) {delete pLeftDeriv; return NULL;}

      // we now know that derivations of the left and right branch exist

      switch ((CEvaluationNodeOperator::SubType) CEvaluationNode::subType(pENO->getType()))
        {
          case CEvaluationNodeOperator::MULTIPLY:
          {
            CEvaluationNode * pLeftCopy = copyBranch_var2obj(pENO->getLeft(), env);
            CEvaluationNode * pRightCopy = copyBranch_var2obj(pENO->getRight(), env);

            CEvaluationNode * tmpNode1 = multiply(pRightCopy, pLeftDeriv, simplify);
            CEvaluationNode * tmpNode2 = multiply(pRightDeriv, pLeftCopy, simplify);

            return add(tmpNode1, tmpNode2, simplify);
          }
          break;

          case CEvaluationNodeOperator::DIVIDE:
          {
            CEvaluationNode * pLeftCopy = copyBranch_var2obj(pENO->getLeft(), env);
            CEvaluationNode * pRightCopy = copyBranch_var2obj(pENO->getRight(), env);

            //numerator
            CEvaluationNode * tmpNode1 = multiply(pRightCopy, pLeftDeriv, simplify);
            CEvaluationNode * tmpNode2 = multiply(pRightDeriv, pLeftCopy, simplify);

            CEvaluationNode * minusNode = subtract(tmpNode1, tmpNode2, simplify);

            minusNode->compile(NULL);

            //denominator
            CEvaluationNode * powerNode = power(copyBranch_var2obj(pENO->getRight(), env),
                                                new CEvaluationNodeNumber(CEvaluationNodeNumber::INTEGER, "2"),
                                                simplify);

            return divide(minusNode, powerNode, simplify);
          }
          break;

          case CEvaluationNodeOperator::PLUS:

            return add(pLeftDeriv, pRightDeriv, simplify);
            break;

          case CEvaluationNodeOperator::MINUS:

            return subtract(pLeftDeriv, pRightDeriv, simplify);
            break;

          case CEvaluationNodeOperator::POWER:
          {
            // b-1
            CEvaluationNode * tmpNode = subtract(copyBranch_var2obj(pENO->getRight(), env),
                                                 new CEvaluationNodeNumber(CEvaluationNodeNumber::INTEGER, "1"),
                                                 simplify);

            // a^(b-1)
            CEvaluationNode * powerNode = power(copyBranch_var2obj(pENO->getLeft(), env), tmpNode, simplify);

            // b*a'
            tmpNode = multiply(copyBranch_var2obj(pENO->getRight(), env),
                               pLeftDeriv, simplify);

            // ln a
            CEvaluationNodeFunction * funcNode = new CEvaluationNodeFunction(CEvaluationNodeFunction::LOG, "ln");
            funcNode->addChild(copyBranch_var2obj(pENO->getLeft(), env)); // add a

            // a * b' * ln a
            CEvaluationNode * tmpNode2 = multiply(copyBranch_var2obj(pENO->getLeft(), env),
                                                  multiply(pRightDeriv, funcNode, simplify),
                                                  simplify);

            // b*a + a*b * ln a
            CEvaluationNode * plusNode = add(tmpNode, tmpNode2, simplify);

            // a^(b-1)*(b*a + a*b * ln a)
            return multiply(powerNode, plusNode, simplify);
          }
//.........这里部分代码省略.........
开发者ID:jonasfoe,项目名称:COPASI,代码行数:101,代码来源:CDerive.cpp

示例13: infix

void test_depth_first_iterator::test_dfi()
{
  std::string infix("7-(3+(4-6))+1*8");
  CEvaluationTree* pTree = new CEvaluationTree();
  pTree->setInfix(infix);
  std::string s = pTree->getInfix();
  CPPUNIT_ASSERT(pTree->getRoot() != NULL);
  CEvaluationNodeDepthFirstIterator it(pTree->getRoot());
  CPPUNIT_ASSERT(it.isValid());
  CEvaluationNode* pNode = NULL;
  CEvaluationNodeNumber* pNumberNode = NULL;
  CEvaluationNodeOperator* pOperatorNode = NULL;
  // 7
  pNode = *it;
  CPPUNIT_ASSERT(pNode != NULL);
  CPPUNIT_ASSERT(CEvaluationNode::type(pNode->getType()) == CEvaluationNode::NUMBER);
  pNumberNode = dynamic_cast<CEvaluationNodeNumber*>(pNode);
  CPPUNIT_ASSERT(pNumberNode != NULL);
  CPPUNIT_ASSERT((fabs(pNumberNode->getValue() - 7) / 7.0) <= std::numeric_limits<double>::min());
  // 3
  ++it;
  CPPUNIT_ASSERT(it.isValid() == true);
  pNode = *it;
  CPPUNIT_ASSERT(pNode != NULL);
  CPPUNIT_ASSERT(CEvaluationNode::type(pNode->getType()) == CEvaluationNode::NUMBER);
  pNumberNode = dynamic_cast<CEvaluationNodeNumber*>(pNode);
  CPPUNIT_ASSERT(pNumberNode != NULL);
  CPPUNIT_ASSERT((fabs(pNumberNode->getValue() - 3) / 3.0) <= std::numeric_limits<double>::min());
  // 4
  ++it;
  CPPUNIT_ASSERT(it.isValid() == true);
  pNode = *it;
  CPPUNIT_ASSERT(pNode != NULL);
  CPPUNIT_ASSERT(CEvaluationNode::type(pNode->getType()) == CEvaluationNode::NUMBER);
  pNumberNode = dynamic_cast<CEvaluationNodeNumber*>(pNode);
  CPPUNIT_ASSERT(pNumberNode != NULL);
  CPPUNIT_ASSERT((fabs(pNumberNode->getValue() - 4) / 4.0) <= std::numeric_limits<double>::min());
  // 6
  ++it;
  CPPUNIT_ASSERT(it.isValid() == true);
  pNode = *it;
  CPPUNIT_ASSERT(pNode != NULL);
  CPPUNIT_ASSERT(CEvaluationNode::type(pNode->getType()) == CEvaluationNode::NUMBER);
  pNumberNode = dynamic_cast<CEvaluationNodeNumber*>(pNode);
  CPPUNIT_ASSERT(pNumberNode != NULL);
  CPPUNIT_ASSERT((fabs(pNumberNode->getValue() - 6) / 6.0) <= std::numeric_limits<double>::min());
  // -
  ++it;
  CPPUNIT_ASSERT(it.isValid() == true);
  pNode = *it;
  CPPUNIT_ASSERT(pNode != NULL);
  CPPUNIT_ASSERT(CEvaluationNode::type(pNode->getType()) == CEvaluationNode::OPERATOR);
  pOperatorNode = dynamic_cast<CEvaluationNodeOperator*>(pNode);
  CPPUNIT_ASSERT(pOperatorNode != NULL);
  CPPUNIT_ASSERT((CEvaluationNodeOperator::SubType)CEvaluationNode::subType(pOperatorNode->getType()) == CEvaluationNodeOperator::MINUS);
  // +
  ++it;
  CPPUNIT_ASSERT(it.isValid() == true);
  pNode = *it;
  CPPUNIT_ASSERT(pNode != NULL);
  CPPUNIT_ASSERT(CEvaluationNode::type(pNode->getType()) == CEvaluationNode::OPERATOR);
  pOperatorNode = dynamic_cast<CEvaluationNodeOperator*>(pNode);
  CPPUNIT_ASSERT(pOperatorNode != NULL);
  CPPUNIT_ASSERT((CEvaluationNodeOperator::SubType)CEvaluationNode::subType(pOperatorNode->getType()) == CEvaluationNodeOperator::PLUS);
  // -
  ++it;
  CPPUNIT_ASSERT(it.isValid() == true);
  pNode = *it;
  CPPUNIT_ASSERT(pNode != NULL);
  CPPUNIT_ASSERT(CEvaluationNode::type(pNode->getType()) == CEvaluationNode::OPERATOR);
  pOperatorNode = dynamic_cast<CEvaluationNodeOperator*>(pNode);
  CPPUNIT_ASSERT(pOperatorNode != NULL);
  CPPUNIT_ASSERT((CEvaluationNodeOperator::SubType)CEvaluationNode::subType(pOperatorNode->getType()) == CEvaluationNodeOperator::MINUS);
  // 1
  ++it;
  CPPUNIT_ASSERT(it.isValid() == true);
  pNode = *it;
  CPPUNIT_ASSERT(pNode != NULL);
  CPPUNIT_ASSERT(CEvaluationNode::type(pNode->getType()) == CEvaluationNode::NUMBER);
  pNumberNode = dynamic_cast<CEvaluationNodeNumber*>(pNode);
  CPPUNIT_ASSERT(pNumberNode != NULL);
  CPPUNIT_ASSERT((fabs(pNumberNode->getValue() - 1) / 1.0) <= std::numeric_limits<double>::min());
  // 8
  ++it;
  CPPUNIT_ASSERT(it.isValid() == true);
  pNode = *it;
  CPPUNIT_ASSERT(pNode != NULL);
  CPPUNIT_ASSERT(CEvaluationNode::type(pNode->getType()) == CEvaluationNode::NUMBER);
  pNumberNode = dynamic_cast<CEvaluationNodeNumber*>(pNode);
  CPPUNIT_ASSERT(pNumberNode != NULL);
  CPPUNIT_ASSERT((fabs(pNumberNode->getValue() - 8) / 8.0) <= std::numeric_limits<double>::min());
  // *
  ++it;
  CPPUNIT_ASSERT(it.isValid() == true);
  pNode = *it;
  CPPUNIT_ASSERT(pNode != NULL);
  CPPUNIT_ASSERT(CEvaluationNode::type(pNode->getType()) == CEvaluationNode::OPERATOR);
  pOperatorNode = dynamic_cast<CEvaluationNodeOperator*>(pNode);
  CPPUNIT_ASSERT(pOperatorNode != NULL);
  CPPUNIT_ASSERT((CEvaluationNodeOperator::SubType)CEvaluationNode::subType(pOperatorNode->getType()) == CEvaluationNodeOperator::MULTIPLY);
//.........这里部分代码省略.........
开发者ID:ShuoLearner,项目名称:COPASI,代码行数:101,代码来源:test_depth_first_iterator.cpp

示例14: switch

CEvaluationNode* CEvaluationNodeLogical::createNodeFromASTTree(const ASTNode& node)
{
  SubType subType;
  std::string data = "";

  switch (node.getType())
    {
      case AST_LOGICAL_AND:
        subType = AND;
        data = "and";
        break;
      case AST_LOGICAL_OR:
        subType = OR;
        data = "or";
        break;
      case AST_LOGICAL_XOR:
        subType = XOR;
        data = "xor";
        break;
      case AST_RELATIONAL_EQ:
        subType = EQ;
        data = "eq";
        break;
      case AST_RELATIONAL_GEQ:
        subType = GE;
        data = "ge";
        break;
      case AST_RELATIONAL_GT:
        subType = GT;
        data = "gt";
        break;
      case AST_RELATIONAL_LEQ:
        subType = LE;
        data = "le";
        break;
      case AST_RELATIONAL_LT:
        subType = LT;
        data = "lt";
        break;
      case AST_RELATIONAL_NEQ:
        subType = NE;
        data = "ne";
        break;
      default:
        subType = INVALID;
        break;
    }

  CEvaluationNode* convertedNode = new CEvaluationNodeLogical(subType, data);
  // convert the two children
  int i, iMax = node.getNumChildren();

  switch (subType)
    {
      case AND:
      case OR:
      case XOR:
        // these can have two or more children
        assert(iMax >= 2);
        convertedNode->addChild(CEvaluationTree::convertASTNode(*node.getChild(iMax - 1)));
        convertedNode->addChild(CEvaluationTree::convertASTNode(*node.getChild(iMax - 2)));
        iMax -= 3;

        for (i = iMax; i >= 0; --i)
          {
            CEvaluationNode* pTmpNode = new CEvaluationNodeLogical(subType, data);
            pTmpNode->addChild(convertedNode);
            pTmpNode->addChild(CEvaluationTree::convertASTNode(*node.getChild(i)));
            convertedNode = pTmpNode;
          }

        break;
      case EQ:
      case NE:
      case GE:
      case GT:
      case LE:
      case LT:
        // all these are binary
        convertedNode->addChild(CEvaluationTree::convertASTNode(*node.getLeftChild()));
        convertedNode->addChild(CEvaluationTree::convertASTNode(*node.getRightChild()));
        break;
      case INVALID:
        // do nothing
        break;
    }

  return convertedNode;
}
开发者ID:mgaldzic,项目名称:copasi_api,代码行数:89,代码来源:CEvaluationNodeLogical.cpp

示例15: assert

// static
CEvaluationNode * CEvaluationNodeLogical::fromAST(const ASTNode * pASTNode, const std::vector< CEvaluationNode * > & children)
{
    assert(pASTNode->getNumChildren() == children.size());

    size_t i = 0;
    size_t iMax = children.size();

    SubType subType;
    std::string data = "";

    switch (pASTNode->getType())
    {
    case AST_LOGICAL_AND:
        subType = AND;
        data = "and";
        break;

    case AST_LOGICAL_OR:
        subType = OR;
        data = "or";
        break;

    case AST_LOGICAL_XOR:
        subType = XOR;
        data = "xor";
        break;

    case AST_RELATIONAL_EQ:
        subType = EQ;
        data = "eq";
        break;

    case AST_RELATIONAL_GEQ:
        subType = GE;
        data = "ge";
        break;

    case AST_RELATIONAL_GT:
        subType = GT;
        data = "gt";
        break;

    case AST_RELATIONAL_LEQ:
        subType = LE;
        data = "le";
        break;

    case AST_RELATIONAL_LT:
        subType = LT;
        data = "lt";
        break;

    case AST_RELATIONAL_NEQ:
        subType = NE;
        data = "ne";
        break;

    default:
        subType = INVALID;
        break;
    }

    CEvaluationNode* pNode = NULL;
    // convert the two children

    switch (subType)
    {
    case AND:
    case OR:
    case XOR:

        // The number of chidren may vary
        switch (iMax)
        {
        case 0:

            if (subType == AND)
                pNode = new CEvaluationNodeConstant(CEvaluationNodeConstant::TRUE, "TRUE");
            else
                pNode = new CEvaluationNodeConstant(CEvaluationNodeConstant::FALSE, "FALSE");

            break;

        case 1:
            pNode = children[0];
            break;

        default:
        {
            pNode = new CEvaluationNodeLogical(subType, data);
            CEvaluationNode * pCurrent = pNode;

            // We have at least 2 children
            while (i < iMax - 1)
            {
                // add the first value
                pCurrent->addChild(children[i++]);

                switch (iMax - i)
//.........这里部分代码省略.........
开发者ID:jonasfoe,项目名称:COPASI,代码行数:101,代码来源:CEvaluationNodeLogical.cpp


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