Component Class

Class Brief …

Public Methods

Detailed

Class detailed documentation …

Member Methods Documentation

class Component : public libcellml::ComponentEntity, public libcellml::ImportedEntity, public std::enable_shared_from_this<Component>

The Component class.

The Component class is for representing a CellML Component.

Public Functions

~Component()

Destructor.

Component(const Component &rhs)

Copy constructor.

Component(Component &&rhs)

Move constructor.

Component &operator=(Component rhs)

Assignment operator.

void setSourceComponent(const ImportSourcePtr &importSource, const std::string &name)

Set the source component for this component.

Make this component an imported component by defining an import model from which to extract the named component from.

Parameters
  • importSource: The import source from which the named component originates.

  • name: The name of the component in the imported model to use.

void appendMath(const std::string &math)

Appends the argument to the math string for this component.

Appends math to the existing math string for this component.

Parameters
  • math: The std::string to append for this component.

std::string math() const

Get the math string for this component.

Returns a math string if one has been appended for this component. Returns an empty string if math has not been appended (or has been removed).

Return

std::string math for this component.

void setMath(const std::string &math)

Set the math string for this component.

Sets the math string for this component. If math is an empty string, math will be removed from the component.

Parameters
  • math: The std::string to append for this component.

void removeMath()

Clear the math from this component.

Clears the math string from this component.

void addVariable(const VariablePtr &variable)

Add a variable by reference as part of this component.

Add a variable by reference as part of the given component.

See

removeVariable

Parameters
  • variable: The variable to add.

bool removeVariable(size_t index)

Remove the variable at the given index from this component.

Remove the variable at the given index from this component. If the index is not valid false is returned, the valid range for the index is [0, #variables). If the variable to be removed is in a connection (is equivalent to another variable), this component will not be serialised in the connection.

See

addVariable

Return

True if the variable was removed, false otherwise.

Parameters
  • index: The index of the variable to remove.

bool removeVariable(const std::string &name)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Remove the variable with the given name from this component.

Remove the variable with the given name from this component. If the named variable to be removed is in a connection (is equivalent to another variable), this component will not be serialised in the connection.

See

addVariable

Return

True if the variable was removed, false otherwise.

Parameters
  • name: The name of the variable to remove.

bool removeVariable(const VariablePtr &variable)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Remove the variable by the given variable pointer from this component.

Remove the variable with the given pointer from this component. If the variable to be removed is in a connection (is equivalent to another variable), this component will not be serialised in the connection.

See

addVariable

Return

True if the variable was removed, false otherwise.

Parameters
  • variable: The pointer to the variable to remove.

void removeAllVariables()

Remove all variables stored in this component.

Clears all variables that have been added to this component. If any of the variables to be removed are in connections (are equivalent to other variables), this component will not be serialised in the connection.

VariablePtr variable(size_t index) const

Get a variable at index.

Returns a reference to a variable at the index index for this component. If the index is not valid a nullptr is returned, the valid range for the index is [0, #variables).

Return

A reference to the variable at the given index on success, nullptr otherwise.

Parameters
  • index: The index of the variable to return.

VariablePtr variable(const std::string &name) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Get a variable with the given name name.

Returns a reference to a variable with the name name for this component. If the name is not found a nullptr is returned.

Return

A reference to the Variable with the given name on success, nullptr otherwise.

Parameters
  • name: The name of the variable to return.

VariablePtr takeVariable(size_t index)

Take a variable at index.

Remove the variable at the given index from this component and returns a reference to a variable at the index index for this component. If the index is not valid a nullptr is returned, the valid range for the index is [0, #variables).

Return

A reference to the variable at the given index on success, nullptr otherwise.

Parameters
  • index: The index of the variable to return.

VariablePtr takeVariable(const std::string &name)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Take a variable with the given name name.

Remove the variable with the given name from this component and returns a reference to a variable with the name name for this component. If the name is not found a nullptr is returned.

Return

A reference to the Variable with the given name on success, nullptr otherwise.

Parameters
  • name: The name of the variable to return.

size_t variableCount() const

Get the number of variables in the component.

Returns the number of variables the component directly contains.

Return

the number of variables.

bool hasVariable(const VariablePtr &variable) const

Test whether the argument variable is in this component.

Tests whether the argument variable exists in the set of this component’s variables. Returns true if the variable is in this component’s variables and false otherwise.

Return

true if the variable is in this component and false otherwise.

Parameters
  • variable: The variable to check for in this component.

bool hasVariable(const std::string &name) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Test whether the variable named name is in this component.

Tests whether a variable with the argument name exists in the set of this component’s variables. Returns true if the named variable is in this component’s variables and false otherwise.

Return

true if a variable named name is in this component and false otherwise.

Parameters
  • name: The name of the variable to check for in this component.

void addReset(const ResetPtr &reset)

Add a reset by reference as part of this component.

Add a reset by reference as part of the given component.

See

removeReset

Parameters
  • reset: The reset to add.

bool removeReset(size_t index)

Remove the reset at the given index from this component.

Remove the reset at the given index from this component. If the index is not valid false is returned, the valid range for the index is [0, #resets).

See

addReset

Return

True if the reset was removed, false otherwise.

Parameters
  • index: The index of the reset to remove.

bool removeReset(const ResetPtr &reset)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Remove the reset by the given reset pointer from this component.

Remove the reset with the given pointer from this component.

See

addReset

Return

True if the reset was removed, false otherwise.

Parameters
  • reset: The pointer to the reset to remove.

void removeAllResets()

Remove all resets stored in this component.

Clears all resets that have been added to this component.

ResetPtr reset(size_t index) const

Get a reset at index.

Returns a reference to a reset at the index index for this component. If the index is not valid a nullptr is returned, the valid range for the index is [0, #resets).

Return

A reference to the reset at the given index on success, nullptr otherwise.

Parameters
  • index: The index of the reset to return.

size_t resetCount() const

Get the number of resets in the component.

Returns the number of resets the component contains.

Return

the number of resets.

bool hasReset(const ResetPtr &reset) const

Test whether the argument reset is in this component.

Tests whether the argument reset exists in the set of this component’s resets. Returns true if the reset is in this component’s resets and false otherwise.

Return

true if the reset is in this component and false otherwise.

Parameters
  • reset: The reset to check for in this component.

ComponentPtr clone() const

Create a clone of this component.

Creates a full separate copy of this component without copying the parent. Thus the cloned (returned) version of this component will not have a parent set even if this component does. Any and all child components will also be cloned recreating the full component hierarchy that this component is the root of.

Return

a new ComponentPtr to the cloned component.

Public Static Functions

static ComponentPtr create()

Create a Component object.

Factory method to create a Component. Create a blank component with::

ComponentPtr component = libcellml::Component::create();

or a named component with name “Component” with::

ComponentPtr component = libcellml::Component::create(“Component”);

Return

A smart pointer to a Component object.

static ComponentPtr create(const std::string &name)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.