使用 C++企业架构师中的STL

发布于 2024-11-01 03:00:22 字数 216 浏览 5 评论 0原文

如何在 Enterprise Architect 中使用部分 C++ STL?
如果能够将某些类属性指定为 std::string 或使用 std::auto_ptr (甚至 std::tr1::shared_ptr ) 作为类型。

另一件有趣的事情是如何将诸如 std::vectorstd::map 之类的容器类型集成到 EA 中。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

空‖城人不在 2024-11-08 03:00:22

我已经教过 STL 容器对于 EA 来说是怎样的,我想它也可以扩展到 stl 指针:

正向工程:

您可以在语言设置中为全局不同的多重性定义集合类,或者为特定的集合类定义集合类。项目的类(这将定义它如何“包含”在其他类中) 这边
简单示例设置:

将所有集合类设置为 std::vector

确保为目标设置容器类 关联的类,而不是源。将目标角色多重性设置为多个(根据代码模板,与0、0..1、1和空字段不同)。另外,将关联的目标角色包含设置为以避免生成指向容器的指针。

另一种更灵活的方法是修改“设置”->“设置”中的代码模板。代码生成模板。我相信有一种方法可以覆盖构造型连接器的默认模板,尽管我从未尝试过。这可能是生成 STL 指针的唯一方法,因为 EA 仅将集合类定义用于大于 1 的重数。

逆向工程

转到工具 -> 选项 -> 源代码工程 - >C++ 并将以下字符串附加到“附加集合类”:

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

我从未尝试过,但我认为向此添加 STL 指针是微不足道的。

往返工程

如果你做往返工程,我不知道上面的方法是否有效。我认为定义不对称这一事实会引起问题。

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.

娇妻 2024-11-08 03:00:22

我一直在玩弄这种事情,这是可行的……只是。

您需要做的是从源代码对库进行逆向工程,但由于 EA 不包含完整的预处理器,因此您最终会遇到很多“您可能需要定义语言宏”错误。也许首先通过预处理器实际运行源代码会有所帮助。

当然,另一种方法是根据需要添加 STL 类。

至于容器类型,我不确定 EA 是否提供对

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

简单模板类中的分配器之类的构造的支持,但是,它们被定义为具有模板参数的类。创建实例化的最简单方法是创建一个新类,进入其模板选项卡并向模板类添加绑定;这允许您选择正式模板参数的值。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文