Skip to content

Primitives

Usage

Primitives should be used inside the model to refer to specific types with specific type qualifiers. Therefore we adapted the Uml Profile for Embedded Engineer to now also allow the usage of the following Stereotypes with Primitives.

These Stereotypes behave the same way as when used with an Attribute.

Info

Primitives can be placed anywhere inside the model and either used 'standalone', without any link to a model element (other than as a type).

OR

You can link a Primitive element to a Class or Interface,... with an Aggregation to generate code for them.

Defining new types

To define a new type that can be used inside the model the following model elements need to be used.

  1. a Class or Interface,... to contain the definition
  2. a Primitive element with the typedef Stereotype
  3. the Alias of the Primitive element set to the 'base' type.

    When using MagicDraw use the Alias Stereotype and the Typename Tagged Value

  4. a Aggregation link from the Class/Interface whole to the Primitive part

Example

Point 1. 2. and 4.

Primitves typedef

Point 3.

Primitves typedef

#ifndef H_TYPES
#define H_TYPES
typedef int typeTest;
#endif

External types

When using external libraries or defining your own types you usually refer to them inside your model. For example when using them as a type of an Attribute or as the type of a parameter in an Operation.

Often users tend to refer to these types with a string value in the Type field of the Attribute/Parameter.

By using a Primitive element inside your model, you can refer to it via an actual model reference.

This has the following advantages:

  • You exaclty see which types are used inside your model
  • Typing errors can be traced back to only one source
  • Refactoring/renaming can be done by changing a single element
  • Better tracebility
  • High degree of freedom for types

Tip

Using primitives gives you the freedom to use whatever type you'd need. When defining types with different pointers and modifiers, there are multiple permutations possible that would be hard to define with stereotypes and/or tagged values. For example a const int pointer or pointer to constant integer,... and many more. With primitives you can just use what you prefer and the generated code will then use the defined type in the way you created the primitive.

  • int const *
  • const int *
  • ...

Primitves

Info

Since the code generation will use the "Normalized Name" for an element/type it is not always possible to write certain type and or keyword combinations.

To do this you can use a Primitve element, since the code generation will output the name of the element as it is (not using the "Normalized Name").

Normalized element name all illegal characters are replaced by _.

Legal characters:

  • first character: _ or [a-z] or [A-Z]
  • following characters: _ or [a-z] or [A-Z] or [0-9]