QM  5.1.4
Model-Based Design Tool
Working with Attributes

An attribute defines a variable that can be attached to the instances of a class (see Class Attributes) or to a package (see Free Attributes).

Class Attributes

Attributes attached to a class are present in each instance of the class, except for a static class attribute, which exists in one copy only, regardless of the number of class instances. In C/C++, non-static class attributes correspond to data members of a struct/class.

Adding a Class Attribute

A class attribute can only be added to a Class. To add a class attribute, in the Model Explorer right-click on the Class to which you want to add a new class attribute and select Add Attribute from the popup menu.

Adding a Class Attribute

Class Attribute Property Sheet

A Class Attribute item can be configured by the Class-Attribute-Specific Property Sheet.

Class Attribute Property Sheet

The class-attribute-item property sheet allows you to set the following properties:

  • attribute name (NOTE: name can be followed by the array dimension for arrays of attributes)
  • attribute type drop-down box (NOTE: accepts also user-supplied types)
  • attribute visibility drop-down box with options: public, protected, private
  • static checkbox (for designating a class attribute as a static class attribute)
  • attribute documentation for documenting the attribute (see also generate comments)

Free Attributes

Attributes attached to a package (as opposed to a class) are called free attributes. In C/C++, such free attributes correspond to variables defined directly at file scope (either static variables or a global variables).

Adding a Free Attribute

A free attribute can only be added to a Package. To add a free attribute, in the Model Explorer right-click on the Package to which you want to add a new free attribute and select Add Attribute from the popup menu.

Adding a Class Attribute

Free Attribute Property Sheet

A Free Attribute item can be configured by the Free-Attribute-Specific Property Sheet.

Free Attribute Property Sheets (simple initializer--left, and array initializer--right)

The free-attribute-item property sheet allows you to set the following properties:

  • attribute name (NOTE: name can be followed by the array dimension for arrays of attributes)
  • attribute type drop-down box (NOTE: accepts also user-supplied types)
  • attribute documentation for documenting the attribute (see also generate comments)
  • attribute initializer (for optional initialization of the free attribute)

Free Attribute Initialization

As mentioned in the previous section, the Free Attribute Property Sheet, provides the attribute initializer field for an optional initialization of the free attribute at the point of definition. If specified, the attribute initializer is copied literally immediately after the attribute definition (see also $define${}).

For example, the free attribute initializer shown on the left-hand side of the Free Attribute Property Sheets above generates the following code (directive $define${AOs::AO_Table}):

/* opaque pointer to the Table AO */
/*${AOs::AO_Table} .........................................................*/
QActive * const AO_Table = &l_table.super;
/*$enddef${AOs::AO_Table} ##################################################*/

The free attribute initializer shown on the right-hand side of the Free Attribute Property Sheets above generates the following code (directive $define${AOs::AO_Philo[N_PHILO]}):

/* opaque pointers to the Philo AOs */
/*${AOs::AO_Philo[N_PHILO]} ................................................*/
QActive * const AO_Philo[N_PHILO] = {
&l_philo[0].super,
&l_philo[1].super,
&l_philo[2].super,
&l_philo[3].super,
&l_philo[4].super
};
/*$enddef${AOs::AO_Philo[N_PHILO]} #########################################*/