如何将标准容器作为字段添加到 OMNet++ 消息中? [英] How can a standard container be added as a field to an OMNet++ message?

查看:135
本文介绍了如何将标准容器作为字段添加到 OMNet++ 消息中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个简单的消息定义包含使用 std::vector 实现的字段.根据 OMNet++ 5.5 手册 ch.6 秒.8.1,这看起来很简单.

I'm trying to create a simple message definition that contains a field implemented using std::vector. Per the OMNet++ 5.5 manual ch. 6 sec. 8.1, this is seemingly straightforward.

但是,我使用的是 OMNet++ 6.0pre6:我无法弄清楚这样做的正确方法是什么,因为手册已经过时1,并且更改非常肤浅在 nedxml 变更日志中引用.

However, I'm using OMNet++ 6.0pre6: I can't figure out what the correct way of doing this is, as the manual is out of date1, and the changes are very superficially referred to in the nedxml changelog.

消息定义可以归结为中的确切示例手册,但在这种情况下,它是一个 message 而不是 packet(两者都会产生相同的错误):

The message definition can be boiled down to the exact example in the manual, but in this case it is a message rather than a packet (either yields same error):

cplusplus {{
#include <vector>
typedef std::vector<int> IntVector;
}}

class noncobject IntVector;

message SimpleMsg {
    int this_thing;
    int that_thing;
    IntVector these_things;
}

以下错误由 opp_msgtool(消息到 C++ 的转译器)提供:

The following errors were provided by opp_msgtool, the messages-to-C++ transpiler:

SimpleMsg.msg:6: Error: Type declarations are not needed with imports, try invoking the message compiler in legacy (4.x) mode using the --msg4 option
SimpleMsg.msg:11: Error: unknown type 'IntVector' for field 'these_things' in 'SimpleMsg'

认为导入不需要类型声明可能是从 OMNet 5.x 到 6.x 更改的简单总结,我继续删除 class noncobject IntVector.虽然它消除了第一个错误,但它仍然会产生 Error: unknown type 'IntVector' for field 'these_things' in 'SimpleMsg'.

Thinking type declarations are not needed with imports could be the simple summary of the changes from OMNet 5.x to 6.x, I proceeded to remove class noncobject IntVector. While it removes the first error, it still yields Error: unknown type 'IntVector' for field 'these_things' in 'SimpleMsg'.

想法?建议?要吸取的教训?

Ideas? Suggestions? Lessons to be had?

编辑:特别是发现 nedxml 更改日志中有一些注释涉及 4.0-5.x 和 6.0 之间的更改,但如何理想地使用它不太清楚.

EDIT: Notably found that there are some notes in the nedxml changelog referring to changes between 4.0-5.x and 6.0, but how to ideally use it is less clear.

1 至少不能完全适用于 OMNet++ 6.0.

1 Certainly not wholly applicable to OMNet++ 6.0 at the very least.

推荐答案

应该是这样的:

cplusplus {{
#include <vector>
typedef std::vector<int> IntVector;
}}

class IntVector {
    @existingClass;
}

message SimpleMsg {
    int this_thing;
    int that_thing;
    IntVector these_things;
}

另一种解决方案"是强制消息编译器兼容 4.x(旧模式).只需在 makefrag 文件中添加以下行

An alternate 'solution' is to force the message compiler into 4.x compatible (old mode). Just add the following line in a makefrag file

MSGC:=$(MSGC) --msg4

但是,您迟早应该转换您的代码.如果您希望您的代码同时使用 OMNeT++ 5.5 和 6.0 进行编译,那么您绝对应该明确指定 MSG 编译器版本.兼容 4.x 或 6.x.

However, sooner or later you should convert your code. If you want your code to compile with both OMNeT++ 5.5 and 6.0 then you should definitely specify the MSG compiler version explicitly. Either to be 4.x or 6.x compatible.

这篇关于如何将标准容器作为字段添加到 OMNet++ 消息中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