简体   繁体   English

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

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

I'm trying to create a simple message definition that contains a field implemented using std::vector .我正在尝试创建一个简单的消息定义,其中包含使用std::vector实现的字段。 Per the OMNet++ 5.5 manual ch.根据OMNet++ 5.5 手册 ch。6 sec.6 秒。8.1 , this is seemingly straightforward.8.1 ,这看似简单。

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 date 1 , and the changes are very superficially referred to in the nedxml changelog.但是,我使用的是 OMNet++ 6.0pre6:我不知道这样做的正确方法是什么,因为手册已经过时1 ,并且在nedxml更改日志中非常肤浅地提到了nedxml更改。

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

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

class noncobject IntVector;

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

The following errors were provided by opp_msgtool , the messages-to-C++ transpiler:以下错误由opp_msgtool提供,消息到 C++ 转译器:

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'

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 .认为导入不需要类型声明可能是从 OMNet 5.x 到 6.x 更改的简单总结,我继续删除class noncobject IntVector While it removes the first error, it still yields Error: unknown type 'IntVector' for field 'these_things' in 'SimpleMsg' .虽然它删除了第一个错误,但它仍然会产生Error: unknown type 'IntVector' for field 'these_things' in 'SimpleMsg'

Ideas?想法? Suggestions?建议? Lessons to be had?要吸取的教训?

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.编辑:值得注意的是, nedxml更改日志有一些注释涉及 4.0-5.x 和 6.0 之间的更改,但如何理想地使用它不太清楚。


1 Certainly not wholly applicable to OMNet++ 6.0 at the very least. 1当然至少不完全适用于 OMNet++ 6.0。

It should be something like this:它应该是这样的:

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

class IntVector {
    @existingClass;
}

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

An alternate 'solution' is to force the message compiler into 4.x compatible (old mode).另一种“解决方案”是强制消息编译器进入 4.x 兼容(旧模式)。 Just add the following line in a makefrag file只需在 makefrag 文件中添加以下行

MSGC:=$(MSGC) --msg4

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.如果您希望您的代码同时使用 OMNeT++ 5.5 和 6.0 进行编译,那么您绝对应该明确指定 MSG 编译器版本。 Either to be 4.x or 6.x compatible.兼容 4.x 或 6.x。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM