Skip to content

Commit

Permalink
Merge pull request #248 from hsorby/imports_revisited
Browse files Browse the repository at this point in the history
Imports revisited. Closes #238.
  • Loading branch information
nickerso committed Aug 15, 2018
2 parents 7a88fc4 + 1744188 commit 41d06d9
Show file tree
Hide file tree
Showing 65 changed files with 1,359 additions and 225 deletions.
2 changes: 1 addition & 1 deletion docs/doxy.config.in
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ BRIEF_MEMBER_DESC = YES
# brief descriptions will be completely suppressed.
# The default value is: YES.

REPEAT_BRIEF = YES
REPEAT_BRIEF = NO

# This tag implements a quasi-intelligent brief description abbreviator that is
# used to form the text in various listings. Each string in this list, if found
Expand Down
4 changes: 2 additions & 2 deletions src/api/libcellml/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class LIBCELLML_EXPORT Error
public:
Error(); /**< Constructor */
virtual ~Error(); /**< Destructor */
Error(const Error& rhs); /**< Copy constructor */
Error(const Error &rhs); /**< Copy constructor */
Error(Error &&rhs); /**< Move constructor */
Error& operator=(Error rhs); /**< Assignment operator */

Expand Down Expand Up @@ -129,7 +129,7 @@ class LIBCELLML_EXPORT Error
*
* @param description The @c std::string error description to set.
*/
void setDescription(const std::string& description);
void setDescription(const std::string &description);

/**
* @brief Get the description for this error.
Expand Down
51 changes: 41 additions & 10 deletions src/api/libcellml/importsource.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,57 @@ class LIBCELLML_EXPORT ImportSource: public Entity
~ImportSource() override; /**< Destructor */
ImportSource(const ImportSource &rhs); /**< Copy constructor */
ImportSource(ImportSource &&rhs); /**< Move constructor */
ImportSource& operator=(ImportSource m); /**< Assignment operator */
ImportSource& operator=(ImportSource rhs); /**< Assignment operator */

/**
* @brief Set the imported model source.
* @brief Get the source @c Model's URL.
*
* Set the imported model source that this import source refers to.
* Get the source @c Model's URL set in this instance. If no source @c Model
* URL is set then return an empty string.
*
* @param source The source of the model as a @c std::string.
* @return The URL of the source @c Model if set otherwise the emtpy string.
*/
void setSource(const std::string &source);
std::string getUrl() const;

/**
* @brief Get the imported model source.
* @brief Set the source @c Model's URL.
*
* Get the imported model source set in this instance. If no imported source
* is set then return an empty string.
* Set the source @c Model's URL that this @c ImportSource refers to.
*
* @return The imported model source as a @c std::string, if set, otherwise the empty string.
* @param source The source @c Model's URL.
*/
std::string getSource() const;
void setUrl(const std::string &url);

/**
* @brief Get the @c Model that resolves the import.
*
* Get the @c Model which has been assigned to resolve this @c ImportSource. If no @c Model
* has been assigned then return the @c nullptr.
*
* @return The @c Model used to resolve this @c ImportSource.
*/
libcellml::ModelPtr getModel() const;

/**
* @brief Provide the @c Model used to resolve this import.
*
* Uses the provided @c Model to resolve this @c ImportSource, which should correspond
* to the @c ImportSource identified by this import.
*
* @param model The @c Model to use in resolving this @c ImportSource.
*/
void setModel(libcellml::ModelPtr model);

/**
* @brief Test if this @c ImportSource is resolved.
*
* Method to test if this @c ImportSource has been resolved, i.e., the source @c Model has
* been assigned. Returns @c true if the @c ImportSource is resolved otherwise returns
* @c false.
*
* @return @c true if the @c ImportSource has been resolved, @c false otherwise.
*/
bool hasModel() const;

private:
void swap(ImportSource &rhs); /**< Swap method required for C++ 11 move semantics. */
Expand Down
27 changes: 27 additions & 0 deletions src/api/libcellml/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ limitations under the License.
#include "libcellml/componententity.h"
#include "libcellml/exportdefinitions.h"

#ifndef SWIG
template class LIBCELLML_EXPORT std::weak_ptr<libcellml::Model>;
#endif

