Book a Demo

Author Topic: C++ template instantiation  (Read 5051 times)

edroi

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
C++ template instantiation
« on: November 25, 2009, 02:54:32 am »
Hi

I am trying to use Enterprise Architect for documenting and modeling C++ projects.
So far I've been quite happy with the tool. However I have a couple of issues I'd like to be resolved.
Can anybody explain me how to create an instantiation of a parametrized class (C++ template)?
In Rational Rose a result of instantiation of a template class would look like an anonymous class (with stereotype "anonymous") with a specific template parameter. This class will be connected to the parametrized one with association 'instantiates'. (The same is created as a result of reverse engineering.)
The only help I found in EA regarding this subject is in the topic about parametrized classes where it is said
"For an instantiated template, select Instantiated and add the arguments in the Arguments field"
I tried that and didn't really see on the UML diagram any difference between regular classes and instantiated one.
Am I missing anything?

Thanks
Eugene

Makulik

  • EA User
  • **
  • Posts: 400
  • Karma: +0/-0
    • View Profile
Re: C++ template instantiation
« Reply #1 on: November 25, 2009, 04:46:36 am »
Hi,

There's no difference shown for instantiations of parameterized classes vs. regular ones in EA.
In short:
Generalize the parameterized class from a new one, name it appropriately (e.g. provide the full language syntax like 'map<string>'), provide the same class parameters as in the base, also fill in the Arguments, and set 'none' as code generation language.

HTH
Günther


edroi

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Re: C++ template instantiation
« Reply #2 on: November 25, 2009, 12:20:58 pm »
Thanks Gunter.
However I am a bit puzzled what's really value there in specifying those arguments.
Besides in my view it would make more sense having the relationship with a template class 'instantiate' vs 'generalize".
Also naming a class "map<string>" does not look semantically  correct to me. It is probably good enough though for presentation purposes
« Last Edit: November 25, 2009, 12:22:15 pm by edroi »

Makulik

  • EA User
  • **
  • Posts: 400
  • Karma: +0/-0
    • View Profile
Re: C++ template instantiation
« Reply #3 on: November 26, 2009, 02:12:46 am »
Quote
Besides in my view it would make more sense having the relationship with a template class 'instantiate' vs 'generalize".
In fact it should be a <<bind>> stereotyped dependency AFAIK, but this is not really supported by EA.

Quote
Also naming a class "map<string>" does not look semantically  correct to me. It is probably good enough though for presentation purposes

Not so sure now if this is necessary at all. But filling in the Arguments field matters for code generation (e.g. if a class inherits an instantiated parameterized class).

I have a more detailed article (tutorial) about this topic. If you're interested, leave your eMail in my message box and I'll hand it out to you.

WBR
Günther

edroi

  • EA Novice
  • *
  • Posts: 8
  • Karma: +0/-0
    • View Profile
Re: C++ template instantiation
« Reply #4 on: November 26, 2009, 02:21:05 am »
Thanks
I sent my email to you.
Please let me know in case you didn't receive it

g.makulik

  • EA User
  • **
  • Posts: 355
  • Karma: +0/-0
    • View Profile
Re: C++ template instantiation
« Reply #5 on: November 26, 2009, 07:34:54 am »
Hi Eugene,

Yes, after having a look again, I'm using the notation I have mentioned in my last post. At least it's valid UML notation (you can name classes as you like) and helps with correct (C++)code generation from EA.
The UML 2.2 Superstructure spec (http://www.omg.org/spec/UML/2.2/Superstructure/PDF/)
covers the topic in chapter '17.5 Templates' (couldn't really find this so quickly ;-)).
It's the <<bind>> dependency stereotype that should be used for instantiations (substitutions) of parametrized classes. As described there further, the notation to specify the substituted class parameters is to put text label (the <<bind>> associations name?) besides the stereotype, like this for given class parameters T:class, k:int :

    <<[size=9]bind[/size]>>[size=9] <T -> S1, k -> 5>[/size]

At least this could be visualized easily in EA using the associations name. But this will have no impact
on code generatioon AFAIK.

WBR
Günther
Using EA9.3, UML2.3, C++, linux, my brain, http://makulik.github.com/sttcl/

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8626
  • Karma: +259/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: C++ template instantiation
« Reply #6 on: November 26, 2009, 09:54:39 am »
Quote
[size=18]...[/size]
The UML 2.2 Superstructure spec (http://www.omg.org/spec/UML/2.2/Superstructure/PDF/)
covers the topic in chapter '17.5 Templates' (couldn't really find this so quickly ;-)).
It's the <<bind>> dependency stereotype that should be used for instantiations (substitutions) of parameterized classes.
[size=18]...[/size]
Hi Gunther,

I believe the «bind» relationship, together with «realization» and «generalization» are examples of transformative relationships.  Where the instructions for the transform should be contained in the relationship, not the end items.  Unfortunately (AFAIK), no tools take this view and so they all struggle.

If one did take this view, one could even provide «transform» relationships (dependency) that would identify the origins and destinations of transforms.

Just my  AU$0.05,
Paolo
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!