Sinelabore Homepage

Packages#

Role in SysML v2#

A package is a kind of namespace that is used solely as a container for other elements to organize the model. In addition, a package has the capability to filter imported elements based on certain conditions.

Mapping to C++#

Packages are mapped to C++ namespaces.

The complete model must reside in a single file. Within that file you may define several packages and use imports so types resolve across packages. Splitting a model across multiple files is not supported yet. Standard library imports such as ScalarValues::* mainly satisfy SysML editors; only a basic scalar type mapping is generated.

Imports (same file)#

Supported in one translation unit:

Form Example Effect
Membership import import Types::Sensor; Brings one name into scope
Wildcard import import Types::*; Brings all public members of the package into scope
Visibility private import … / public import … Controls whether the import is re-exported (default is public)
Qualified name Types::Actuator Always resolves without an import

File-level imports (before a package) attach to the following package. Package-body imports apply inside that package.

Example#

SysML v2 source code:

package Types {
    private import ScalarValues::*;
    part def Sensor {
        attribute reading : Real = 1.0;
    }
    part def Actuator {
        attribute power : Real = 2.0;
    }
}

package Test {
    private import Types::*;
    private import ScalarValues::*;

    // Sensor known via Types::*
    part def Probe :> Sensor {
        attribute label : Real = 10.0;
    }

    // Or use a fully qualified path without importing Actuator
    // part def ElActuator :> Types::Actuator { … }
}

C++ source code:

namespace Types {
  // Sensor, Actuator classes …
}

namespace Test {
  // Probe specializes Types::Sensor (qualified type in generated code as needed)
}