Book a Demo

Author Topic: Modelling C++ templates??  (Read 15373 times)

Hazzelbanger

  • EA Novice
  • *
  • Posts: 10
  • Karma: +0/-0
    • View Profile
Modelling C++ templates??
« on: February 23, 2010, 03:54:53 pm »
Hi,

The user guide has minimal details on the modelling of templates. So I wrote the following C++ code and reverse engineered it in (EA version 7.1.828).

<Code>

template<class T, class U> Foo
{
public:
    T d1;
    U d2;
};

typedef Foo<int, char> FooType;

<Code>

The reverse engineering created the Foo class and the FooType typedef. When I dragged them onto a class diagram it displayed FooType to be inherited from Foo. However, the diagram does not display the template binding arguments for the typedef. So how does a reader of the diagram determine what template arguments are defined by FooType?

If I open the proptery details for FooType, EA indicates FooType is an Instantiated template with the correct arguments. But why don't these arguments appear on the diagram?

Do I need to tick a setting somewhere to make this happen?

Is there more doco available on dealing with C++ templates?


TIA Hazzelbanger

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Modelling C++ templates??
« Reply #1 on: February 23, 2010, 06:24:10 pm »
There is a help page available on parametrized classes

Geert

Hazzelbanger

  • EA Novice
  • *
  • Posts: 10
  • Karma: +0/-0
    • View Profile
Re: Modelling C++ templates??
« Reply #2 on: February 23, 2010, 11:06:24 pm »
Unfortunately help page is the one I referred to in my initial post. I don't find it very useful.

Hazzelbanger

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Modelling C++ templates??
« Reply #3 on: February 23, 2010, 11:19:23 pm »
Sorry, then I won't be able to help you.
I haven't really used this feature before, but I plan on doing so.
If I ever find out how it works exactly I'll let you know.
If anybody has experience on how to use this please post an explanation.

Geert

Makulik

  • EA User
  • **
  • Posts: 400
  • Karma: +0/-0
    • View Profile
Re: Modelling C++ templates??
« Reply #4 on: February 24, 2010, 01:53:58 am »
Quote
I don't find it very useful.
So what do you miss in particular, or need to be more explained?

WBR
Günther
« Last Edit: February 24, 2010, 01:54:53 am by Makulik »

Hazzelbanger

  • EA Novice
  • *
  • Posts: 10
  • Karma: +0/-0
    • View Profile
Re: Modelling C++ templates??
« Reply #5 on: February 25, 2010, 09:27:28 am »
The diagram is missing the details outlining what types are used to instantiate the template. To achieve my aim I have edited the generalisation link and set the link name to " T->int, U->char", and set the stereotype to <<bind>>.  Before I performed these steps it was not possible for the reader of the printed diagram to determine the template instantiation. I was hoping I wouldn't have to perform this step after reverse engineernig in the code.

Makulik

  • EA User
  • **
  • Posts: 400
  • Karma: +0/-0
    • View Profile
Re: Modelling C++ templates??
« Reply #6 on: February 25, 2010, 11:44:34 pm »
Hi,

I already guessed s.th like this (that's the really interesting part usually, and totally missing in EA documentation).
In short: To model it correctly in UML you need to setup a <<bind>> dependency between the parameterized class and the instantiated template class.
But to do this in a way, that EA generates the correct code for this, is not a simple straightforward task (at least not for C++).
I have an article (tutorial) at hand, that describes the necessary steps for C++ code generation for a number of modeling situations in detail. If you're interested, leave your eMail in my message box, and I will send it to you.

WBR
Günther

tanja

  • EA User
  • **
  • Posts: 71
  • Karma: +0/-0
    • View Profile
Re: Modelling C++ templates??
« Reply #7 on: December 16, 2010, 12:03:31 am »
Could you maybe share what you know with everybody here?

I'm now considering whether I could use the parameterized class construct to simplify an existing model (at the cost of a UML feature not well supported by tools).

I don't need a C++ template or any code generation capability, but I do need the instantiated parameters both displayed on diagrams and available within the model (that I can access with the java API).

I fully agree with Hazzelbanger that the single parameterized class-related page in EA help is really of little help to me. I would never think of using dependency with a stereotype that some mentioned of the forum...