Fine-tuning code generated for arguments

You can use the Code pattern field to fine-tune the code that is generated for the arguments of a specific operation or event. If you want to modify the code generated when a given class, type, or event is used as an operation or event argument anywhere in your model, you can set the value of the relevant In, Out, or InOut property at the class, type, or event level.

You can fine-tune the code that is generated for operation or event arguments at two different levels:

  • at the operation level, by specifying the code that should be generated for an argument of a specific operation or event
  • at the project level, by specifying the code that should be generated any time a specific class (or type or event) is used as an argument of an operation or event

Code generated for an argument of a specific operation or event

To specify the code that is generated for an argument of a specific operation or event, modify the content of the Code pattern field in the Argument Dialog window. This content can consist of actual C/C++ code together with the $type keyword, which will generate the type of the model element that is being used for the argument, for example, you can enter const $type&

When you modify the content of the Code pattern field and then press OK, you can see the change immediately in the operation signature that is displayed on the General and Arguments tabs of the Features dialog for operations and events.

The Code pattern field corresponds to the In, Out, or InOut property (depending on the argument direction). After you modify the contents of the field and press OK, you can see the change reflected in the value of the relevant property at the argument level.

For example:

  • If you modified the code pattern for an In argument that is a class, you will see the new value under [lang]_CG::Class::In.
  • If you modified the code pattern for an Out argument that is a Type, you will see the new value under [lang]_CG::Type::Out.
  • If you modified the code pattern for an InOut argument that is an Event, you will see the new value under [lang]_CG::Event::InOut.

The relationship with the property is two-way. In theory, you can also modify the value of the relevant property at the argument level, and you will see the new value reflected in the Code pattern field. However, since this is only for the context of a single operation, there is no advantage of using the property rather than modifying the Code pattern field directly.

Note: The In, Out, and InOut properties are relevant only for operation arguments. Argument direction is not relevant for event arguments, so for event arguments you will see the new value reflected in the TriggerArgument property.

Code generated when a given class, type, or event is used as an argument anywhere in the model

If you want to modify the code that is generated when a given class, type, or event is used as an operation or event argument anywhere in your model, you can set the value of the relevant In, Out, InOut, or TriggerArgument property for the relevant class, type, or event.

For example:

  • If you modify the value of the property [lang]_CG::Class::In for a class called Printer, this will affect the code that is generated anywhere that an argument of type Printer is used as an In argument for an operation in your model.
  • If you modify the value of the property [lang]_CG::Type::TriggerArgument for a Type called Color, this will affect the code that is generated anywhere that an argument of type Color is used as the argument of an event in your model.
Note: If you set the value of one of the argument properties (In, Out, InOut, TriggerArgument) at the level of a class, type, or event, you can still override the code generation pattern in the context of an individual operation or event by entering a different code pattern in the Code pattern field for the argument, or by overriding the value of the property at the argument level.