Mono and multi valued attributes [message #1850226] |
Tue, 22 February 2022 10:18 |
John Henbergs Messages: 239 Registered: October 2020 |
Senior Member |
|
|
Hi all,
I came across the following paragraph in a research paper.
Since QVT-O distinguish between assignments to mono- or multi-valued properties or variables, this has also to be considered during the processing of attributes. Hence, a simple assignment (':=' operator) is used for the mapping of an attribute with an upper multiplicity of 1. In contrast, attributes with an upper multiplicity of >1 are assigned with a composite assignment ('+=' operator).
From my understanding this means that if the source element is a collection then we use += and if it is not, we use :=.
Is that always the case?
For example if I map
result.multiA += self.multiB -> map ... (this works fine)
result.singleA += self.multiB -> map ... (I get an error "Property singleA must have collection type").
And the rest should be like this?
result.singleA := self.singleB. map
result.multiA := self.singleB .map
Moreover , I have read that when executing the mapping on a single element, after the element we put a dot not an arrow, and executing the mapping on a collection of elements, we put an arrow. But is that for the input or output? So when the input is single/collection or when the output is single/collection?
|
|
|
Re: Mono and multi valued attributes [message #1850229 is a reply to message #1850226] |
Tue, 22 February 2022 10:45 |
Christopher Gerking Messages: 116 Registered: April 2011 |
Senior Member |
|
|
Hi
John Henbergs wrote on Tue, 22 February 2022 05:18
From my understanding this means that if the source element is a collection then we use += and if it is not, we use :=.
Not entirely. If the source element is a collection then we use either += (to add the element to the collection) or := (to reinitialize the collection with the element, dropping all previous elements). If it is not a collection, we use := because adding is not possible. As you can see, the difference is whether you would like to reset your collection or not. By the way, this is something you could have found out really easily using the QVTo debugger.
John Henbergs wrote on Tue, 22 February 2022 05:18
result.singleA += self.multiB -> map ... (I get an error "Property singleA must have collection type"). But this makes a lot of sense, isn't it? multB is multi-valued. You invoke a mapping on each of these values, resulting in a collection of mapping results. Obviously you can't assign that collection to singleA because it is single-valued. What behavior did you expect instead?
John Henbergs wrote on Tue, 22 February 2022 05:18
Moreover , I have read that when executing the mapping on a single element, after the element we put a dot not an arrow, and executing the mapping on a collection of elements, we put an arrow. But is that for the input or output? So when the input is single/collection or when the output is single/collection?
For the difference between the dot and arrow notations, take a look at this recent topic: https://www.eclipse.org/forums/index.php/t/1109682/
Kind regards
Christopher
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05620 seconds