OMNeT++ Simulation Library  5.6.1
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 
78  cPacketQueue& operator=(const cPacketQueue& queue);
80 
83 
89  virtual cPacketQueue *dup() const override {return new cPacketQueue(*this);}
90 
95  virtual std::string str() const override;
96 
102  virtual void parsimPack(cCommBuffer *buffer) const override;
103 
109  virtual void parsimUnpack(cCommBuffer *buffer) override;
111 
119  virtual void insert(cPacket *pkt);
120 
126  virtual void insertBefore(cPacket *where, cPacket *pkt);
127 
134  virtual void insertAfter(cPacket *where, cPacket *pkt);
135 
141  virtual cPacket *remove(cPacket *pkt);
142 
147  virtual cPacket *pop() override;
148 
153  virtual void clear() override;
155 
162  int64_t getBitLength() const {return bitLength;}
163 
168  int64_t getByteLength() const {return (bitLength+7)>>3;}
169 
175  virtual cPacket *front() const override {return (cPacket *)cQueue::front();}
176 
182  virtual cPacket *back() const override {return (cPacket *)cQueue::back();}
183 
189  virtual cPacket *get(int i) const override {return (cPacket *)cQueue::get(i);}
191 };
192 
193 } // namespace omnetpp
194 
195 
196 #endif
197 
virtual cObject * front() const
Root of the OMNeT++ class hierarchy. cObject is a lightweight class without any data members...
Definition: cobject.h:58
virtual cPacketQueue * dup() const override
Definition: cpacketqueue.h:89
virtual cPacket * back() const override
Definition: cpacketqueue.h:182
int64_t getByteLength() const
Definition: cpacketqueue.h:168
A subclass of cMessage to represent packets, frames, datagrams, application messages, and similar data.
Definition: cpacket.h:52
int64_t getBitLength() const
Definition: cpacketqueue.h:162
virtual cObject * get(int i) const
cPacketQueue(const char *name=nullptr, Comparator *cmp=nullptr)
Definition: cpacketqueue.h:57
virtual cObject * back() const
Buffer for the communications layer of parallel simulation.
Definition: ccommbuffer.h:41
Queue class for objects derived from cObject.
Definition: cqueue.h:42
Definition: cabstracthistogram.h:21
virtual cPacket * front() const override
Definition: cpacketqueue.h:175
cPacketQueue(const char *name, CompareFunc cmp)
Definition: cpacketqueue.h:62
Base class for object comparators, used by cQueue for priority queuing.
Definition: cqueue.h:57
A queue class specialized for cPacket objects.
Definition: cpacketqueue.h:33