Union: Difference between revisions

From PHENOM Portal Knowledgebase
Jump to navigation Jump to search
No edit summary
Line 1: Line 1:
[[File:View Page Union Toggle.png|alt=The toggle to switch a view to a union type on the view element's detail page.|thumb|481x481px|The toggle to switch a view to a union type on the view element's detail page.]]
[[File:View Page Union Toggle.png|alt=The toggle to switch a view to a union type on the view element's detail page.|thumb|481x481px|The toggle to switch a view to a union type on the view element's detail page.]]
The FACE 3 standard introduced the ability to document union templates – in Phenom, these are represented by union [[View|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 [https://publications.opengroup.org/c207 FACE Technical Standard] documents for details on implementing union type structures in code.
The FACE 3 standard introduced the ability to document union templates – in Phenom, these are represented by union [[View|views]].


== Union Creation In Phenom ==
== Union Creation In Phenom ==
Line 29: Line 29:
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 ==
== Union View Export to FACE 3 Queries and Templates ==
[[File:Union Query Template Preview.png|thumb|507x507px|A view of Phenom's query and template preview for a union view.]]
Upon exporting a model to the FACE 3 format, Phenom automatically converts any union views to their appropriate FACE query and template representations.
 
The template representing any union view is prefixed with the `union` FACE keyword. The discriminant field selected for the view is used as the parameter of the union's switch statement. The view attributes' case literal assignments are converted to case groups in the union template. The union template as a whole is related to a query that reflects the semantics indicated in the view attributes' Phenom paths.
 
The query and template generated for a given view can be previewed on the view's Details page by expanding the 'Query and Template Preview' section under the attributes listing.
 
== Union Structure Code Representation ==
Though interpreted as unions in IDL, the FACE standard dictates C struct and C++/Java class representations of these structures.
 
Please refer to the [https://publications.opengroup.org/c207 FACE Technical Standard] documents for details on implementing union type structures in code.

Revision as of 11:26, 6 February 2024

The toggle to switch a view to a union type on the view element's detail page.
The toggle to switch a view to a union type on the view element's detail page.

The FACE 3 standard introduced the ability to document union templates – in Phenom, these are represented by union views.

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.

The private nesting of a union view within a top level view.

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.

Selection of an enumeration-based view attribute as a union discriminant.

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.

The projected characteristic uniformity among view attributes required of union types.

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

The drop-down listing the discriminant field's enumeration type's literals can be used to select case literals applied to a given field's case. Once selected, they will appear above the relevant field's rolename.

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.

Union View Export to FACE 3 Queries and Templates

A view of Phenom's query and template preview for a union view.

Upon exporting a model to the FACE 3 format, Phenom automatically converts any union views to their appropriate FACE query and template representations.

The template representing any union view is prefixed with the `union` FACE keyword. The discriminant field selected for the view is used as the parameter of the union's switch statement. The view attributes' case literal assignments are converted to case groups in the union template. The union template as a whole is related to a query that reflects the semantics indicated in the view attributes' Phenom paths.

The query and template generated for a given view can be previewed on the view's Details page by expanding the 'Query and Template Preview' section under the attributes listing.

Union Structure Code Representation

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.