本文整理汇总了C++中ASTNode::setValue方法的典型用法代码示例。如果您正苦于以下问题:C++ ASTNode::setValue方法的具体用法?C++ ASTNode::setValue怎么用?C++ ASTNode::setValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ASTNode
的用法示例。
在下文中一共展示了ASTNode::setValue方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: cleanEquation
ASTNode* CompiledModelGenerator::cleanEquation(ASTNode* astP)
{
ASTNode& ast = *astP; //For convenience...
if (ast.getType() == AST_PLUS && ast.getNumChildren() == 0)
{
ASTNode* result = new ASTNode(AST_INTEGER);
result->setValue(0);
return result;
}
else if (ast.getType() == AST_TIMES && ast.getNumChildren() == 0)
{
ASTNode* result = new ASTNode(AST_INTEGER);
result->setValue(1);
return result;
}
else if ((ast.getType() == AST_PLUS && ast.getNumChildren() == 1) ||
(ast.getType() == AST_TIMES && ast.getNumChildren() == 1))
{
ASTNode *p = ast.getChild(0);
return p ? new ASTNode(*p) : p;
}
for (int i = (int) ast.getNumChildren() - 1; i >= 0; i--)
{
ASTNode *p = ast.getChild(i);
ast.replaceChild(i, cleanEquation(p));
delete p;
}
return new ASTNode(ast);
}
示例2:
/**
* Sets the type of an ASTNode based on the given MathML <cn> element.
* Errors will be logged in the stream's SBMLErrorLog object.
*/
static void
setTypeCN (ASTNode& node, const XMLToken& element, XMLInputStream& stream)
{
string type = "real";
element.getAttributes().readInto("type", type);
// here is the only place we might encounter the sbml:units attribute
string units = "";
element.getAttributes().readInto("units", units);
if (type == "real")
{
double value = 0;
istringstream isreal;
isreal.str( stream.next().getCharacters() );
isreal >> value;
node.setValue(value);
if (isreal.fail()
|| node.isInfinity()
|| node.isNegInfinity()
)
{
static_cast <SBMLErrorLog*>
(stream.getErrorLog())->logError(FailedMathMLReadOfDouble,
stream.getSBMLNamespaces()->getLevel(),
stream.getSBMLNamespaces()->getVersion());
}
}
示例3: writeMathML
/*
* Subclasses should override this method to write out their contained
* SBML objects as XML elements. Be sure to call your parents
* implementation of this method as well.
*/
void
SpeciesReference::writeElements (XMLOutputStream& stream) const
{
if ( mNotes != NULL ) stream << *mNotes;
SpeciesReference * sr = const_cast <SpeciesReference *> (this);
sr->syncAnnotation();
if ( mAnnotation != NULL ) stream << *mAnnotation;
if (getLevel() == 2)
{
if (mStoichiometryMath || mDenominator != 1)
{
if (mStoichiometryMath != NULL)
{
mStoichiometryMath->write(stream);
}
else
{
ASTNode node;
node.setValue(static_cast<long>(mStoichiometry), mDenominator);
stream.startElement("stoichiometryMath");
writeMathML(&node, stream);
stream.endElement("stoichiometryMath");
}
}
}
//
// (EXTENSION)
//
SBase::writeExtensionElements(stream);
}
示例4: toAST
ASTNode* CEvaluationNodeNumber::toAST(const CDataModel* /* pDataModel */) const
{
SubType subType = (SubType)this->subType();
ASTNode* node = new ASTNode();
double num1;
double num2;
const char * end;
const char * str = mData.c_str();
switch (subType)
{
case SubType::DOUBLE:
node->setType(AST_REAL);
node->setValue(*mpValue);
break;
case SubType::INTEGER:
node->setType(AST_INTEGER);
node->setValue((long)*mpValue);
break;
case SubType::ENOTATION:
node->setType(AST_REAL_E);
num2 = floor(log10(*mpValue));
num1 = pow(10.0, log10(*mpValue) - num2);
node->setValue(num1, (long)num2);
break;
case SubType::RATIONALE:
node->setType(AST_RATIONAL);
str++; // Skip the '('
num1 = strToDouble(str, &end);
end++; // Skip the '/'
num2 = strToDouble(end, NULL);
node->setValue((long)num1, (long)num2);
break;
case SubType::INVALID:
break;
}
return node;
}
示例5: if
/**
* Ensures the given ASTNode has the appropriate number of arguments. If
* arguments are missing, appropriate defaults (per the MathML 2.0
* specification) are added:
*
* log (x) -> log (10, x)
* root(x) -> root( 2, x)
*/
static void
checkFunctionArgs (ASTNode& node)
{
if (node.getNumChildren() == 1)
{
if (node.getType() == AST_FUNCTION_LOG)
{
ASTNode* child = new ASTNode;
child->setValue(10);
node.prependChild(child);
}
else if (node.getType() == AST_FUNCTION_ROOT)
{
ASTNode* child = new ASTNode;
child->setValue(2);
node.prependChild(child);
}
}
}
示例6: ASTNode
END_TEST
START_TEST (test_MathMLFromAST_replaceIDWithFunction_2)
{
const char* expected = wrapMathML
(
" <apply>\n"
" <power/>\n"
" <apply>\n"
" <plus/>\n"
" <cn> 1 </cn>\n"
" </apply>\n"
" <cn> 2 </cn>\n"
" </apply>\n"
);
const char* original = wrapMathML
(
" <apply>\n"
" <power/>\n"
" <ci> x </ci>\n"
" <cn> 2 </cn>\n"
" </apply>\n"
);
N = new ASTNode(AST_POWER);
ASTNode *n1 = new ASTNode(AST_NAME);
n1->setName("x");
ASTNode *n2 = new ASTNode();
n2->setValue(2.0);
N->addChild(n1);
N->addChild(n2);
ASTNode *replaced = new ASTNode(AST_PLUS);
ASTNode *c = new ASTNode();
c->setValue(1.0);
replaced->addChild(c);
S = writeMathMLToString(N);
fail_unless( equals(original, S) );
N->replaceIDWithFunction("x", replaced);
S = writeMathMLToString(N);
fail_unless( equals(expected, S) );
}
示例7: toAST
ASTNode* CEvaluationNodeConstant::toAST(const CCopasiDataModel* /*pDataModel*/) const
{
SubType subType = (SubType)this->subType();
ASTNode* node = new ASTNode();
switch (subType)
{
case S_PI:
node->setType(AST_CONSTANT_PI);
break;
case S_EXPONENTIALE:
node->setType(AST_CONSTANT_E);
break;
case S_TRUE:
node->setType(AST_CONSTANT_TRUE);
break;
case S_FALSE:
node->setType(AST_CONSTANT_FALSE);
break;
case S_INFINITY:
node->setType(AST_REAL);
node->setValue(std::numeric_limits<C_FLOAT64>::infinity());
break;
case S_NAN:
case S_INVALID:
node->setType(AST_REAL);
node->setValue(std::numeric_limits<C_FLOAT64>::quiet_NaN());
break;
}
return node;
}
示例8: buildAST
void BoostSpiritGrammar::buildAST(const iter_t &it, ASTNode *parent, const uint32_t &depth) const {
ASTNode *child = NULL;
string key;
for (uint32_t j = 0; j < it->children.size(); j++) {
string data((it->children.begin() + j)->value.begin(), (it->children.begin() + j)->value.end());
boost::algorithm::trim(data);
if ( (data != "") &&
((it->children.begin() + j)->value.id().to_long() == 0) &&
((it->children.begin() + j)->children.size() == 0)
) {
// Keys have no children and an ID of 0 because they are keywords from the grammar.
key = data;
child = new ASTNode(parent);
child->setKey(key);
parent->addChild(child);
} else if ( (data != "") &&
((it->children.begin() + j)->value.id().to_long() > 0) &&
((it->children.begin() + j)->children.size() == 0) ) {
// Values have an ID greater than 0 and no children.
// Check if there's already a child with no value set.
if ( (child == NULL) || (child->getValue<string>() != "") ) {
child = new ASTNode(parent);
parent->addChild(child);
}
child->setKey(key);
child->setValue(data);
} else if ( ((it->children.begin() + j)->value.id().to_long() > 0) &&
((it->children.begin() + j)->children.size() > 0) ) {
// Hierarchically sub-ordered values have also an ID greater than 0 but children as well.
ASTNode *multipleChildren = new ASTNode(parent);
buildAST(it->children.begin() + j, multipleChildren, depth + 1);
multipleChildren->setKey(key);
parent->addChild(multipleChildren);
// ASTNode *multipleChildren = NULL;
// if ( (parent != NULL) && (parent->getLastChild() != NULL) && (parent->getLastChild()->getKey() == key) && (parent->getLastChild()->getValue<string>() == "") ) {
// // Re-use last added child if value is empty AND keys are identical.
// multipleChildren = parent->getLastChild();
// }
// else {
// multipleChildren = new ASTNode(parent);
// parent->addChild(multipleChildren);
// }
// buildAST(it->children.begin() + j, multipleChildren, depth + 1);
// multipleChildren->setKey(key);
}
}
}
示例9: if
void
MMOMath::_processNode (ASTNode* node)
{
ASTNodeType_t t = node->getType ();
if (t == AST_FUNCTION_ROOT)
{
ASTNode *first = new ASTNode (*node->getChild (0));
ASTNode *exp = new ASTNode (AST_DIVIDE);
ASTNode *constant = new ASTNode (AST_REAL);
constant->setValue (1);
exp->addChild (constant);
exp->addChild (first);
node->setType (AST_POWER);
node->removeChild (0);
node->addChild (exp);
}
else if (t == AST_NAME && !_prefix.empty ()
&& node->getId ().compare ("REPLACED_FUNCTION"))
{
string controlName = node->getName ();
string flatName = _prefix + "_";
if (controlName.compare (0, flatName.size (), flatName))
{
flatName.append (node->getName ());
node->setName (flatName.c_str ());
}
}
string package = MMOUtils::getInstance ()->checkPredefinedFunctions (node);
if (!package.empty ())
{
_imports[package] = package;
}
int childs = node->getNumChildren ();
int i;
for (i = 0; i < childs; i++)
{
_processNode (node->getChild (i));
}
}
示例10: convertTimeAndExtent
int Submodel::convertTimeAndExtent()
{
int ret=LIBSBML_OPERATION_SUCCESS;
string tcf = "";
ASTNode* tcf_ast = NULL;
if (isSetTimeConversionFactor()) {
tcf = getTimeConversionFactor();
tcf_ast = new ASTNode(AST_NAME);
tcf_ast->setName(tcf.c_str());
}
string xcf = "";
ASTNode* xcf_ast = NULL;
if (isSetExtentConversionFactor()) {
xcf = getExtentConversionFactor();
xcf_ast = new ASTNode(AST_NAME);
xcf_ast->setName(xcf.c_str());
}
ASTNode* klmod = NULL;
if (xcf_ast != NULL) {
klmod = xcf_ast;
}
if (tcf_ast != NULL) {
if (klmod==NULL) {
klmod = new ASTNode(AST_INTEGER);
klmod->setValue(1);
}
ASTNode* divide = new ASTNode(AST_DIVIDE);
divide->addChild(klmod);
divide->addChild(tcf_ast);
klmod = divide;
}
ret = convertTimeAndExtentWith(tcf_ast, xcf_ast, klmod);
delete klmod;
return ret;
}
示例11: dealWithL1Stoichiometry
void dealWithL1Stoichiometry(Model & m, bool l2)
{
unsigned int idCount = 0;
char newid[15];
std::string id;
for (unsigned int i = 0; i < m.getNumReactions(); i++)
{
Reaction *r = m.getReaction(i);
unsigned int j;
for (j = 0; j < r->getNumReactants(); j++)
{
SpeciesReference *sr = r->getReactant(j);
if (sr->getDenominator() != 1)
{
long stoich = static_cast<long>(sr->getStoichiometry());
int denom = sr->getDenominator();
ASTNode *node = new ASTNode();
node->setValue(stoich, denom);
if (l2 == true)
{
StoichiometryMath * sm = sr->createStoichiometryMath();
sm->setMath(node);
}
else
{
sprintf(newid, "speciesRefId_%u", idCount);
id.assign(newid);
idCount++;
sr->setId(id);
InitialAssignment * ar = m.createInitialAssignment();
ar->setSymbol(id);
ar->setMath(node);
sr->unsetStoichiometry();
}
}
}
for (j = 0; j < r->getNumProducts(); j++)
{
SpeciesReference *sr = r->getProduct(j);
if (sr->getDenominator() != 1)
{
long stoich = static_cast<long>(sr->getStoichiometry());
int denom = sr->getDenominator();
ASTNode *node = new ASTNode();
node->setValue(stoich, denom);
if (l2 == true)
{
StoichiometryMath * sm = sr->createStoichiometryMath();
sm->setMath(node);
}
else
{
sprintf(newid, "speciesRefId_%u", idCount);
id.assign(newid);
idCount++;
sr->setId(id);
InitialAssignment * ar = m.createInitialAssignment();
ar->setSymbol(id);
ar->setMath(node);
sr->unsetStoichiometry();
}
}
}
}
}
示例12: ASTNode
END_TEST
START_TEST(test_SBMLTransforms_evaluateAST)
{
double temp;
const char * mathml;
ASTNode * node = new ASTNode();
node->setValue((int)(2));
fail_unless(SBMLTransforms::evaluateASTNode(node) == 2);
node->setValue((double) (3.2));
fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), 3.2));
node->setValue((long)(1), (long)(4));
fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), 0.25));
node->setValue((double) (4.234), (int) (2));
fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), 423.4));
node->setType(AST_NAME_AVOGADRO);
fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), 6.02214179e23));
node->setType(AST_NAME_TIME);
fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), 0.0));
node->setType(AST_NAME);
fail_unless(util_isNaN(SBMLTransforms::evaluateASTNode(node)));
node->setType(AST_CONSTANT_E);
fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), exp(1.0)));
node->setType(AST_CONSTANT_FALSE);
fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), 0.0));
node->setType(AST_CONSTANT_PI);
fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), 4.0*atan(1.0)));
node->setType(AST_CONSTANT_TRUE);
fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), 1.0));
node = SBML_parseFormula("2.5 + 6.1");
fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), 8.6));
node = SBML_parseFormula("-4.3");
fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), -4.3));
node = SBML_parseFormula("9.2-4.3");
temp = 9.2-4.3;
fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), temp));
node = SBML_parseFormula("2*3");
fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), 6));
node = SBML_parseFormula("1/5");
fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), 0.2));
node = SBML_parseFormula("pow(2, 3)");
fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), 8));
node = SBML_parseFormula("3^3");
fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), 27));
node = SBML_parseFormula("abs(-9.456)");
fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), 9.456));
node = SBML_parseFormula("ceil(9.456)");
fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), 10));
node = SBML_parseFormula("exp(2.0)");
temp = exp(2.0);
fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), temp));
node = SBML_parseFormula("floor(2.04567)");
fail_unless(util_isEqual(SBMLTransforms::evaluateASTNode(node), 2));
node = SBML_parseFormula("ln(2.0)");
//.........这里部分代码省略.........
示例13: ASTNode
END_TEST
START_TEST(test_SBMLTransforms_evaluateAST)
{
double temp;
ASTNode * node = new ASTNode();
node->setValue((int)(2));
fail_unless(SBMLTransforms::evaluateASTNode(node) == 2);
node->setValue((double) (3.2));
fail_unless(equalDouble(SBMLTransforms::evaluateASTNode(node), 3.2));
node->setValue((long)(1), (long)(4));
fail_unless(equalDouble(SBMLTransforms::evaluateASTNode(node), 0.25));
node->setValue((double) (4.234), (int) (2));
fail_unless(equalDouble(SBMLTransforms::evaluateASTNode(node), 423.4));
node->setType(AST_NAME_AVOGADRO);
fail_unless(equalDouble(SBMLTransforms::evaluateASTNode(node), 6.02214179e23));
node->setType(AST_NAME_TIME);
fail_unless(equalDouble(SBMLTransforms::evaluateASTNode(node), 0.0));
node->setType(AST_NAME);
fail_unless(isnan(SBMLTransforms::evaluateASTNode(node)));
node->setType(AST_CONSTANT_E);
fail_unless(equalDouble(SBMLTransforms::evaluateASTNode(node), exp(1.0)));
node->setType(AST_CONSTANT_FALSE);
fail_unless(equalDouble(SBMLTransforms::evaluateASTNode(node), 0.0));
node->setType(AST_CONSTANT_PI);
fail_unless(equalDouble(SBMLTransforms::evaluateASTNode(node), 4.0*atan(1.0)));
node->setType(AST_CONSTANT_TRUE);
fail_unless(equalDouble(SBMLTransforms::evaluateASTNode(node), 1.0));
node = SBML_parseFormula("2.5 + 6.1");
fail_unless(equalDouble(SBMLTransforms::evaluateASTNode(node), 8.6));
node = SBML_parseFormula("-4.3");
fail_unless(equalDouble(SBMLTransforms::evaluateASTNode(node), -4.3));
node = SBML_parseFormula("9.2-4.3");
temp = 9.2-4.3;
fail_unless(equalDouble(SBMLTransforms::evaluateASTNode(node), temp));
node = SBML_parseFormula("2*3");
fail_unless(equalDouble(SBMLTransforms::evaluateASTNode(node), 6));
node = SBML_parseFormula("1/5");
fail_unless(equalDouble(SBMLTransforms::evaluateASTNode(node), 0.2));
node = SBML_parseFormula("pow(2, 3)");
fail_unless(equalDouble(SBMLTransforms::evaluateASTNode(node), 8));
node = SBML_parseFormula("3^3");
fail_unless(equalDouble(SBMLTransforms::evaluateASTNode(node), 27));
node = SBML_parseFormula("abs(-9.456)");
fail_unless(equalDouble(SBMLTransforms::evaluateASTNode(node), 9.456));
node = SBML_parseFormula("ceil(9.456)");
fail_unless(equalDouble(SBMLTransforms::evaluateASTNode(node), 10));
node = SBML_parseFormula("exp(2.0)");
temp = exp(2.0);
fail_unless(equalDouble(SBMLTransforms::evaluateASTNode(node), temp));
node = SBML_parseFormula("floor(2.04567)");
fail_unless(equalDouble(SBMLTransforms::evaluateASTNode(node), 2));
node = SBML_parseFormula("ln(2.0)");
temp = log(2.0);
//.........这里部分代码省略.........
示例14: toAST
ASTNode* CEvaluationNodeFunction::toAST(const CCopasiDataModel* pDataModel) const
{
SubType subType = (SubType)this->subType();
ASTNode* node = new ASTNode();
bool needFirstArg = true;
switch (subType)
{
case S_INVALID:
break;
case S_LOG:
node->setType(AST_FUNCTION_LN);
break;
case S_LOG10:
{
// log 10 needs two children, the log and the base
node->setType(AST_FUNCTION_LOG);
ASTNode* logBase = new ASTNode();
logBase->setType(AST_INTEGER);
logBase->setValue(10);
node->addChild(logBase);
break;
}
case S_EXP:
node->setType(AST_FUNCTION_EXP);
break;
case S_SIN:
node->setType(AST_FUNCTION_SIN);
break;
case S_COS:
node->setType(AST_FUNCTION_COS);
break;
case S_TAN:
node->setType(AST_FUNCTION_TAN);
break;
case S_SEC:
node->setType(AST_FUNCTION_SEC);
break;
case S_CSC:
node->setType(AST_FUNCTION_CSC);
break;
case S_COT:
node->setType(AST_FUNCTION_COT);
break;
case S_SINH:
node->setType(AST_FUNCTION_SINH);
break;
case S_COSH:
node->setType(AST_FUNCTION_COSH);
break;
case S_TANH:
node->setType(AST_FUNCTION_TANH);
break;
case S_SECH:
node->setType(AST_FUNCTION_SECH);
break;
case S_CSCH:
node->setType(AST_FUNCTION_CSCH);
break;
case S_COTH:
node->setType(AST_FUNCTION_COTH);
break;
case S_ARCSIN:
node->setType(AST_FUNCTION_ARCSIN);
break;
case S_ARCCOS:
node->setType(AST_FUNCTION_ARCCOS);
break;
case S_ARCTAN:
node->setType(AST_FUNCTION_ARCTAN);
break;
case S_ARCSEC:
node->setType(AST_FUNCTION_ARCSEC);
break;
case S_ARCCSC:
node->setType(AST_FUNCTION_ARCCSC);
break;
//.........这里部分代码省略.........