本文整理汇总了C++中Submodel::instantiate方法的典型用法代码示例。如果您正苦于以下问题:C++ Submodel::instantiate方法的具体用法?C++ Submodel::instantiate怎么用?C++ Submodel::instantiate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Submodel
的用法示例。
在下文中一共展示了Submodel::instantiate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getSBMLDocument
int
Submodel::instantiate()
{
SBMLDocument* doc = getSBMLDocument();
SBMLDocument* rootdoc = doc;
if (doc==NULL)
{
return LIBSBML_OPERATION_FAILED;
}
CompSBMLDocumentPlugin* docplugin =
static_cast<CompSBMLDocumentPlugin*>(doc->getPlugin(getPrefix()));
if (docplugin==NULL)
{
return LIBSBML_OPERATION_FAILED;
}
SBase* parent = getParentSBMLObject();
string parentmodelname = "";
string parentURI = "";
set<string> uniqueModels;
while (parent != NULL && parent->getTypeCode() != SBML_DOCUMENT) {
if (parent->getTypeCode() == SBML_COMP_SUBMODEL) {
const Submodel* parentsub = static_cast<const Submodel*>(parent);
uniqueModels.insert(parentsub->mInstantiationOriginalURI + "::" + parentsub->getModelRef());
if (parentURI=="") {
parentURI=parentsub->mInstantiationOriginalURI;
}
}
if (parent->getTypeCode() == SBML_MODEL ||
parent->getTypeCode() == SBML_COMP_MODELDEFINITION)
{
if (parentmodelname == "") {
parentmodelname = parent->getId();
}
}
rootdoc = parent->getSBMLDocument();
parent = parent->getParentSBMLObject();
}
if (mInstantiatedModel != NULL)
{
delete mInstantiatedModel;
mInstantiatedModel = NULL;
mInstantiationOriginalURI.clear();
}
if (!hasRequiredAttributes()) {
string error = "Instantiation error in Submodel::instantiate: ";
if (!isSetId()) {
error += "A submodel in model '" + getParentModel(this)->getId() + "' does not have an 'id' attribute.";
}
else if (!isSetModelRef()) {
error += "The submodel '" + getId() + "' does not have a 'modelRef' attribute.";
}
rootdoc->getErrorLog()->logPackageError("comp", CompSubmodelAllowedAttributes, getPackageVersion(), getLevel(), getVersion(), error, getLine(), getColumn());
return LIBSBML_INVALID_OBJECT;
}
SBase* origmodel = docplugin->getModel(getModelRef());
if (origmodel==NULL) {
string error = "In Submodel::instantiate, unable to instantiate submodel '" + getId() + "' because the referenced model ('" + getModelRef() +"') does not exist.";
rootdoc->getErrorLog()->logPackageError("comp", CompSubmodelMustReferenceModel, getPackageVersion(), getLevel(), getVersion(), error, getLine(), getColumn());
return LIBSBML_INVALID_OBJECT;
}
ExternalModelDefinition* extmod;
SBMLDocument* origdoc = NULL;
string newmodel = parentURI + "::" + getModelRef();
set<pair<string, string> > parents;
switch(origmodel->getTypeCode())
{
case SBML_MODEL:
case SBML_COMP_MODELDEFINITION:
origdoc = origmodel->getSBMLDocument();
mInstantiatedModel = static_cast<Model*>(origmodel)->clone();
if (uniqueModels.insert(newmodel).second == false) {
//Can't instantiate this model, because we are already a child of it.
string error = "Error in Submodel::instantiate: cannot instantiate submodel '" + getId() + "' in model '" + parentmodelname + "' because it references the model '" + getModelRef() + "', which is already an ancestor of the submodel.";
rootdoc->getErrorLog()->logPackageError("comp", CompSubmodelCannotReferenceSelf, getPackageVersion(), getLevel(), getVersion(), error, getLine(), getColumn());
return LIBSBML_OPERATION_FAILED;
}
mInstantiationOriginalURI = parentURI;
break;
case SBML_COMP_EXTERNALMODELDEFINITION:
extmod = static_cast<ExternalModelDefinition*>(origmodel);
if (extmod==NULL)
{
//No error message: it should be impossible, if origmodel has the type code 'external model definition', for it to not be castable to an external model definition.
mInstantiatedModel = NULL;
mInstantiationOriginalURI = "";
return LIBSBML_OPERATION_FAILED;
}
mInstantiatedModel = extmod->getReferencedModel(rootdoc, parents);
if (mInstantiatedModel == NULL)
{
string error = "In Submodel::instantiate, unable to instantiate submodel '" + getId() + "' because the external model definition it referenced (model '" + getModelRef() +"') could not be resolved.";
rootdoc->getErrorLog()->logPackageError("comp", CompSubmodelMustReferenceModel, getPackageVersion(), getLevel(), getVersion(), error, getLine(), getColumn());
mInstantiationOriginalURI = "";
//.........这里部分代码省略.........