Home » Modeling » Papyrus » User Model for C++ Template Containers(Trying to define the C++ STL containers as bound template classes to be used in my UML model)
|User Model for C++ Template Containers [message #1751320]
||Sun, 08 January 2017 14:15
| Philip SchrÃ¶der
Registered: January 2017
Dear fellow Developers,|
I am currently trying to understand how to created template classes and bind actual parameters to them to get a C++ STL container library as a UML model, which I plan to use then in another model by
ModelExplorer -> modelRoot -> rightClick -> Import -> Import Package from User Model
So suppose I want to have in C++ something like
HashMap<T> and for T I want to use some custom class BoundElement
1. I have created a class named HashMap.
2. I have added a Redefinable Template Signature.
3. I have added a Classifier Template Parameter to the signature.
Now in the properties editor I got 4 parameters:
Default, Owned default, Owned parametered element and parametered element.
This is my first problem, I have no clue what the purpose of those is, nor did I find information in any documentation, not UML nor Papyrus; I chose Owned parametered element, because I read it in a Forum, but when I put values in several it seems strange.
I just want HashMap<T>, so I clicked + -> Class and named it T.
I thought maybe the Default could somehow mean, what to use when there are no elements bound to the container.
Setting Owned paramtrized element together with Default gave me a type signature T: Class=String, which I hope, but don't know, is what I think it is.
Not having any documentation clearly leaves me completely lost here.
I still have no idea what Owned Default and Parametered Element are supposed to do (especially what the difference between Parametered Element and Owned parametered element might be).
4. I created another custom class BoundElement
5. From Edges, I used TemplateBinding from BoundElement to HashMap
For unknown reasons it didn't have the <<bind>> stereotype.
6. I specified Formal = T and Actual = Bound Element.
Here again I have no clue what Owned Actual is or what the difference to Actual is.
Now I tried to import the Model into my original one and use the BoundElement as data type for some class property.
I am unsure if the type should be now HashMap or BoundElement, those are the 2 possibilities that I found, I chose HashMap.
Also it doesn't show me, if it is actually a HashMap<BoundElement>, it only says HashMap.
What is going wrong?
Thank you for your time and trouble.
|Re: User Model for C++ Template Containers [message #1751788 is a reply to message #1751440]
||Fri, 13 January 2017 21:58
|| Ansgar Radermacher
Registered: March 2011
Location: Paris Saclay, France
good that you already found out the differences between ownedParametered and parametered element.
There is no <<Bind:>> stereotype, that is normal. The confusion is caused by the UML notation which uses the <<>> also for non-stereotypes, e.g. for abstractions, interfaces, or the <<bind>> on page 641 of the 2.4.1 standard.
When you create a template binding, you need to add a parameter substitution. Create a reference to formal and actual. In case of classifier template parameters, you typically don't provide an owned actual, since your actual is part of the "normal" model. Owned actuals, i.e. those that are part of the template-binding relationship are typically used for concrete values, e.g. if your template parameter is an integer value (size), the template binding could contain the concrete value in form of a literal integer.
The OS abstraction layer in Papyrus SW designer (a registered import library) uses template to some extend. There is also a very small subset of the C++ STL (also a registered library) that defines the STL classes pragmatically simply as external classes.
Hope that helps
|Re: User Model for C++ Template Containers [message #1764198 is a reply to message #1764062]
||Fri, 26 May 2017 15:12
| Philip SchrÃ¶der
Registered: January 2017
I think I understood it now.|
As the UML2.4.1-Specification says on page 632:
"The semantics of a binding relationship is equivalent to the model elements that would result from copying the contents of the template into the bound element, replacing any elements exposed as a template parameter with the corresponding
element(s) specified as actual parameters in this binding."
I always thought, this was a mistake, and actually the content of the bound element is copied into the template as a substitution for the corresponding template signature parameter, but it seems as if it is not that binding Bar to the template Foo,
the result becomes Foo<Bar>, but actually that assuming Foo is of the form Foo<Class T> and Bar has a template Binding to Foo with a template substistution T -> Blubs, then Bar = Foo<Blubs>.
So if I want Foo<Blubs> as a type of a property, I choose Bar as the type.
Oh, I see, you already said that in your answer, while I was too blinded to see it, my apologies.
[Updated on: Tue, 30 May 2017 13:44]
Report message to a moderator
Current Time: Thu Apr 19 15:56:48 GMT 2018
Powered by FUDForum
. Page generated in 0.02081 seconds