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 Messages: 28 Registered: January 2017 |
Junior Member |
|
|
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
Now
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).
Anyway
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?
Please help.
Thank you for your time and trouble.
Best regards
Phil.
|
|
| |
Re: User Model for C++ Template Containers [message #1751788 is a reply to message #1751440] |
Fri, 13 January 2017 21:58 |
|
Hi Philip,
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 #1763974 is a reply to message #1763944] |
Tue, 23 May 2017 14:11 |
|
Dear Philip,
if I interpret the figure right, you created a new class BoundElement which a parameter substitution with itself, i.e. T is replaced with BoundElement. This is not legal, as it would imply a circular substitution. You should substitute T by another class, e.g. MyActual. BoundElement is actually the type that would be written as TemplateClass<MyActual> in a programming language. It is a good idea to use a naming convention like TemplateClass_MyActual to clarify the nature of this class, i.e. I suggest to rename BoundElement.
Afterwards, you just type Attribute1 with the class TemplateClass_MyActual.
|
|
| |
Re: User Model for C++ Template Containers [message #1764198 is a reply to message #1764062] |
Fri, 26 May 2017 15:12 |
Philip Schröder Messages: 28 Registered: January 2017 |
Junior Member |
|
|
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
|
|
|
Goto Forum:
Current Time: Tue Apr 16 04:17:54 GMT 2024
Powered by FUDForum. Page generated in 0.20007 seconds
|