Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
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 Go to next message
Philip Schröder is currently offline Philip SchröderFriend
Messages: 25
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 #1751440 is a reply to message #1751320] Tue, 10 January 2017 11:39 Go to previous messageGo to next message
Philip Schröder is currently offline Philip SchröderFriend
Messages: 25
Registered: January 2017
Junior Member
As an update, I found this

http://www.omg.org/spec/UML/2.4.1/Superstructure/

There all the parameters like Default, Owned Default, Owned parametered Element or Owned actual are explained starting from page 651.

Now the only problem left is, how to set specific bound elements from a user model as types of class properties.
Re: User Model for C++ Template Containers [message #1751788 is a reply to message #1751440] Fri, 13 January 2017 21:58 Go to previous messageGo to next message
Ansgar Radermacher is currently offline Ansgar RadermacherFriend
Messages: 163
Registered: March 2011
Location: Paris Saclay, France
Senior Member
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 #1763944 is a reply to message #1751788] Tue, 23 May 2017 09:26 Go to previous messageGo to next message
Philip Schröder is currently offline Philip SchröderFriend
Messages: 25
Registered: January 2017
Junior Member
Dear Ansgar Radermacher,
first of all thank you for your answer.

As I think I already said in my original post, I did define a template substistution.
What I want is to use that now as a type to an Attribute.
Maybe the picture will make it clear, what I want to achieve

index.php/fa/29433/0/

As you can see, I did set formal and actual, but how do I make it, that I get the result Attribute1: TemplateClass<BoundElement>?

What do I have to choose in the type wizard window?

Thank you for your time and trouble.


Best regards

Philip.
Re: User Model for C++ Template Containers [message #1763974 is a reply to message #1763944] Tue, 23 May 2017 14:11 Go to previous messageGo to next message
Ansgar Radermacher is currently offline Ansgar RadermacherFriend
Messages: 163
Registered: March 2011
Location: Paris Saclay, France
Senior Member
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 #1764062 is a reply to message #1763974] Wed, 24 May 2017 13:30 Go to previous messageGo to next message
Philip Schröder is currently offline Philip SchröderFriend
Messages: 25
Registered: January 2017
Junior Member
Sorry,
but I don't get what you are saying;
T is the template parameter of TemplateClass; I then created a new class BoundElement and a TemplateBinding from BoundElement to templateClass with formal = T and actual = BoundElement.

I want to bind BoundElement as a template substitution to the template Parameter T of templateClass.

I understood it like that is what does templateClass<T> -> templateClass<BoundElement>

like this

http://www.uml-diagrams.org/template.html#template-binding

Why is this a circular substistution?

[Updated on: Wed, 24 May 2017 13:42]

Report message to a moderator

Re: User Model for C++ Template Containers [message #1764198 is a reply to message #1764062] Fri, 26 May 2017 15:12 Go to previous message
Philip Schröder is currently offline Philip SchröderFriend
Messages: 25
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

Previous Topic:Confusing Property Types
Next Topic:Confusing Property Types
Goto Forum:
  


Current Time: Wed Oct 17 21:21:41 GMT 2018

Powered by FUDForum. Page generated in 0.01754 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top