OMNeT++/OMNEST Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0000525OMNeT++command line toolspublic2012-01-18 17:382012-01-20 15:00
Reportermichael 
Assigned To 
PrioritynormalSeverityminorReproducibilityalways
StatusnewResolutionopen 
PlatformOSOS Version
Product Version4.2 
Target VersionFixed in Version 
Summary0000525: Maybe enumerations handled not correct in .msg files
DescriptionI 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)
}
TagsNo tags attached.
Attached Files

- Relationships

-  Notes
(0000702)
andras (administrator)
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...

- Issue History
Date Modified Username Field Change
2012-01-18 17:38 michael New Issue
2012-01-20 15:00 andras Note Added: 0000702


Copyright © 2000 - 2019 MantisBT Team
Powered by Mantis Bugtracker