Real-Time C++ Target RTS group properties for UML classes, interfaces, and enumerations

The following C++ properties in the Target RTS group are associated with UML classes, interfaces, and enumerations. The properties control aspects of code generation for UML-to-Real-Time-C++ transformations and are listed in the order in which they appear in the Properties view, on the RT Properties page.
The information in parentheses refers to the element type and the name of the tab that is associated with the properties in Rational Rose® RealTime.
Copy Function Body (class, C++ TargetRTS)
Specifies the body of a function to copy a data type. By default the C++ transformation generates a function that calls the data type's copy constructor.
static void rtg_AClass1_copy( const RTObject_class * type, AClass1 *
target, const AClass1 * source )
{
(void)new( target ) AClass1( *source );
}
Decode Function Body (class, C++ Target RTS)
Specifies the body of a function to decode a data type from a stream of bytes. By default, the C++ code generator uses a built-in function. If the C++ Services Library does not recognize a data type, because it might be defined externally, or have private fields, you can write your own decoder. The function is passed a pointer to an object of the RTDecoding class called coding and a pointer is passed to an object of the externally defined type called target. The RTDecoding class has a number of operations that can be used to decode different data values to the target argument.
Note: The C++ transformation does not automatically generate proper decode functions for classes which have more than one base class.

In the Properties view for the MotorStatus class, on the RT Properties page, in the Target RTS group, the Decode Function Body field contains the code that decodes information injected when the model is running using a probe. Code in this field triggers the generation of a static function called rtg_MotorStatus_decode. The complete signature for the function is as follows:

static int rtg_MotorStatus_decode( const RTObject_class * type,
enum MotorStatus * target,
RTDecoding * coding )

The parameters type and coding are defined as above. The parameter target provides access to the data field of the signal; however, its use is not limited to probes or the signals.

You must provide encode and decode functions for attributes that have double indirection (for example, int **).
Destroy Function Body (class, C++ Target RTS)
Specifies the body of a function to destroy a data type. By default the C++ code generator calls the data types default constructor.
Histatic void rtg_AClass1_destroy( const RTObject_class * type, AClass1
* target )
{
target->~AClass1();
}
Encode Function Body (class, C++ Target RTS)
Specifies the body of a function to encode a data type to a stream of bytes. By default the C++ code generator uses a built-in function. If the C++ Services Library does not recognize a data type, because it might be defined externally, or have private fields, you can write your own encoder. The function is passed a pointer to an object of the RTEncoding class called coding and a pointer is passed to an object of the externally defined class called source. The RTEncoding class has several operations that encode different data values from the source argument.
Note:

The C++ transformation does not automatically generate proper encode functions for classes that have more than one base class.

To demonstrate this concept, consider a UML enumeration called MotorStatus that has three public attributes: On, Off, and Standby. The enumeration generates the following code:

enum MotorStatus { On, Off, Standby };
In the Properties view for the MotorStatus enumeration, on the RT Properties page, in the Target RTS group, the Encode Function Body field contains the code that encodes the data. If code is present in this field, it triggers the generation of a static function called rtg_MotorStatus_encode. The complete signature for this function is as follows:
static int rtg_MotorStatus_encode( const RTObject_class * type,
const enum MotorStatus * source,
RTEncoding * coding )
The parameter type points to a data structure that provides an internal description of the MotorStatus enumeration. The parameter source is a pointer to the data that the signal sends, and coding provides a pointer to the data structure that holds the descriptive information that a trace window will use. In the following code example, the signal data (contained in "source") is used to enter the proper string representation in "coding" using the "put_string" function:
// BEGIN CODE EXAMPLE
switch(*source)
{
case On :
coding->put_string("On");
break;
case Off:
coding->put_string("Off");
break;
case Standby:
coding->put_string("Standby");
break;
default:
coding->put_string("ERROR");
}
return 1;
// END CODE EXAMPLE
You must provide encode and decode functions for attributes that have double indirection (for example, int **).
Generate Descriptor (class, C++ TargetRTS)
If set to True, the C++ transformation creates a type descriptor (RTObject_class) for the class. The type descriptor allows marshalling (encode/decode) of the class.

The type descriptor contains information that the C++ Services Library requires to initialize, copy, destroy, encode, and decode data types. If the Generate Descriptor property is set to False, the data type cannot be sent by value in messages and is not observable or injected.

Init Function Body (class, C++ TargetRTS)
Specifies the body of a function to initialize a data type. By default the C++ transformation generates a function that calls the data types default constructor.
static void rtg_AClass1_init( const RTObject_class * type, AClass1 *
target )
{
(void)new( target ) AClass1;
}
You should only have to modify this property if your data type cannot be initialized with a default constructor.
Version (class, C++ TargetRTS)
Specifies the version of the data type.

Feedback