本文整理汇总了C++中UnitDefinition类的典型用法代码示例。如果您正苦于以下问题:C++ UnitDefinition类的具体用法?C++ UnitDefinition怎么用?C++ UnitDefinition使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UnitDefinition类的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: START_TEST
END_TEST
START_TEST (test_unitdefinition_convert_SI2)
{
UnitDefinition *ud = new UnitDefinition(1, 1);
UnitDefinition *ud1;
Unit * u = ud->createUnit();
u->setKind(UNIT_KIND_FARAD);
ud1 = UnitDefinition::convertToSI(ud);
fail_unless( ud1->getNumUnits() == 4);
fail_unless( ud1->getLevel() == 1);
fail_unless( ud1->getVersion() == 1);
fail_unless( ud1->getUnit(0)->getKind() == UNIT_KIND_AMPERE );
fail_unless( ud1->getUnit(0)->getExponent() == 2);
fail_unless( ud1->getUnit(1)->getKind() == UNIT_KIND_KILOGRAM );
fail_unless( ud1->getUnit(1)->getExponent() == -1);
fail_unless( ud1->getUnit(2)->getKind() == UNIT_KIND_METRE );
fail_unless( ud1->getUnit(2)->getExponent() == -2);
fail_unless( ud1->getUnit(3)->getKind() == UNIT_KIND_SECOND );
fail_unless( ud1->getUnit(3)->getExponent() == 4);
UnitDefinition_free(ud);
}
开发者ID:0u812,项目名称:roadrunner-backup,代码行数:28,代码来源:TestUtilsUnitDefinition.cpp
示例2: START_TEST
END_TEST
#if (0)
START_TEST (test_getUnitDefinition_power_minus_double_exponent)
{
ASTNode * node = new ASTNode(AST_POWER);
ASTNode * c = new ASTNode(AST_NAME);
c->setName("k");
ASTNode * c1 = new ASTNode(AST_REAL);
c1->setValue(0.3);
ASTNode * c2 = new ASTNode(AST_MINUS);
c2->addChild(c1);
node->addChild(c);
node->addChild(c2);
UnitDefinition * ud = NULL;
ud = uff->getUnitDefinition(node);
fail_unless(uff->getContainsUndeclaredUnits() == false);
fail_unless(uff->canIgnoreUndeclaredUnits() == false);
fail_unless(ud != NULL);
fail_unless(ud->getNumUnits() == 1);
fail_unless(ud->getUnit(0)->getKind() == UNIT_KIND_METRE);
fail_unless(util_isEqual(ud->getUnit(0)->getExponentAsDouble(), -0.3));
delete node;
delete ud;
}
开发者ID:sys-bio,项目名称:libroadrunner-deps,代码行数:32,代码来源:TestUnitFormulaFormatter3.cpp
示例3: UnitDefinition
/*
* Converts a Watt Unit into the corresponding UnitDefinition
* consisting only of SI units.
* If the given unit does not have the correct kind, a NULL pointer is
* returned.
* It is up to the receiver to free the memory of the returned
* UnitDefinition.
* @param const Unit& unit
* @return UnitDefinition* result
*/
LIBSBML_EXTERN
UnitDefinition* UnitConversionFactory::convertWattToSI(const Unit& unit)
{
UnitKind_t uKind = unit.getKind();
if (uKind != UNIT_KIND_WATT) return NULL;
UnitDefinition* pUdef = new UnitDefinition(UnitConversionFactory::SBML_LEVEL, UnitConversionFactory::SBML_VERSION);
Unit* pU = new Unit(unit);
pU->setOffset(0.0);
pU->setKind(UNIT_KIND_KILOGRAM);
pU->setExponent(unit.getExponent());
pUdef->addUnit(pU);
delete pU;
pU = new Unit(UnitConversionFactory::SBML_LEVEL, UnitConversionFactory::SBML_VERSION);
pU->setKind(UNIT_KIND_METER);
pU->setExponent(2*unit.getExponent());
pUdef->addUnit(pU);
delete pU;
pU = new Unit(UnitConversionFactory::SBML_LEVEL, UnitConversionFactory::SBML_VERSION);
pU->setKind(UNIT_KIND_SECOND);
pU->setExponent(-3*unit.getExponent());
pUdef->addUnit(pU);
delete pU;
return pUdef;
}
开发者ID:jonasfoe,项目名称:COPASI,代码行数:36,代码来源:UnitConversionFactory.cpp
示例4: START_TEST
END_TEST
START_TEST ( test_UnitDefinition_parent_NULL )
{
SBMLDocument *d = new SBMLDocument();
Model *m = d->createModel();
UnitDefinition *c = m->createUnitDefinition();
Unit *u = c->createUnit();
fail_unless(u->getAncestorOfType(SBML_UNIT_DEFINITION) == c);
UnitDefinition *c1 = c->clone();
delete d;
fail_unless(c1->getAncestorOfType(SBML_MODEL) == NULL);
fail_unless(c1->getParentSBMLObject() == NULL);
fail_unless (c1->getSBMLDocument() == NULL);
fail_unless(c1->getUnit(0)->getAncestorOfType(SBML_UNIT_DEFINITION) == c1);
fail_unless(c1->getUnit(0)->getParentSBMLObject() != NULL);
fail_unless (c1->getUnit(0)->getSBMLDocument() == NULL);
delete c1;
}
开发者ID:alexholehouse,项目名称:SBMLIntegrator,代码行数:25,代码来源:TestSBMLParentObject.cpp
示例5: START_TEST
END_TEST
START_TEST (test_WriteL3SBML_UnitDefinition)
{
const char* expected =
"<unitDefinition id=\"myUnit\">\n"
" <listOfUnits>\n"
" <unit kind=\"mole\" exponent=\"1\" scale=\"0\" multiplier=\"1.8\"/>\n"
" </listOfUnits>\n"
"</unitDefinition>";
UnitDefinition* ud = D->createModel()->createUnitDefinition();
ud->setId("myUnit");
Unit* u1 = ud->createUnit();
u1->setKind(UnitKind_forName("mole"));
u1->setMultiplier(1.8);
u1->setScale(0);
u1->setExponent(1);
char* sbml = ud->toSBML();
fail_unless( equals(expected, sbml) );
safe_free(sbml);
}
开发者ID:sn248,项目名称:Rcppsbml,代码行数:26,代码来源:TestWriteL3SBML.cpp
示例6: UnitDefinition
/**
* Checks that the units of the arguments
* of the function are dimensionless
* and that there is only one argument
*
* If inconsistent units are found, an error message is logged.
*/
void
ArgumentsUnitsCheckWarnings::checkDimensionlessArgs (const Model& m,
const ASTNode& node,
const SBase & sb,
bool inKL, int reactNo)
{
/* check that node has children */
if (node.getNumChildren() == 0)
{
return;
}
UnitDefinition *dim = new UnitDefinition(m.getSBMLNamespaces());
Unit *unit = new Unit(m.getSBMLNamespaces());
unit->setKind(UNIT_KIND_DIMENSIONLESS);
unit->initDefaults();
UnitDefinition * tempUD;
dim->addUnit(unit);
UnitFormulaFormatter *unitFormat = new UnitFormulaFormatter(&m);
tempUD = unitFormat->getUnitDefinition(node.getChild(0), inKL, reactNo);
if (tempUD->getNumUnits() != 0 &&
!UnitDefinition::areEquivalent(dim, tempUD))
{
logInconsistentDimensionless(node, sb);
}
delete tempUD;
delete dim;
delete unit;
delete unitFormat;
}
开发者ID:mgaldzic,项目名称:copasi_api,代码行数:42,代码来源:ArgumentsUnitsCheckWarnings.cpp
示例7: START_TEST
END_TEST
START_TEST ( test_UnitDefinition_L1 )
{
UnitDefinition* ud = new UnitDefinition(1, 2);
fail_unless (ud->hasRequiredElements());
delete ud;
}
开发者ID:kirichoi,项目名称:roadrunner,代码行数:10,代码来源:TestRequiredElements.cpp
示例8: START_TEST
END_TEST
START_TEST (test_CalcUnitDefinition_local1)
{
UnitDefinition *fud = m->getReaction("R5")->getKineticLaw()
->getLocalParameter(0)->getDerivedUnitDefinition();
fail_unless(fud->getNumUnits() == 0);
m->getReaction("R5")->getKineticLaw()
->getLocalParameter(0)->setCalculatingUnits(true);
fud = m->getReaction("R5")->getKineticLaw()
->getLocalParameter(0)->getDerivedUnitDefinition();
m->getReaction("R5")->getKineticLaw()
->getLocalParameter(0)->setCalculatingUnits(false);
fail_unless(fud->getNumUnits() == 1);
fail_unless(!strcmp(fud->getId().c_str(), ""), NULL);
fail_unless(fud->getUnit(0)->getMultiplier() == 1);
fail_unless(fud->getUnit(0)->getScale() == 0);
fail_unless(fud->getUnit(0)->getExponent() == 1);
fail_unless(fud->getUnit(0)->getOffset() == 0.0);
fail_unless(fud->getUnit(0)->getKind() == UNIT_KIND_SECOND);
}
开发者ID:0u812,项目名称:libsbml.js.frozen,代码行数:26,代码来源:TestCalculatedUnitDefinitions.cpp
示例9: toString
/*
* Returns a string representation of the given Unit. THis function is
* only for debugging purposes.
* @param const UnitDefinition& uDef
* @return std::string unitDefinitionRepresentation
*/
LIBSBML_EXTERN
std::string UnitConversionFactory::toString(const UnitDefinition& uDef)
{
unsigned int maxUnits = uDef.getNumUnits();
unsigned int i;
std::stringstream ss;
for (i = 0; i < maxUnits; ++i)
{
ss << "(" << UnitConversionFactory::toString(*(uDef.getUnit(i))) << ") ";
}
return ss.str();
}
开发者ID:jonasfoe,项目名称:COPASI,代码行数:20,代码来源:UnitConversionFactory.cpp
示例10: START_TEST
END_TEST
START_TEST ( test_UnitDefinition )
{
UnitDefinition* ud = new UnitDefinition(2, 4);
fail_unless (!(ud->hasRequiredAttributes()));
ud->setId("ud");
fail_unless (ud->hasRequiredAttributes());
delete ud;
}
开发者ID:alexholehouse,项目名称:SBMLIntegrator,代码行数:14,代码来源:TestRequiredAttributes.cpp
示例11: getMathML
std::string Expression2PresentationMMLUnits::getMathML(const UnitDefinition & ud) const
{
std::string tmp;
/*tmp += "<mrow>";
unsigned int i, imax = ud.getNumUnits();
for (i=0; i<imax; ++i)
{
if (i) tmp += "<mo>·</mo>";
tmp += getMathML(ud.getUnit(i), false);
}
tmp += "</mrow>";*/
tmp += "<mrow>";
bool isFirst = true;
unsigned int i, imax = ud.getNumUnits();
for (i = 0; i < imax; ++i)
{
if (ud.getUnit(i)->getExponent() >= 0)
{
if (!isFirst) tmp += "<mo>·</mo>";
tmp += getMathML(ud.getUnit(i), true);
isFirst = false;
}
}
if (isFirst) tmp += "<mn>1</mn>"; //there are no units with pos. exponent
std::string tmp2;
isFirst = true;
for (i = 0; i < imax; ++i)
{
if (ud.getUnit(i)->getExponent() < 0)
{
if (!isFirst) tmp2 += "<mo>·</mo>";
tmp2 += getMathML(ud.getUnit(i), true);
isFirst = false;
}
}
if (!isFirst) tmp += "<mo>/</mo>" + tmp2; //only create fraction when there is a denominator
tmp += "</mrow>";
return tmp;
}
开发者ID:mgaldzic,项目名称:copasi_api,代码行数:50,代码来源:Expression2PresentationMMLUnits.cpp
示例12: START_TEST
END_TEST
START_TEST (test_UnitFormulaFormatter2_getUnitDefinition_model_extent)
{
UnitDefinition * ud = NULL;
/* model extent units */
ud = uff->getExtentUnitDefinition();
fail_unless(ud->getNumUnits() == 1);
fail_unless(!strcmp(ud->getId().c_str(), ""), NULL);
fail_unless(ud->getUnit(0)->getMultiplier() == 1);
fail_unless(ud->getUnit(0)->getScale() == 0);
fail_unless(ud->getUnit(0)->getExponent() == 1);
fail_unless(ud->getUnit(0)->getOffset() == 0.0);
fail_unless(ud->getUnit(0)->getKind() == UNIT_KIND_MOLE);
/* check deals with invalid nodes */
delete ud;
UnitDefinition * ud1 = NULL;
m->unsetExtentUnits();
ud1 = uff->getExtentUnitDefinition();
fail_unless (ud1->getNumUnits() == 0);
delete ud1;
}
开发者ID:sys-bio,项目名称:libroadrunner-deps,代码行数:34,代码来源:TestUnitFormulaFormatter2.cpp
示例13: START_TEST
END_TEST
START_TEST (test_UnitFormulaFormatter_getUnitDefinition_plus)
{
UnitDefinition * ud = new UnitDefinition(2, 4);
ud = uff->getUnitDefinition(m->getRule(3)->getMath());
fail_unless(ud->getNumUnits() == 1);
fail_unless(!strcmp(ud->getId().c_str(), ""), NULL);
fail_unless(ud->getUnit(0)->getMultiplier() == 1);
fail_unless(ud->getUnit(0)->getScale() == 0);
fail_unless(ud->getUnit(0)->getExponent() == 1);
fail_unless(ud->getUnit(0)->getOffset() == 0.0);
fail_unless(ud->getUnit(0)->getKind() == UNIT_KIND_METRE);
/* check an invalid node */
delete ud;
UnitDefinition * ud1 = new UnitDefinition(m->getLevel(), m->getVersion());
ASTNode *node = new ASTNode(AST_PLUS);
ud1 = uff->getUnitDefinition(node);
fail_unless (ud1->getNumUnits() == 0);
delete ud1;
delete node;
}
开发者ID:mgaldzic,项目名称:copasi_api,代码行数:30,代码来源:TestUnitFormulaFormatter.cpp
示例14: getUnits
/*
* Constructs and returns a UnitDefinition that expresses the units of this
* LocalParameter.
*/
UnitDefinition *
LocalParameter::getDerivedUnitDefinition()
{
/* if we have the whole model but it is not in a document
* it is still possible to determine the units
*/
Model * m = static_cast <Model *> (getAncestorOfType(SBML_MODEL));
if (m != NULL)
{
if (!m->isPopulatedListFormulaUnitsData())
{
m->populateListFormulaUnitsData();
}
UnitDefinition *ud = NULL;
const char * units = getUnits().c_str();
if (!strcmp(units, ""))
{
ud = new UnitDefinition(getSBMLNamespaces());
return ud;
}
else
{
if (UnitKind_isValidUnitKindString(units,
getLevel(), getVersion()))
{
Unit * unit = new Unit(getSBMLNamespaces());
unit->setKind(UnitKind_forName(units));
unit->initDefaults();
ud = new UnitDefinition(getSBMLNamespaces());
ud->addUnit(unit);
delete unit;
}
else
{
/* must be a unit definition */
ud = static_cast <Model *> (getAncestorOfType(SBML_MODEL))->getUnitDefinition(units);
}
return ud;
}
}
else
{
return NULL;
}
}
开发者ID:alexholehouse,项目名称:SBMLIntegrator,代码行数:53,代码来源:LocalParameter.cpp
示例15: UnitDefinition
/*
* Checks that the units of the delay function are consistent
*
* If inconsistent units are found, an error message is logged.
*/
void
ArgumentsUnitsCheck::checkUnitsFromDelay (const Model& m,
const ASTNode& node,
const SBase & sb, bool inKL, int reactNo)
{
/* check that node has two children */
if (node.getNumChildren() != 2)
{
return;
}
if (!m.getSBMLNamespaces()->getNamespaces())
{
#if 0
cout << "[DEBUG] XMLNS IS NULL" << endl;
#endif
}
/* delay(x, t)
* no restrictions on units of x
* but t must have units of time
*/
UnitDefinition *time = new UnitDefinition(m.getSBMLNamespaces());
Unit *unit = new Unit(m.getSBMLNamespaces());
unit->setKind(UNIT_KIND_SECOND);
unit->initDefaults();
UnitDefinition * tempUD;
time->addUnit(unit);
UnitFormulaFormatter *unitFormat = new UnitFormulaFormatter(&m);
tempUD = unitFormat->getUnitDefinition(node.getRightChild(), inKL, reactNo);
if (!unitFormat->getContainsUndeclaredUnits())
{
if (!UnitDefinition::areEquivalent(time, tempUD))
{
logInconsistentDelay(node, sb);
}
}
delete time;
delete tempUD;
delete unit;
delete unitFormat;
checkUnits(m, *node.getLeftChild(), sb, inKL, reactNo);
}
开发者ID:sbmlteam,项目名称:python-libsbml,代码行数:53,代码来源:ArgumentsUnitsCheck.cpp
示例16: containsOnlyGivenUnits
/*
* The functions determins wether the given UnitDefinition contains only
* units from the list given as the second argument.
* @param const UnitDefinition& uDef
* @param const ListOf& unitList
* @return bool containsOnlyGivenUnits
*/
LIBSBML_EXTERN
bool UnitConversionFactory::containsOnlyGivenUnits(const UnitDefinition& uDef, const ListOf& unitList)
{
bool result = true;
UnitDefinition* pTmpUdef = UnitConversionFactory::convertToSI(uDef);
if (pTmpUdef)
{
unsigned int i;
unsigned int maxUnits = pTmpUdef->getNumUnits();
for (i = 0; i < maxUnits; ++i)
{
Unit* pU = pTmpUdef->getUnit(i);
UnitKind_t kind = pU->getKind();
unsigned int j;
unsigned int maxUnits2 = unitList.size();
bool found = false;
for (j = 0; j < maxUnits2; ++j)
{
const Unit* pU2 = dynamic_cast<const Unit*>(unitList.get(j));
if (!pU2) break;
if (pU2->getKind() == kind)
{
found = true;
break;
}
}
if (!found)
{
result = false;
break;
}
}
delete pTmpUdef;
}
else
{
result = false;
}
return result;
}
开发者ID:jonasfoe,项目名称:COPASI,代码行数:55,代码来源:UnitConversionFactory.cpp
注:本文中的UnitDefinition类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论