Permalink
Browse files

Model: simplified the resolution of component imports.

  • Loading branch information...
agarny committed Jul 20, 2018
1 parent 5a59f55 commit c030275ee66d0affcab5b5742f7919ae25f189a4
Showing with 13 additions and 21 deletions.
  1. +2 −1 src/api/libcellml/model.h
  2. +2 −0 src/api/libcellml/types.h
  3. +9 −20 src/model.cpp
@@ -29,7 +29,8 @@ namespace libcellml {
*
* The Model class is for representing a CellML Model.
*/
class LIBCELLML_EXPORT Model: public ComponentEntity
class LIBCELLML_EXPORT Model: public ComponentEntity,
public std::enable_shared_from_this<Model>
{
public:
Model(); /**< Constructor */
@@ -27,6 +27,8 @@ class Validator; /**< Forward declaration of Validator class. */
// CellML entities.
class Model; /**< Forward declaration of Model class. */
typedef std::shared_ptr<Model> ModelPtr; /**< Type definition for shared model pointer. */
class ComponentEntity; /**< Forward declaration of ComponentEntity class. */
typedef std::shared_ptr<ComponentEntity> ComponentEntityPtr; /**< Type definition for shared component entity pointer. */
class Component; /**< Forward declaration of Component class. */
typedef std::shared_ptr<Component> ComponentPtr; /**< Type definition for shared component pointer. */
class Error; /**< Forward declaration of Error class. */
View
@@ -265,23 +265,16 @@ void resolveImport(ImportedEntityPtr importedEntity,
}
}
void recurseResolveComponentImports(ComponentPtr component, const std::string &baseFile);
void resolveComponentImports(ComponentPtr parentComponent, const std::string &baseFile)
void resolveComponentImports(ComponentEntityPtr parentComponentEntity, const std::string &baseFile)
{
for (size_t n = 0; n < parentComponent->componentCount(); ++n)
for (size_t n = 0; n < parentComponentEntity->componentCount(); ++n)
{
libcellml::ComponentPtr component = parentComponent->getComponent(n);
recurseResolveComponentImports(component, baseFile);
}
}
void recurseResolveComponentImports(ComponentPtr component, const std::string &baseFile)
{
if (component->isImport()) {
resolveImport(component, baseFile);
} else {
resolveComponentImports(component, baseFile);
libcellml::ComponentPtr component = parentComponentEntity->getComponent(n);
if (component->isImport()) {
resolveImport(component, baseFile);
} else {
resolveComponentImports(component, baseFile);
}
}
}
@@ -292,11 +285,7 @@ void Model::resolveImports(const std::string &baseFile)
libcellml::UnitsPtr units = getUnits(n);
resolveImport(units, baseFile);
}
for (size_t n = 0; n < componentCount(); ++n)
{
libcellml::ComponentPtr component = getComponent(n);
recurseResolveComponentImports(component, baseFile);
}
resolveComponentImports(shared_from_this(), baseFile);
}
bool isUnresolvedImport(ImportedEntityPtr importedEntity)

0 comments on commit c030275

Please sign in to comment.