Code generation In the example model, Motor is the owner class, and FunctorIncreaseSpeed_int executes the modeled operation increaseSpeed . This activity diagram increments the value of the class attribute speed by the value specified by the amount argument, then returns the incremental value. Note the following information: Љ An activity diagram should never contain code with the return keyword because the current implementation executes the code fragments of the diagram (that appear in actions, activity flows, and so on) in contexts of different operations. Returning from those contexts (operations) does not have the same effect as returning from the body of a regular operation.
Instead, you should set the return value to the rpyRetVal variable (shown in the previous figure), which is always generated for operations that return values. Љ There are two ways an operation can finish and return control to its caller: – Once the diagram reaches a “stable” state (there are no more activity flows to take), the operation is considered to have finished its job and it returns control to its caller. – The diagram reaches a termination connector at the top level. Љ The actual execution of the code does not occur within the scope of the object that owns the operation. Instead, the code is executed in another object whose sole purpose is to execute the diagram.
During the execution of the code in the diagram, the this pointer references a special-purpose object (the functor object ) that contains the code in the diagram (in states, on activity flows, and so on). To refer to the owner object, you can use the this_ variable, which always exists for this purpose. To make coding more natural, direct access to the attributes of the class that owns the operation (without the need for this_ ) is made possible by supplying references in the functor object. The functor class contains references that correspond to each owner class attribute and have the same name.
The constructor of the functor class contains arguments to initialize each attribute; initialization is done when the owner class creates an object of the functor class. You can control the code generation of the attribute references by setting the value of the CPP_CG::Operation::ActivityReferenceToAttributes property to Checked (the default value). Rational Rhapsody 653