OMNeT++ Simulation Library  6.0.3
cpacketqueue.h
1 //==========================================================================
2 // CPACKETQUEUE.H - part of
3 // OMNeT++/OMNEST
4 // Discrete System Simulation in C++
5 //
6 //==========================================================================
7 
8 /*--------------------------------------------------------------*
9  Copyright (C) 1992-2017 Andras Varga
10  Copyright (C) 2006-2017 OpenSim Ltd.
11 
12  This file is distributed WITHOUT ANY WARRANTY. See the file
13  `license' for details on this and other legal matters.
14 *--------------------------------------------------------------*/
15 
16 #ifndef __OMNETPP_CPACKETQUEUE_H
17 #define __OMNETPP_CPACKETQUEUE_H
18 
19 #include "cqueue.h"
20 #include "cpacket.h"
21 
22 namespace omnetpp {
23 
24 
33 class SIM_API cPacketQueue : public cQueue
34 {
35  private:
36  int64_t bitLength=0;
37 
38  private:
39  void copy(const cPacketQueue& other);
40  virtual void insert(cObject *obj) override;
41  virtual void insertBefore(cObject *where, cObject *obj) override;
42  virtual void insertAfter(cObject *where, cObject *obj) override;
43  virtual cObject *remove(cObject *obj) override;
44 
45  protected:
46  // internal
47  void addLength(cPacket *pkt);
48  cPacket *checkPacket(cObject *obj);
49 
50  public:
57  cPacketQueue(const char *name=nullptr, Comparator *cmp=nullptr) : cQueue(name, cmp) {}
58 
62  cPacketQueue(const char *name, CompareFunc cmp) : cQueue(name, cmp) {}
63 
69  cPacketQueue(const cPacketQueue& queue);
70 
77  cPacketQueue& operator=(const cPacketQueue& queue);
79 
82 
88  virtual cPacketQueue *dup() const override {return new cPacketQueue(*this);}
89 
94  virtual std::string str() const override;
95 
101  virtual void parsimPack(cCommBuffer *buffer) const override;
102 
108  virtual void parsimUnpack(cCommBuffer *buffer) override;
110 
118  virtual void insert(cPacket *pkt);
119 
125  virtual void insertBefore(cPacket *where, cPacket *pkt);
126 
133  virtual void insertAfter(cPacket *where, cPacket *pkt);
134 
140  virtual cPacket *remove(cPacket *pkt);
141 
146  virtual cPacket *pop() override;
147 
152  virtual void clear() override;
154 
161  int64_t getBitLength() const {return bitLength;}
162 
167  int64_t getByteLength() const {return (bitLength+7)>>3;}
168 
174  virtual cPacket *front() const override {return (cPacket *)cQueue::front();}
175 
181  virtual cPacket *back() const override {return (cPacket *)cQueue::back();}
182 
188  virtual cPacket *get(int i) const override {return (cPacket *)cQueue::get(i);}
190 };
191 
192 } // namespace omnetpp
193 
194 
195 #endif
196 
omnetpp::cObject
cObject is a lightweight class which serves as the root of the OMNeT++ class hierarchy....
Definition: cobject.h:92
omnetpp::cQueue::front
virtual cObject * front() const
omnetpp::cPacketQueue::front
virtual cPacket * front() const override
Definition: cpacketqueue.h:174
omnetpp::cPacketQueue::get
virtual cPacket * get(int i) const override
Definition: cpacketqueue.h:188
omnetpp::cQueue::back
virtual cObject * back() const
omnetpp::cQueue::Comparator
Base class for object comparators, used by cQueue for priority queuing.
Definition: cqueue.h:57
omnetpp::cPacketQueue::cPacketQueue
cPacketQueue(const char *name=nullptr, Comparator *cmp=nullptr)
Definition: cpacketqueue.h:57
omnetpp::cPacketQueue
A queue class specialized for cPacket objects.
Definition: cpacketqueue.h:33
omnetpp::cPacketQueue::back
virtual cPacket * back() const override
Definition: cpacketqueue.h:181
omnetpp::cPacketQueue::getByteLength
int64_t getByteLength() const
Definition: cpacketqueue.h:167
omnetpp::cPacket
A subclass of cMessage to represent packets, frames, datagrams, application messages,...
Definition: cpacket.h:52
omnetpp::cQueue
Queue class for objects derived from cObject.
Definition: cqueue.h:42
omnetpp::cPacketQueue::cPacketQueue
cPacketQueue(const char *name, CompareFunc cmp)
Definition: cpacketqueue.h:62
omnetpp::cPacketQueue::getBitLength
int64_t getBitLength() const
Definition: cpacketqueue.h:161
omnetpp::cCommBuffer
Buffer for the communications layer of parallel simulation.
Definition: ccommbuffer.h:41
omnetpp::cQueue::get
virtual cObject * get(int i) const
omnetpp::cPacketQueue::dup
virtual cPacketQueue * dup() const override
Definition: cpacketqueue.h:88