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 any contained other attributes are represented as structs.

Attributes with contained other attributes are represented as classes

Attribute usages can only occur within parts (here within Part ‘apart’).

Attributes can have default values

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

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 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 {}
};