Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use the C++ STL in Enterprise Architect

How is it possible to use parts of the C++ STL in Enterprise Architect?
It would be nice to be able to specify certain class attributes as std::string or use std::auto_ptr (or even std::tr1::shared_ptr) as types.

Another interesting thing would be how one is able to integrate container-types like std::vector and std::map into EA.

like image 786
MOnsDaR Avatar asked Apr 14 '11 12:04

MOnsDaR


2 Answers

I have taught how STL containers look like to EA, I guess it can be extended to stl pointers too:

Forward engineering:

You can define collection classes for different multiplicities globally in the language settings, or for a specific class of your project (this will define how it is "contained" in other classes) this way. Simple example setting:

Set all collection classes to std::vector

Make sure you set the container classes for the target class of the association, not the source. Set the Multiplicity of the Target Role to multiple (different from 0, 0..1, 1 and empty field according to the code template). Also, set the Containment of the Target Role of the association to Value to avoid generating a pointer to a container.

Another, more flexible way would be to modify the code templates in Settings -> Code Generation Templates. I believe there is a way to override the default template for stereotyped connectors, though I never tried. This is probably the only way to generate STL pointers, as collection class definitions are only used by EA for multiplicities bigger than 1.

Reverse engineering:

Go to Tools->Options->Source code engineering->C++ and append to 'Additional Collection Classes' the following string:

vector<#TYPE#*>;deque<#TYPE#*>;list<#TYPE#*>;stack<#TYPE#*>;queue<#TYPE#*>;priority_queue<#TYPE#*>;set<#TYPE#*>;map<*,#TYPE#*>;multiset<#TYPE#*>;multimap<*,#TYPE#*>;

I've never tried, but I assume adding the STL pointers to this is trivial.

Round-trip engineering

I don't know if the above works if you do round-trip engineering. I assume the fact that the definitions are asymmetric will cause issues.

like image 107
Gabor Herman Avatar answered Nov 04 '22 18:11

Gabor Herman


I've been toying with this sort of thing and it's doable... just.

What you'd need to do is reverse-engineer the libraries from source, but since EA does not contain a complete preprocessor, you'll end up with a lot of "You may need to define a language macro" errors. Perhaps actually running the source through a preprocessor first would help.

The other way, of course, is to just add the STL classes as you need them.

As for container types, I'm not sure if EA provides any support for constructions like the Allocator in

template < class T, class Allocator = allocator<T> > class vector;

Simple template classes, however, are defined as a Class with Template Parameters. The easiest way to create an instantiation is to create a new Class, go into its Templates tab and add a Binding to the template Class; this allows you to select values for the formal template parameters.

like image 23
Uffe Avatar answered Nov 04 '22 18:11

Uffe