C_INT32 CFunctionDB::load(CReadConfig &configbuffer) { CFunction Function; CFunction * pFunction = NULL; C_INT32 Size = 0; C_INT32 Fail = 0; configbuffer.getVariable("TotalUDKinetics", "C_INT32", &Size, CReadConfig::LOOP); for (C_INT32 i = 0; i < Size; i++) { Function.load(configbuffer); switch (Function.getType()) { case CEvaluationTree::Function: pFunction = new CFunction(Function); break; case CEvaluationTree::MassAction: pFunction = new CMassAction(Function); break; case CEvaluationTree::PreDefined: case CEvaluationTree::UserDefined: pFunction = new CKinFunction(Function, &configbuffer); break; default: fatalError(); break; } pFunction->compile(); if (!mLoadedFunctions.add(pFunction, true)) { pdelete(pFunction); // We ignore: // CCopasiVector (2): Object '%s' allready exists. if ((MCCopasiVector + 2) != CCopasiMessage::peekLastMessage().getNumber()) return Fail = 1; // Remove the ignored meesage. CCopasiMessage::getLastMessage(); } } return Fail; }
CMathExpression::CMathExpression(const CFunction & src, const CCallParameters< C_FLOAT64 > & callParameters, CMathContainer & container, const bool & replaceDiscontinuousNodes): CEvaluationTree(src.getObjectName(), &container, CEvaluationTree::MathExpression), mPrerequisites() { clearNodes(); // Deal with the different function types switch (src.getType()) { case CEvaluationTree::Function: case CEvaluationTree::PreDefined: case CEvaluationTree::UserDefined: { // Create a vector of CEvaluationNodeObject for each variable CMath::Variables< CEvaluationNode * > Variables; CCallParameters< C_FLOAT64 >::const_iterator it = callParameters.begin(); CCallParameters< C_FLOAT64 >::const_iterator end = callParameters.end(); for (; it != end; ++it) { Variables.push_back(createNodeFromValue(it->value)); } // Create a converted copy of the existing expression tree. mpRootNode = container.copyBranch(src.getRoot(), Variables, replaceDiscontinuousNodes); // Deleted the created variables CMath::Variables< CEvaluationNode * >::iterator itVar = Variables.begin(); CMath::Variables< CEvaluationNode * >::iterator endVar = Variables.end(); for (; itVar != endVar; ++itVar) { pdelete(*itVar); } } break; case CEvaluationTree::MassAction: { // We build a mass action expression based on the call parameters. CCallParameters< C_FLOAT64 >::const_iterator it = callParameters.begin(); // Handle the case we were have an invalid number of call parameters. if (callParameters.size() < 2) { mpRootNode = NULL; } else { // We always have reactants const C_FLOAT64 * pK = it->value; ++it; const CCallParameters< C_FLOAT64 > * pSpecies = it->vector; ++it; CEvaluationNode * pPart = createMassActionPart(pK, pSpecies); if (callParameters.size() < 4) { mpRootNode = pPart; } else { mpRootNode = new CEvaluationNodeOperator(CEvaluationNode::S_MINUS, "-"); mpRootNode->addChild(pPart); pK = it->value; ++it; pSpecies = it->vector; ++it; pPart = createMassActionPart(pK, pSpecies); mpRootNode->addChild(pPart); } } } break; case CEvaluationTree::MathExpression: case CEvaluationTree::Expression: // This cannot happen and is only here to satisfy the compiler. break; } compile(); }