network: Add a Remove method to the Queue base class
This commit is contained in:
@@ -72,6 +72,20 @@ DropTailQueue::DoDequeue (void)
|
||||
return item;
|
||||
}
|
||||
|
||||
Ptr<QueueItem>
|
||||
DropTailQueue::DoRemove (void)
|
||||
{
|
||||
NS_LOG_FUNCTION (this);
|
||||
NS_ASSERT (m_packets.size () == GetNPackets ());
|
||||
|
||||
Ptr<QueueItem> item = m_packets.front ();
|
||||
m_packets.pop ();
|
||||
|
||||
NS_LOG_LOGIC ("Removed " << item);
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
Ptr<const QueueItem>
|
||||
DropTailQueue::DoPeek (void) const
|
||||
{
|
||||
|
||||
@@ -49,6 +49,7 @@ public:
|
||||
private:
|
||||
virtual bool DoEnqueue (Ptr<QueueItem> item);
|
||||
virtual Ptr<QueueItem> DoDequeue (void);
|
||||
virtual Ptr<QueueItem> DoRemove (void);
|
||||
virtual Ptr<const QueueItem> DoPeek (void) const;
|
||||
|
||||
std::queue<Ptr<QueueItem> > m_packets; //!< the items in the queue
|
||||
|
||||
@@ -158,6 +158,32 @@ Queue::Dequeue (void)
|
||||
return item;
|
||||
}
|
||||
|
||||
Ptr<QueueItem>
|
||||
Queue::Remove (void)
|
||||
{
|
||||
NS_LOG_FUNCTION (this);
|
||||
|
||||
if (m_nPackets.Get () == 0)
|
||||
{
|
||||
NS_LOG_LOGIC ("Queue empty");
|
||||
return 0;
|
||||
}
|
||||
|
||||
Ptr<QueueItem> item = DoRemove ();
|
||||
|
||||
if (item != 0)
|
||||
{
|
||||
NS_ASSERT (m_nBytes.Get () >= item->GetPacketSize ());
|
||||
NS_ASSERT (m_nPackets.Get () > 0);
|
||||
|
||||
m_nBytes -= item->GetPacketSize ();
|
||||
m_nPackets--;
|
||||
|
||||
Drop (item);
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
void
|
||||
Queue::DequeueAll (void)
|
||||
{
|
||||
|
||||
@@ -64,10 +64,15 @@ public:
|
||||
*/
|
||||
bool Enqueue (Ptr<QueueItem> item);
|
||||
/**
|
||||
* Remove an item from the front of the Queue
|
||||
* Remove an item from the front of the Queue, counting it as dequeued
|
||||
* \return 0 if the operation was not successful; the item otherwise.
|
||||
*/
|
||||
Ptr<QueueItem> Dequeue (void);
|
||||
/**
|
||||
* Remove an item from the front of the Queue, counting it as dropped
|
||||
* \return 0 if the operation was not successful; the item otherwise.
|
||||
*/
|
||||
Ptr<QueueItem> Remove (void);
|
||||
/**
|
||||
* Get a copy of the item at the front of the queue without removing it
|
||||
* \return 0 if the operation was not successful; the item otherwise.
|
||||
@@ -221,10 +226,15 @@ private:
|
||||
*/
|
||||
virtual bool DoEnqueue (Ptr<QueueItem> item) = 0;
|
||||
/**
|
||||
* Pull an item from the queue
|
||||
* Pull the item to dequeue from the queue
|
||||
* \return the item.
|
||||
*/
|
||||
virtual Ptr<QueueItem> DoDequeue (void) = 0;
|
||||
/**
|
||||
* Pull the item to drop from the queue
|
||||
* \return the item.
|
||||
*/
|
||||
virtual Ptr<QueueItem> DoRemove (void) = 0;
|
||||
/**
|
||||
* Peek the front item in the queue
|
||||
* \return the item.
|
||||
|
||||
Reference in New Issue
Block a user