Integrations (PTC products, 3rd party products and code) > Code integration (Ada, ARINC 653, C, C#, C++, IDL, Java, SQL and VB) > C++ code > Generating C++ code > Generating C++ code > Mapping Information > Mapping information for state diagrams > Association and Role mapping for C++(C++ code)
  
Association and Role mapping for C++(C++ code)
ACS generates Roles applied by Associations and Aggregations as data members (attributes) of a Class, Data Type or Interface. The header file in which the data members are created is determined by the Association Type:
Start-end - generated in the header file created for the Start item.
End-start - generated in the header file created for the End item.
Bi-directional - generated in the header files created for both the Start item and End item.
None - the Association is ignored.
Reverser Notes: When reverse engineering a class' or struct's attributes, the Reverser will reverse engineer an attribute as a Role if allof the following statements are true:
The C++ attribute's data type can be identified as a class or structin the code being reverse engineered.
Note that if the attribute's data type is a collection class or struct, the Cppgen.ini file determines whether the attribute is reverse engineered as a Role or Attribute in the model. For more information, see Collection Class mapping for C++ (C++ code).
The C++ class or struct that is used as a data type can be reverse engineered, that is, it is a child of the root folder or a folder that is mapped to a Modeler Package.
The Reverser cannot match the C++ attribute to an Attribute in the Model.
If a typed Part has an Association that has not been rolled up to the Part's type, ACS generates a nested Class that is derived from the Part's type. The nested Class defines the Role that is modeled against the Part.
If a Class, Data Type or Interface owns Parts that are connected through an Association, initialization code is generated in the constructor for the Class, Data Type or Interface.
The attribute declaration and initialization is derived from the properties of the Association, its Roles and the tagged values set for Tag Definitions that are applied to the Roles by the «C++ Role» stereotype.
Properties
Unnamed Roles are generated with an 'r' prefix, and named Roles are generated without an 'r' prefix. Prefixing and suffixing of named and unnamed Roles is controlled through the [role] and [unnamed role] sections of the mangle.ini file. For example, if you want all Roles to be generated with a 'r' prefix, ensure that the Role sections of the mangle.ini file are as follows:
[role]
AddPrefix=r
AddSuffix=
[unnamed role]
AddPrefix=r
AddSuffix=
The Behavior property is used with the Port property - for more information, see the Port property entry.
If the Composite property is set to false (Composite check box cleared on Property Pages), a pointer to the type is generated. Example code
If a Default Value is set, the value is generated either as a static attribute initializer or a constructor initializer. Example code. For more information, see Default Value for Part Redefinitions.
If the Read Only property is set to true (Read Only check box selected on Property Pages), the const keyword is used.
Example code
If the Port property is set to true (Port check box selected on Property Pages) the Role is generated as a port. For more information about how a Port is generated, including information about port forwarding and wiring, see Port mapping for C++ (C++ code).
If a Qualifier is defined, the generated attribute's type is a map of pointers to the other class or struct, unless the Role is a Composite Aggregate, in which case the generated attribute's type is a map of the other class or struct. Example code
If a Qualifier is not defined, the Multiplicity of the Role determines the generated attribute's type:
If the Multiplicity is 1 (Multiplicity property is set to 1), a pointer to the other class or struct is used, unless the Role is a Composite Aggregate, in which case the other class or struct is used. Example code
If the Multiplicity is a fixed size of two or more (set through User Defined), an array of pointers to the other class or struct is used, unless the Role is a Composite Aggregate, in which case an array of the other class or struct is used. Example code
If the Multiplicity is TBD (Multiplicity property is set to 0), a pointer to the other class or struct is used, unless the Role is a Composite Aggregate, in which case the other class or struct is used. Example code
If the Multiplicity specifies a range, a vector of pointers to the other class or struct is used, unless the Role is a Composite Aggregate, in which case a vector of the other class or struct is used. Example code
If the Storage property of a Role is set to On Class, a static keyword is used for the generated attribute. Example code
The Unique property is ignored.
The Visibility property is used to generate an attribute with the correct visibility in the class or struct definition. Generated attributes are organized by their visibility, that is, Public, Protected, Private or Package.
Tag Definitions:
The following tag definitions are applied to a Role by the «C++ Role» stereotype:
If the tagged value of the C++ Actual Template Parameters tag definition has been set, the value is used to generate the text between the angle brackets, which appears after the value of the C++ Data Type tag definition. Typically used when a collection template class is used to implement the Role. Example code
If the tagged value for the C++ Array Spec tag definition has been set, the set value is used as the array, that is, it is generated after the attribute name. Note that the value must include any brackets. Example code
* 
The C++ Array Spec tag definition is required only for multi-dimensional arrays. One dimensional arrays are modeled through the Association multiplicity.
Reverser Notes: When reverse engineering an initializer or array specification that uses a macro, the C++ Array Spec tag definition is set to the unpreprocessed text.
If the tagged value of the C++ CV Qualifier tag definition is set to const, volatile or const volatile, the selected keyword is generated before the data type. Example code
If the tagged value of the C++ Data Type tag definition references a Class, Data Type or Interface, ACS ignores other Role properties and uses only the value of the C++ Actual Template Parameters tag definition and the referenced Class, Data Type or Interface to generate a container template class that implements the Role. Example code.
Reverser Notes: Note that sometimes the data type of the role that is reverse engineered isn't actually the class or struct at the other end: it is a collection of the classes or structs at the other end. Template classes are often used to achieve this effect. When this is the case, the Reverser creates a sensible Role by looking at the first actual parameter to the template class. If the template class is modeled in the model, it is referenced through the C++ Data Type tag definition. If the template class is not modeled in the model, its name is recorded through the C++ Template Name tag definition.
If the tagged value of the C++ Indirection tag definition has been set, the value is used as an indirection, that is, the value is generated after the data type and before the attribute name. Example code
If the tagged value of the C++ Linkage tag definition has been set, the value is generated as the attribute's linkage. For example, extern "C".
If the tagged value of the C++ Storage Class tag definition is set to auto, register, extern or mutable, the selected storage class keyword is generated. Note that in the context of a Role, only the mutable value of the C++ Storage Class tag definition should be used. Example code
If the tagged value of the C++ Template Name tag definition is set, ACS ignores other Role properties and uses only the value of the C++ Actual Template Parameters tag definition and the named Class, Data Type or Interface to generate a container template class that implements the Role. Example code
Reverser Notes: Note that sometimes the data type of the role that is reverse engineered isn't actually the class or struct at the other end: it is a collection of the classes and structs at the other end. Template classes are often used to achieve this effect. When this is the case, the Reverser creates a sensible Role by looking at the first actual parameter to the template class, which acts as a collection for the other classes and structs. If the template Class is modeled in the model, it is referenced through the C++ Data Type tag definition. If the template Class is not modeled in the model, its name is recorded through the C++ Template Name tag definition.