Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Papyrus » Template class attribute of a template class(Instantiate a template class within another template class and pass through the template parameter)
Template class attribute of a template class [message #1822500] Sun, 08 March 2020 19:01 Go to next message
Dila Eclipse is currently offline Dila EclipseFriend
Messages: 4
Registered: March 2020
Junior Member
What I would like to achieve is this (in C++)

template <typename T> class Inner {
};

template <typename T> class Outer {
  Inner<T> myAttribute;
};


That is, I want to instantiate a template class within another template class and pass through the template parameter.

What I have tried is this

index.php/fa/37538/0/

But when I generate the C++ code, there is a problem

template<class S>
class linked_list {
public:
	/************************************************************/
	typedef shared_ptr<S> linked_list_element_ptr;

	/**
	 * 
	 */
	::CppProject::linked_list::linked_list::linked_list_element_ptr head_;

};


The problem is that, although the inner class is correctly bound to the template parameter of the outer class, the attribute definition refers to the absolute global namespace signature of the inner class and neglects to specify the required template parameter.

So it does not compile.

Is this a bug or is my approach wrong?
  • Attachment: uml.png
    (Size: 37.73KB, Downloaded 432 times)

[Updated on: Mon, 09 March 2020 20:32]

Report message to a moderator

Re: Template class attribute of a template class [message #1822622 is a reply to message #1822500] Tue, 10 March 2020 14:35 Go to previous messageGo to next message
Carsten Pitz is currently offline Carsten PitzFriend
Messages: 479
Registered: May 2015
Location: Germany
Senior Member
I have no C++ Designer installed, but what is about the attached model.
/Carsten
Re: Template class attribute of a template class [message #1822649 is a reply to message #1822622] Tue, 10 March 2020 18:58 Go to previous messageGo to next message
Dila Eclipse is currently offline Dila EclipseFriend
Messages: 4
Registered: March 2020
Junior Member
Thanks, but unfortunately this is not the same as what I am trying to achieve.

The model you have posted produces the following C++ code

class T {
};

class Outer: public T {
public:
	class Inner: public T {
	};
};


Which has nested the declaration of the class rather than an attribute definition. Also, the Template/Generics aspect is missing.

I really appreciate your help though, thanks!
Re: Template class attribute of a template class [message #1822650 is a reply to message #1822649] Tue, 10 March 2020 19:25 Go to previous messageGo to next message
Carsten Pitz is currently offline Carsten PitzFriend
Messages: 479
Registered: May 2015
Location: Germany
Senior Member
Yes, I know. But this is the best semantic approximation with UML notation I am aware of.
Maybe, one of the two Ed know a better one.
/Carsten
Re: Template class attribute of a template class [message #1822651 is a reply to message #1822650] Tue, 10 March 2020 19:31 Go to previous messageGo to next message
Carsten Pitz is currently offline Carsten PitzFriend
Messages: 479
Registered: May 2015
Location: Germany
Senior Member
BTW, if this is really the output of the C++ Designer. Feel free to file a bug report. I am pretty sure I declared the both classes private.
Re: Template class attribute of a template class [message #1822657 is a reply to message #1822651] Tue, 10 March 2020 21:05 Go to previous messageGo to next message
Dila Eclipse is currently offline Dila EclipseFriend
Messages: 4
Registered: March 2020
Junior Member
For the benefit of other readers, I have a screenshot of the model that you uploaded

index.php/fa/37561/0/
  • Attachment: model.png
    (Size: 7.19KB, Downloaded 306 times)
Re: Template class attribute of a template class [message #1822677 is a reply to message #1822657] Wed, 11 March 2020 09:45 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Templates can be really hard and you might well have hit a C++ generator bug, but you may just have done something stupid.

I recommend trying it at the underlying Ecore level and see whether the corresponding Java is plausible.

I suspect that the support for templates in Ecore was strongly influenced by IBM's (misguided) desire to provide an Ecore/UML parameterization of OCL. You may therefore find the following helpful:

https://git.eclipse.org/r/plugins/gitiles/ocl/org.eclipse.ocl/+/master/plugins/org.eclipse.ocl/model/OCL.ecore
https://git.eclipse.org/r/plugins/gitiles/ocl/org.eclipse.ocl/+/master/plugins/org.eclipse.ocl/model/OCL.uml
https://git.eclipse.org/r/plugins/gitiles/ocl/org.eclipse.ocl/+/master/plugins/org.eclipse.ocl.ecore/model/OCLEcore.ecore

Regards

Ed Willink




Previous Topic:No Properties Editor is visible using SysML1.6 for Eclipse 2019-12
Next Topic:Papyrus Activity Diagram Creation via API
Goto Forum:
  


Current Time: Fri Apr 19 22:03:43 GMT 2024

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

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

Back to the top