|
Re: multiplicity at objects? [message #1795520 is a reply to message #1795480] |
Mon, 24 September 2018 16:12 |
Ernesto Posse Messages: 438 Registered: March 2011 |
Senior Member |
|
|
When you set the multiplicity of an element such as a port or part, the generated code will be an array whose name is the name of the element, so you can use normal indices to access individual elements. For example, say you have a protocol P with some messages m1 and m2 and you have a capsule A with a port p (of type P) with multiplicity 2. Then, in actions of A's state machine, or A's operations, you can write, e.g.
p[0].m1().send();
p[1].m2().send();
The same notation can be used for parts.
Now, in a state machine, a transition trigger cannot specify directly a specific index for a port, but there is an API method from the UMLRTMessage class that allows you to determine which has the index of the port that received the message. Every transition action (and state action) has an implicit parameter called "msg" which contains a pointer to the message that was received and triggered the transition (more precisely its type is const UMLRTMessage * msg). From this parameter we can obtain the relevant index in action code by calling on "msg" the methods "sapIndex" or "sapIndex0". They return the same thing, the index of the port where the message was received. The difference is that "sapIndex" counts from 1 and "sapIndex0" counts from 0. So in the action of a transition whose trigger is a port with multiplicity > 1, you can write, e.g.
int i = msg->sapIndex0();
|
|
|
|
Powered by
FUDForum. Page generated in 0.03699 seconds