Book a Demo

Author Topic: template classes  (Read 6654 times)

mstier

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
template classes
« on: April 14, 2003, 03:49:45 am »
Hi there,

I'm about to model some template classes and inherited classes of bound templates.
Example:
template <class Key, class T> class MyMap;

class ASpecialMap : public MyMap <int, ASpecialClass> {
  void DoSomethingSpecial ();
}

I can't find a way to model that relation. My UML-book suggests to create a "BaseMap" class with a dependency-link with the <<bind>> stereotype and to define the template parameters within the dependency association:
"<<bind>> (int, ASpecialClass)"
Now I can inherit my "ASpecialMap" from "BaseMap" as usual.
Two Problems:
I can't specify the template parameters witin the <<bind>> association.
I don't need a "BaseMap" class- I want to inherit directly as shown above.

Any suggestions?

regards Markus
The future is already there-
it just hasn't been delivered jet.

Barry_Pearce

  • EA User
  • **
  • Posts: 70
  • Karma: +0/-0
    • View Profile
Re: template classes
« Reply #1 on: June 24, 2004, 11:28:33 am »
Yes its still a major problem in 729. We will be chasing EA in the coming days....

This is a major issue when deriving classes from STL (assuming you can get STL in to start with).

dushko

  • EA Novice
  • *
  • Posts: 1
  • Karma: +0/-0
    • View Profile
Re: template classes
« Reply #2 on: September 14, 2004, 05:55:05 am »
I'v got 736. Is it now possible to design template classes?
Acctually I just want documentation for my code done with UML diagrams by EA.
So can you explain me how can I do that. ?
If I specify <<bind>> no attributes nor Operations are imported into my class based on templates.
I did it with <<realize>> .... Select All... nad then changing the type of dependency into <<bind>>. Is this a good way to do it?
But where do I define template parameters anyway?
??? >:(

bcgiMJ

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: template classes
« Reply #3 on: September 20, 2004, 05:54:00 am »
There are a few things I'd like to be able to model with respect to C++ templates, but don't know how one would do so in EA.

Given the following template:

template <class T>
class A {
 public:
   A() {}
};

I'd like to be able to model the following things:

typedef A<B> C;

class C : public A<B> {
 public:
   C() {}
};

template <>
class A<B> {
 public:
   A() {}
};

That is, aliasing an instantiation of A<T>, deriving from an instantiation of A<T> and declaring a specialization of A<T>.

It would also be nice, though I don't know how the UML would support it, to be able to model member template functions, friend functions, and template friend functions.

bcgiMJ

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: template classes
« Reply #4 on: October 01, 2004, 12:10:26 pm »
You can model the relationship in the original question in EA by creating the class MyMap, going to the Detail tab in the Class Properties, selecting Parameterized in the drop-down list in the Templates group box, then adding the parameters Key with type class and T with type class.

Then create class ASpecialMap. go into the Detail tab in Class Properties, select Instantiated from the drop-down in the Templates group box, then type "int,ASpecialClass" in the Arguments text field. Go back to the class diagram and make a generalization link between ASpecialMap and MyMap.

This tells EA that class ASpecialMap is a kind of MyMap that is instantiated with the template arguments "int" and "ASpecialClass" and it will generate code appropriately, but only for the first base class. It doesn't handle derivation from multiple template classes (e.g. template <class T, class U> class C : public A<T>, public  B<U>).

The <<bind>> dependency with arguments would do a better job of this kind of thing. The code generation template framework would have to be augmented to include templates for dependency (ClassDepends) and realization (ClassRealizes) links as well as for generalization links, and use these in the ClassInherits template. These new templates would need access to the link stereotype and other link attributes. Where to specify the template parameters is problematic. Using the dependency name field would be expedient, but perhaps not correct. To me it feels like a constraint.

You can also create partial specializations this way by specifying that the derived class is both parameterized and instantiated.

EA doesn't do specializations, but I was able to model them by adding a "specialization" stereotype (under Configuration, UML, Stereotypes) and then heavily modifying the code generation templates with stereotype overrides. This has the advantage that I can see by looking at the class diagram when something is a <<specialization>>. For <<specialization>> classes, I configure them as Parameterized and give the specific types as the parameter types (the names don't matter).

I was also able to do typedefs by creating a "typedef" stereotype. I create a generalization relationship between the <<typedef>> and the class it aliases. If it is aliasing a template, I can make the <<typedef>> an Instantiation with appropriate arguments. I again modified the code generation templates with stereotype overrides to generate appropriate code for the typedef stereotype.

Still working on how to do member template functions....

sbarkeruk

  • EA User
  • **
  • Posts: 31
  • Karma: +0/-0
    • View Profile
Re: template classes
« Reply #5 on: November 12, 2004, 01:20:48 am »
Don't suppose you have some examples you could post?

Trying to acheive this myself.

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: template classes
« Reply #6 on: November 14, 2004, 08:04:52 pm »
Quote
Still working on how to do member template functions....

Just an idea...

I would think that you could generate them by adding a tagged value with the template specification.  You could potentially combine this with a stereotype, but I can imagine wanting to use templates with some other stereotype.

Simon

gmajoros

  • EA Novice
  • *
  • Posts: 1
  • Karma: +0/-0
    • View Profile
Re: template classes
« Reply #7 on: February 03, 2005, 07:03:42 am »
Hi,

I have some problems when instantiating template classes.
When a class inherits from a template class and a non-template class at the same time, the instantiation at the derived class sets a template parameter for the non-template baseclass too!

Example, required declarations:
 template <class T>
 class A{...}

 class B {...}

 class C: public A<X>, public B

instead of that above, I got the following generated code:
 class C: public A<X>, public B<X>

Class B should not get any parameter here!

The only thing I did was I filled out the Detail tab of the class C and set Templates/Type to "Instantiated" and Templates/Arguments to "X".

Have you ever met with this problem before? How could I solve it?
Thanks, in advance.

Gabor