Resolve the imported items in a modelΒΆ

The import functionality for Units and Component items is key to enabling the reuse and sharing of models. The import statements are basically a recipe for how these imported items can be combined to make the present model. While models which contain import dependencies are perfectly valid, they cannot be used to generate runnable code. The process of resolving the imports (telling libCellML where to look for these ingredients) and flattening the model (creating instances of the ingredients and removing the dependency) is necessary before code generation can happen.

The Importer class supports all functionality to do with imports, and contains its own logger which can be used to report anything that might have gone wrong.

Resolve imports in a model

    // Resolve the import dependencies (if any) and flatten the model.

    if(model->hasUnresolvedImports()) {
        auto importer = libcellml::Importer::create();

        // Submit the model to the importer and the absolute location 
        // against which the import reference paths will be resolved.
        importer->resolveImports(model, "");

        printIssues(importer);

        // Print a list of dependencies for the current unflattened model.
        printImportDependencies(model);

        // Retrieve a "flattened" (ie: import-free) model from the importer,
        // and use it to over-write the current model.
        model = importer->flattenModel(model);

        printImportDependencies(model);
    }

Full context: example_simulationToolDev.cpp