如何将标准容器作为字段添加到 OMNet++ 消息中?

How can a standard container be added as a field to an OMNet++ message?

我正在尝试创建一个简单的 message definition,其中包含一个使用 std::vector 实现的字段。 根据 OMNet++ 5.5 manual ch. 6 sec. 8.1,这看起来很简单。

但是,我使用的是 OMNet++ 6.0pre6:我不知道正确的做法是什么,因为手册已经过时了1,并且nedxml 更新日志中非常肤浅地提到了这些更改。

消息定义可以归结为 the exact example in the manual,但在本例中它是 message 而不是 packet(两者都会产生相同的错误):

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

class noncobject IntVector;

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

消息到 C++ 转译器 opp_msgtool 提供了以下错误:

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'.

想法?建议?有哪些教训?

编辑:值得注意的是 there are some notes in the nedxml changelog referring to changes between 4.0-5.x and 6.0,但如何理想地使用它还不太清楚。


1当然至少不能完全适用于OMNet++ 6.0。

应该是这样的:

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

class IntVector {
    @existingClass;
}

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

另一种方法 'solution' 是强制消息编译器进入 4.x 兼容(旧模式)。只需在 makefrag 文件中添加以下行

MSGC:=$(MSGC) --msg4

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