Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Papyrus » Help with templates
Help with templates [message #1816826] Thu, 07 November 2019 19:09 Go to next message
Stephen Blackwell is currently offline Stephen BlackwellFriend
Messages: 138
Registered: March 2014
Senior Member
I've been struggling with understanding how to use templates in Papyrus so I found an example here https://docs.nomagic.com/display/MD190/Template and decided to attempt to recreate it in Papyrus.

I got stuck trying to add a Template Parameter to to a Redefinable Template signature.
index.php/fa/36727/0/

Para 7.3.3.2 says "A templateParameter is defined in terms of a ParameterableElement contained within the template that owns the TemplateSignature of which the TemplateParameter is a part."

OK, so I read that as saying that I need to add a ParameterableElement to my GenericArray template. Para 7.8.13.1 says "A ParameterableElement is an Element that can be exposed as a formal TemplateParameter for a template, or specified as an actual parameter in a binding of a template."

I take this to mean that any element can be a ParameterableElement once it is associated with a TemplateParameter. I added the property myArraySize to GenericArray and then attempted to set it as the Paramererized Element of the current Undefined Template Parameter but nothing appears to happen. There are no messages, warnings but the Template Parameter still says UNDEFINED.

Can someone point out where I'm going wrong here?
I found an open bug from 2013 or 2014 that said that this was not possible but at some point in my experiments, I was able to get class: T written into the TemplateParameter. I just don't know how.

Thanks,
Steve
Re: Help with templates [message #1816947 is a reply to message #1816826] Tue, 12 November 2019 17:33 Go to previous messageGo to next message
Stephen Blackwell is currently offline Stephen BlackwellFriend
Messages: 138
Registered: March 2014
Senior Member
Found this bug report. https://bugs.eclipse.org/bugs/show_bug.cgi?id=405600 so maybe it is not possible but I know I got it to work one time.
Re: Help with templates [message #1817199 is a reply to message #1816947] Mon, 18 November 2019 13:44 Go to previous messageGo to next message
Ansgar Radermacher is currently offline Ansgar RadermacherFriend
Messages: 228
Registered: March 2011
Location: Paris Saclay, France
Senior Member
Hi Steve,

while it's not very user-friend, it works for me: Select the "undefined" parameter and then click on the "+" of the "Owned parametered ..." field in the property view (already in your screen-shot). Choose for instance DataType as meta-class. In the dialog that pops-up afterwords, choose the name "T" (leave all other fields as they are)

Best

Ansgar
Re: Help with templates [message #1817209 is a reply to message #1817199] Mon, 18 November 2019 14:51 Go to previous messageGo to next message
Stephen Blackwell is currently offline Stephen BlackwellFriend
Messages: 138
Registered: March 2014
Senior Member
Hmm....

I'm not sure if I follow you correctly. Did you mean choose "InstanceDataType" as the Owned parametedElement or did you mean choose "DataType" as the instance of the Owned parameteredElement?

If I choose DataType, name it T and click OK, the Owned parameteredElement remains <Undefined>.
The pop up list for the Owned parameteredElement has an "InstanceSpecification" and an "InstanceValue" but no "InstanceDataType".

If I select either "InstanceSpecification" or "InstanceValue", the Owned parameteredElement and ParameteredElement get filled in.

For my array example, I chose an InstanceValue for ArraySize and gave it a default of an IntegerLiteral = 10 and I chose an InstanceSpecification for ArrayType so my example now looks like this.
index.php/fa/36772/0/
which I think is what I want.

Thanks,
Steve
Re: Help with templates [message #1817246 is a reply to message #1817209] Tue, 19 November 2019 09:05 Go to previous messageGo to next message
Ansgar Radermacher is currently offline Ansgar RadermacherFriend
Messages: 228
Registered: March 2011
Location: Paris Saclay, France
Senior Member
Hi Steve,

I meant DataType and not InstanceDataType (which is not offered in my case). I've chosen to add a "classifier template parameter" after having created the (redefinable template) signature. For this, "DataType" works - unlike for a "normal" (non classifier) template parameter. I think, the popup list should be better filtered, depending on the kind of template parameter.

Ansgar
Re: Help with templates [message #1817282 is a reply to message #1817246] Tue, 19 November 2019 19:25 Go to previous message
Stephen Blackwell is currently offline Stephen BlackwellFriend
Messages: 138
Registered: March 2014
Senior Member
Hi Ansgar,
Agreed. There is already an bug report on this but it's been out there a while.

So I wanted to try to create an STL project that uses some parameterized type. I created a vector template class using a Template Parameter and a set template using a Classifier Template Parameter. I made the root element an ExternalLibrary and gave it a prefix of std. Like this:
index.php/fa/36777/0/
Then a created a couple of DataTypes to bind to the templates and creates a class with some properties of those bound DataTypes and generated the code. This didn't really work. Here is the code generated for my intSetType:
index.php/fa/36778/0/
First of all it the code tries to include a file called "helloworldRootElementName/set.h" that doesn't exist and second it tyies to typedef set<Integer> instead of std::set<Integer>. I could add "using namespace std;" to the stereotype header but that is not ideal.

Next I decided to try to create a nested DataType to bind to the template like this:
index.php/fa/36780/0/
This looks more promising. Here is the .h file it generated:
index.php/fa/36781/0/
Any idea on how to get the std prefix to show up?

Thanks,
Steve
Previous Topic:cannot update from 4.4 to 4.5
Next Topic:Issue with Undo
Goto Forum:
  


Current Time: Mon Dec 16 01:50:35 GMT 2019

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

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

Back to the top