OMNeT++/OMNEST Bug Tracker - OMNeT++
View Issue Details
0000525OMNeT++command line toolspublic2012-01-18 17:382012-01-20 15:00
michael 
 
normalminoralways
newopen 
4.2 
 
0000525: Maybe enumerations handled not correct in .msg files
I think the enumerations in message files will not be handled correctly. Here an example of the .msg file:

enum SenseMode {
    UNTIL_IDLE = 1; //sense until channel is busy or timeout is reached
    UNTIL_BUSY = 2; //sense until channel is idle or timeout is reached
    UNTIL_TIMEOUT = 3; //sense until timeout is reached
};
    
packet ChannelSenseRequest
{
    int senseMode enum(SenseMode); // defines the sensing mode (see SenseMode enum)

}

will generate following header file (shortened):

enum SenseMode {
    UNTIL_IDLE = 1,
    UNTIL_BUSY = 2,
    UNTIL_TIMEOUT = 3
};

class ChannelSenseRequest : public ::cPacket
{
  protected:
    int senseMode_var;

  private:
    void copy(const ChannelSenseRequest& other);

  protected:
    // protected and unimplemented operator==(), to prevent accidental usage
    bool operator==(const ChannelSenseRequest&);

  public:
    ChannelSenseRequest(const char *name=NULL, int kind=0);
    ChannelSenseRequest(const ChannelSenseRequest& other);
    virtual ~ChannelSenseRequest();
    ChannelSenseRequest& operator=(const ChannelSenseRequest& other);
    virtual ChannelSenseRequest *dup() const {return new ChannelSenseRequest(*this);}
    virtual void parsimPack(cCommBuffer *b);
    virtual void parsimUnpack(cCommBuffer *b);

    // field getter/setter methods
    virtual int getSenseMode() const;
    virtual void setSenseMode(int senseMode);
};

I would expecting:

class ChannelSenseRequest : public ::cPacket
{
  protected:
    SenseMode senseMode_var;

  private:
    void copy(const ChannelSenseRequest& other);

  protected:
    // protected and unimplemented operator==(), to prevent accidental usage
    bool operator==(const ChannelSenseRequest&);

  public:
    ChannelSenseRequest(const char *name=NULL, int kind=0);
    ChannelSenseRequest(const ChannelSenseRequest& other);
    virtual ~ChannelSenseRequest();
    ChannelSenseRequest& operator=(const ChannelSenseRequest& other);
    virtual ChannelSenseRequest *dup() const {return new ChannelSenseRequest(*this);}
    virtual void parsimPack(cCommBuffer *b);
    virtual void parsimUnpack(cCommBuffer *b);

    // field getter/setter methods
    virtual SenseMode getSenseMode() const;
    virtual void setSenseMode(SenseMode senseMode);
};

Instead of using int you should use the enum type, which allows also the compiler to do more checks ;). Maybe that this also needs some syntax changes in the .msg file, for instance following would be more intuitive:

packet ChannelSenseRequest
{
    enum(SenseMode) senseMode; // defines the sensing mode (see SenseMode enum)
}
No tags attached.
Issue History
2012-01-18 17:38michaelNew Issue
2012-01-20 15:00andrasNote Added: 0000702

Notes
(0000702)
andras   
2012-01-20 15:00   
Looks OK. One thing to consider is that the message file syntax allows an enum to be extended, i.e. new values to be added (enum B extends A {}). As C++ enums cannot be extended that way, using the enum name as parameter/return value instead of "int" may cause compile errors. If it really does, or whether extending enums is a useful feature, needs to be checked...