//! Everything in libCellML is in this namespace.
namespace libcellml {

Expand All @@ -30,6 +34,9 @@ namespace libcellml {
* The Model class is for representing a CellML Model.
*/
class LIBCELLML_EXPORT Model: public ComponentEntity
#ifndef SWIG
, public std::enable_shared_from_this<Model>
#endif
{
public:
Model(); /**< Constructor */
Expand Down Expand Up @@ -224,6 +231,26 @@ class LIBCELLML_EXPORT Model: public ComponentEntity
*/
size_t unitsCount() const;

/**
* @brief Resolve all imports in this model.
*
* Resolve all @c Component and @c Units imports by loading the models
* from local disk through relative URLs. The @p baseFile is used to determine
* the full path to the source model relative to this one.
*
* @param baseFile The @c std::string location on local disk of the source @c Model.
*/
void resolveImports(const std::string &baseFile);

/**
* @brief Test if this model has unresolved imports.
*
* Test if this model has unresolved imports.
*
* @return True if the @c Model has unresolved imports and false otherwise.
*/
bool hasUnresolvedImports();

private:
void doAddComponent(const ComponentPtr &c) override;
void swap(Model &rhs); /**< Swap method required for C++ 11 move semantics. */
Expand Down
12 changes: 8 additions & 4 deletions src/api/libcellml/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,24 @@ class Parser; /**< Forward declaration of Parser class. */
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 Component; /**< Forward declaration of Component class. */
typedef std::shared_ptr<Component> ComponentPtr; /**< Type definition for shared component pointer. */
class ComponentEntity; /**< Forward declaration of ComponentEntity class. */
typedef std::shared_ptr<ComponentEntity> ComponentEntityPtr; /**< Type definition for shared component entity pointer. */
class Error; /**< Forward declaration of Error class. */
typedef std::shared_ptr<Error> ErrorPtr; /**< Type definition for shared error pointer. */
class ImportedEntity; /**< Forward declaration of ImportedEntity class. */
typedef std::shared_ptr<ImportedEntity> ImportedEntityPtr; /**< Type definition for shared imported entity pointer. */
class ImportSource; /**< Forward declaration of ImportSource class. */
typedef std::shared_ptr<ImportSource> ImportSourcePtr; /**< Type definition for shared import source pointer. */
class Model; /**< Forward declaration of Model class. */
typedef std::shared_ptr<Model> ModelPtr; /**< Type definition for shared model pointer. */
class Reset; /**< Forward declaration of Reset class. */
typedef std::shared_ptr<Reset> ResetPtr; /**< Type definition for shared reset pointer. */
class Units; /**< Forward declaration of Units class. */
typedef std::shared_ptr<Units> UnitsPtr; /**< Type definition for shared units pointer. */
class Variable; /**< Forward declaration of Variable class. */
typedef std::shared_ptr<Variable> VariablePtr; /**< Type definition for shared variable pointer. */
class When; /**< Forward declaration of When class. */
typedef std::shared_ptr<When> WhenPtr; /**< Type definition for shared when pointer. */
class Reset; /**< Forward declaration of Reset class. */
typedef std::shared_ptr<Reset> ResetPtr; /**< Type definition for shared reset pointer. */
}
28 changes: 14 additions & 14 deletions src/bindings/interface/component.i
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,6 @@
%import "types.i"
%import "componententity.i"

#if defined(SWIGPYTHON)
// Treat negative size_t as invalid index (instead of unknown method)
%extend libcellml::Component {
VariablePtr getVariable(long index) const {
if(index < 0) return nullptr;
return $self->getVariable(size_t(index));
}
bool removeVariable(long index) {
if(index < 0) return false;
return $self->removeVariable(size_t(index));
}
}
#endif

%feature("docstring") libcellml::Component
"Represents a CellML component.";

Expand Down Expand Up @@ -94,6 +80,20 @@ range for the index is [0, #resets).";
resets. Returns True if the :param: reset is in this component's
resets and False otherwise.";

#if defined(SWIGPYTHON)
// Treat negative size_t as invalid index (instead of unknown method)
%extend libcellml::Component {
VariablePtr getVariable(long index) const {
if(index < 0) return nullptr;
return $self->getVariable(size_t(index));
}
bool removeVariable(long index) {
if(index < 0) return false;
return $self->removeVariable(size_t(index));
}
}
#endif

%{
#include "libcellml/component.h"
%}
Expand Down
71 changes: 45 additions & 26 deletions src/bindings/interface/componententity.i
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,6 @@
%import "types.i"
%import "importedentity.i"

#if defined(SWIGPYTHON)
// Allow any type of input to be converted to bool
%typemap(typecheck,precedence=SWIG_TYPECHECK_BOOL) bool { $1 = 1; }
%typemap(in) bool { $1 = PyObject_IsTrue($input) == 1; }

// Treat negative size_t as invalid index (instead of unknown method)
%extend libcellml::ComponentEntity {
ComponentPtr getComponent(long index) const {
if(index < 0) return nullptr;
return $self->getComponent(size_t(index));
}
bool removeComponent(long index) {
if(index < 0) return false;
return $self->removeComponent(size_t(index));
}
ComponentPtr takeComponent(long index) {
if(index < 0) return nullptr;
return $self->takeComponent(size_t(index));
}
bool replaceComponent(long index, const ComponentPtr &c) {
if(index < 0) return false;
return $self->replaceComponent(size_t(index), c);
}
}
#endif

%feature("docstring") libcellml::ComponentEntity
"Abstract class that provides component managing functionality.";

Expand Down Expand Up @@ -85,6 +59,51 @@ Returns `True` on success.";
%feature("docstring") libcellml::ComponentEntity::componentCount
"Returns the number of components the component contains. ";

%feature("docstring") libcellml::ComponentEntity::getEncapsulationId
"Returns the encapsulation id for this entity.
The encapsulation Id is placed on the XML element for this entity. For the
:class:`Model` class this is the ``encapsulation`` element that is the root
element for the model's structure. For the :class:`Component` class this is
the ``component_ref`` element that references the component it represents in
the structure."

%feature("docstring") libcellml::ComponentEntity::setEncapsulationId
"Sets the encapsulation id for this entity.
The encapsulation Id is placed on the XML element for this entity. For the
:class:`Model` class this is the ``encapsulation`` element that is the root
element for the model's structure. For the :class:`Component` class this is
the ``component_ref`` element that references the component it represents in
the structure."


#if defined(SWIGPYTHON)
// Allow any type of input to be converted to bool
%typemap(typecheck,precedence=SWIG_TYPECHECK_BOOL) bool { $1 = 1; }
%typemap(in) bool { $1 = PyObject_IsTrue($input) == 1; }

// Treat negative size_t as invalid index (instead of unknown method)
%extend libcellml::ComponentEntity {
ComponentPtr getComponent(long index) const {
if(index < 0) return nullptr;
return $self->getComponent(size_t(index));
}
bool removeComponent(long index) {
if(index < 0) return false;
return $self->removeComponent(size_t(index));
}
ComponentPtr takeComponent(long index) {
if(index < 0) return nullptr;
return $self->takeComponent(size_t(index));
}
bool replaceComponent(long index, const ComponentPtr &c) {
if(index < 0) return false;
return $self->replaceComponent(size_t(index), c);
}
}
#endif

%{
#include "libcellml/componententity.h"
%}
Expand Down
44 changes: 28 additions & 16 deletions src/bindings/interface/error.i
Original file line number Diff line number Diff line change
Expand Up @@ -16,54 +16,66 @@
"Sets a string description for why this error was raised.";

%feature("docstring") libcellml::Error::getKind
"Get the `kind` of this error. If no kind has been set for this error, will
"Get the ``kind`` of this error. If no kind has been set for this error, will
return Kind::UNDEFINED.";

%feature("docstring") libcellml::Error::isKind
"Tests if this error matches the given `kind`.";
"Tests if this error matches the given ``kind``.";

%feature("docstring") libcellml::Error::setKind
"Sets the `kind` of this error.";
"Sets the ``kind`` of this error.";

%feature("docstring") libcellml::Error::getRule
"Get the `SpecificationRule` of this error.";
"Get the :class:`SpecificationRule` of this error.";

%feature("docstring") libcellml::Error::setRule
"Sets the `SpecificationRule` for this error.";
"Sets the :class:`SpecificationRule` for this error.";

%feature("docstring") libcellml::Error::getSpecificationHeading
"Returns the CellML 2.0 Specification heading associated with the
SpecificationRule for this error (empty string if not set).";
:class:`SpecificationRule` for this error (empty string if not set).";

%feature("docstring") libcellml::Error::getComponent
"Returns the Component that this error is relevant to (or `None`).";
"Returns the :class:`Component` that this error is relevant to (or ``None``).";

%feature("docstring") libcellml::Error::setComponent
"Sets the Component that this error is relevant to (`None` to unset).";
"Sets the :class:`Component` that this error is relevant to (``None`` to unset).";

%feature("docstring") libcellml::Error::getImportSource
"Returns the ImportSource that this error is relevant to (or `None`).";
"Returns the :class:`ImportSource` that this error is relevant to (or ``None``).";

%feature("docstring") libcellml::Error::setImportSource
"Sets the ImportSource that this error is relevant to (`None` to unset).";
"Sets the :class:`ImportSource` that this error is relevant to (``None`` to unset).";

%feature("docstring") libcellml::Error::getModel
"Returns the Model that this error is relevant to (or `None`).";
"Returns the :class:`Model` that this error is relevant to (or ``None``).";

%feature("docstring") libcellml::Error::setModel
"Sets the Model that this error is relevant to (`None` to unset).";
"Sets the :class:`Model` that this error is relevant to (``None`` to unset).";

%feature("docstring") libcellml::Error::getUnits
"Get the Units that this error is relevant to (or `None`).";
"Get the :class:`Units` that this error is relevant to (or ``None``).";

%feature("docstring") libcellml::Error::setUnits
"Sets the Units that this error is relevant to (`None` to unset).";
"Sets the :class`Units` that this error is relevant to (``None`` to unset).";

%feature("docstring") libcellml::Error::getVariable
"Get the variable that this error is relevant to (or `None`).";
"Get the :class:`Variable` that this error is relevant to (or ``None``).";

%feature("docstring") libcellml::Error::setVariable
"Sets the Variable that this error is relevant to (`None` to unset).";
"Sets the :class:`Variable` that this error is relevant to (``None`` to unset).";

%feature("docstring") libcellml::Error::getReset
"Get the :class:`Reset` that this error is relevant to (or ``None``).";

%feature("docstring") libcellml::Error::setReset
"Sets the :class:`Reset` that this error is relevant to (``None`` to unset).";

%feature("docstring") libcellml::Error::getWhen
"Get the :class:`When` that this error is relevant to (or ``None``).";

%feature("docstring") libcellml::Error::setWhen
"Sets the :class:`When` that this error is relevant to (``None`` to unset).";

%{
#include "libcellml/error.h"
Expand Down

0 comments on commit 41d06d9

Please sign in to comment.