Union: Difference between revisions
No edit summary |
No edit summary |
||
Line 28: | Line 28: | ||
Composite unions don't require any additional specifications, such as the indication of an enumeration-based discriminant. Instead, each composition is considered a member of a single case labeled with an integer value corresponding to the compositions index in the composite. | Composite unions don't require any additional specifications, such as the indication of an enumeration-based discriminant. Instead, each composition is considered a member of a single case labeled with an integer value corresponding to the compositions index in the composite. | ||
== Union Structure Representation == |
Revision as of 12:12, 6 February 2024
The FACE 3 standard introduced the ability to document union templates – in Phenom, these are represented by union views. Though interpreted as unions in IDL, the FACE standard dictates C struct and C++/Java class representations of these structures; please refer to the FACE Technical Standard documents for details on implementing union type structures in code.
Union Creation In Phenom
Unions cannot be created independently, but rather existing Phenom view elements can be converted to be unions. On the view element's Details page, a toggle labeled 'Union' is used to change view element between a union and non-union structure.
Not all views can be changed to be a union type, and so the toggle may appear disabled for some view elements in a model. Which views may be transformed into unions is governed by FACE standard rules.
Non-Composite (Nesting) Views as Unions
For a non-composite view to be converted to a union, three FACE structural requirements must be fulfilled.
First: a union cannot be a “top level” type, but must rather be defined as a sub-type, nested inside the definition of another structure. In a FACE model, this will appear as a template structure that is not housed in its own template node, but is rather defined as a sub-structure in the specification of another template node. In Phenom, this is represented as a view that is referenced as the type of another view's field - this is what is referred to as "nested attribute". In this case, the field in question should also be marked as "Private", indicating that the nested view is defined in a scope internal to the view in which it is nested.
Second: to become a union, a view must have at least one attribute or field that references an enumeration as its platform type. In a FACE model, this enumerated field will be selected by the query related to the union template to serve as the discriminant over which the union is switched. In Phenom, when a user toggles a view to be a union, a drop-down appears next to the switch allowing the selection of the discriminant. This drop-down lists all of the current view's attributes the Platform Type property of which references a platform enumeration element.
Third: to be eligible for conversion to a union, all of the projections in the view must project the same element. In a FACE model, this is the same rule that applies to all non-composite templates. In Phenom, this requirement can be satisfied by ensuring that the first element of each attribute's projection path is the same for the selected view.
If the union toggle on a given view's page is disabled, is is likely because one of the above requirements is not fulfilled.
Assigning Case Literals to Union Fields
Once the discriminant of a view has been indicated, the attributes of the view can be assigned to the different union cases. Each case is represented by at least one of the literals associated with the discriminant attribute's platform type enumeration. While more than one of the literals can indicate a single case, only one attribute is allowed to occupy any given case. A given literal is also only allowed to be associated with a single case. The view attribute acting as the union's discriminant can also occupy one of the cases.
The literal assignment UI can be found by expanding a view attribute in Phenom. A drop-down listing the discriminant enumeration's literals found in the view attribute's expanded view is used to add literals to that attribute's case. Once selected, the literals of a given attribute's case are shown above the attribute rolename.
Composite Views as Unions
Composite FACE templates can also be indicated as unions. Mirroring that, in Phenom, composite views can also be switched to be unions.
Composite unions don't require any additional specifications, such as the indication of an enumeration-based discriminant. Instead, each composition is considered a member of a single case labeled with an integer value corresponding to the compositions index in the composite.