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.

A model may be written as a single file containing several packages, or split across several files. Both work; the import forms are the same in either case.

Imports#

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.

Models split across files#

If an imported package is not defined in the current file, the generator looks for it in a sibling file next to the one being generated and loads it. Imports in that file are followed in turn, so a chain of files is resolved recursively. Call the generator with the primary file; the others are pulled in automatically.

// Something.sysml — shared types
package Something {
    attribute def Something;
}
// other_a.sysml — a library that uses the shared types
package other_a {
    private import ScalarValues::*;
    private import Something::Something;

    abstract part def DevicePart {
        attribute power : Real default 0.0;
    }

    part def Sensor :> DevicePart {
        attribute reading : Real default 0;
    }
}
// test.sysml — the primary file; generate this one
private import other_a::*;
private import ScalarValues::*;

package App {
    part def Device {
        abstract ref part parts : DevicePart [*];
        ref part sensor subsets parts : Sensor;
    }
}

Each file produces its own header, so the generated C++ keeps the same structure as the model.

The lookup is by file name next to the primary file; there is no search path or library directory yet. Keep the files of one model in one directory.

The standard library#

Name-compatible stubs for ScalarValues and ISQ are bundled with the generator and loaded automatically, even without an explicit import. This makes declarations such as attribute l : Real :> ISQ::length; bind to a real feature instead of failing, and keeps SysML editors quiet.

These stubs are a small subset of the OMG standard library, not a copy of it. They are never emitted into the generated code, and scalar types keep their usual C++ mapping (Realdouble, Integerint, …). If your model needs a quantity kind that is missing, define it yourself or use a plain scalar type.

Unit names such as kg or km are not covered by the stubs. Use the qualified form ([SI::kilogram]) or add private import SI::*; if you want to write them unqualified — see Attributes.

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)
}