Use the C++ STL in Enterprise Architect

痞子三分冷 提交于 2019-12-12 08:01:50

问题


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.


回答1:


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:

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.




回答2:


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.



来源:https://stackoverflow.com/questions/5663239/use-the-c-stl-in-enterprise-architect

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!