Sinelabore Homepage

Attributes#

Role in SysML v2#

An attribute definition defines a set of data values, such as numbers, quantitative values with units, qualitative values such as text strings, or data structures of such values.

An attribute usage is a usage of an attribute definition.

Mapping to C++#

Basic attribute definitions without nested attributes are represented as structs.

Attributes with nested attributes are represented as classes.

Attribute usages typically occur within parts (and can also be package-scoped — see Packages).

Attributes can have default values and a type. If no type is given the type is mapped to an int and set to 0 as default value.

Attributes (and items) may declare multiplicity, for example attribute test : Integer[0..5];. Indexed access in actions uses #(n) where supported.

When a part specializes another, attributes can be redefined with :>> or redefines (see Parts).

Example#

SysML v2 source code:


private import ScalarValues::*;

package Test {
	
	/*
	* Another comment
	*/
	attribute def Att4{
		attribute att5 : Integer default 10; 
		attribute att6 : Real default 7.0;
	}


	// comment
	part def apart{
		attribute att10 : String default "Hello"; 
		attribute b:Integer default 3;
		attribute att3 : Boolean;
		attribute samples : Integer[0..5];
		
    // attribute with user-defined type
    attribute f:Att4;
  }

}

C++ source code:


namespace Test {

class Att4 {
public:
  int att5;
  double att6;

  // Constructors
  Att4(int att5Val, double att6Val) : att5(att5Val), att6(att6Val) {}

  Att4() : att5(10), att6(7.0) {}
};

struct Att28 {};

class apart : public Part {

public:
  apart() {}

  // elements of this part

  std::string att10 = "Hello";
  int b = 3;
  bool att3 = false;
  Att4 f;
  int x = 0;

  virtual void process() override {}

  // must be called by derived classes after constructing the parts
  virtual void init(void) override {}
};