Parts#
Role in SysML v2#
A part definition represents a modular unit of structure such as a system, system component, or external entity that may directly or indirectly interact with the system.
A part usage is a kind of item usage that is a usage of one or more part definitions.
Mapping to C++#
Parts are mapped to C++ classes which are derived from the Part base class. This base class is defined in the framework header which defines helper functionality required for the execution of the generated model.
Part usages can only be used within a part and are mapped to class attributes.
Example#
SysML v2 source code:
private import ScalarValues::*;
package Test {
part def PartDef1;
part def PartDef2 {
/* members */
part part1 : PartDef1;
part part2 : PartDef1 {
/* members */
}
}
}C++ source code:
namespace Test {
class PartDef1 : public Part {
public:
PartDef1() {}
virtual void process() override {}
// must be called by derived classes after constructing the parts
virtual void init(void) override {}
};
class PartDef2 : public Part {
public:
PartDef2() {}
std::unique_ptr<PartDef1> part1 = std::make_unique<PartDef1>();
virtual void process() override { part1->process(); }
// must be called by derived classes after constructing the parts
virtual void init(void) override {
assert(part1);
part1->init();
}
};
} // end of namespace Test