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

℡╲_俬逩灬. 提交于 2020-12-15 03:43:33

问题


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.

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.

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;
}

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'

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?

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 Certainly not wholly applicable to OMNet++ 6.0 at the very least.


回答1:


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). Just add the following line in a makefrag file

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. Either to be 4.x or 6.x compatible.



来源:https://stackoverflow.com/questions/59786184/how-can-a-standard-container-be-added-as-a-field-to-an-omnet-message

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