next up previous contents index
Next: 9.1.3 Integer Up: 9.1 Simple Data Types Previous: 9.1.1 Boolean   Contents   Index

9.1.2 Integer Counter

An integer counter is a cell that stores an integer in it. The only operations on its value are ``increase'' by 1 and ``decrease'' by 1.

The model saved in Counter.des in the DataTypes/ subdirectory of SVM models such an integer counter.

Counter.des

The INIT macro can be redefined to give a different initial integer value to the cell.

In this model, recursive importation is extensively used. When the model receives the inc event after it is initialized, a submodel with the same structure is imported into the LARGER state (because its value becomes [INIT]+1, which is larger than [INIT]). The value in the submodel is redefined as [CURRENT]+1 in the submodel. Since transitions in this model are inner-first, if the get event is received at this time, a transition in the submodel instead of the importing model is triggered. The model returns the new value. When dec is received at this time, the model goes out of the submodel. The [CURRENT] value of the model at the higher level is 1 less than the [CURRENT] value of its submodel in the LARGER state. A get event received at this time is handled by the importing model itself.

If the value of the cell becomes less than [INIT] because of dec events, submodels are imported into its SMALLER state.

The cell has a theoretically infinite capacity, which only depends on the available memory of the system.


next up previous contents index
Next: 9.1.3 Integer Up: 9.1 Simple Data Types Previous: 9.1.1 Boolean   Contents   Index
Thomas Huining Feng 2004-04-28