network: Rename Queue methods to allow range based for loops

This commit is contained in:
Stefano Avallone
2019-04-11 16:18:05 +02:00
parent b8130644e8
commit dc074293d5
3 changed files with 85 additions and 39 deletions

View File

@@ -52,8 +52,8 @@ public:
virtual Ptr<const Item> Peek (void) const;
private:
using Queue<Item>::Head;
using Queue<Item>::Tail;
using Queue<Item>::begin;
using Queue<Item>::end;
using Queue<Item>::DoEnqueue;
using Queue<Item>::DoDequeue;
using Queue<Item>::DoRemove;
@@ -99,7 +99,7 @@ DropTailQueue<Item>::Enqueue (Ptr<Item> item)
{
NS_LOG_FUNCTION (this << item);
return DoEnqueue (Tail (), item);
return DoEnqueue (end (), item);
}
template <typename Item>
@@ -108,7 +108,7 @@ DropTailQueue<Item>::Dequeue (void)
{
NS_LOG_FUNCTION (this);
Ptr<Item> item = DoDequeue (Head ());
Ptr<Item> item = DoDequeue (begin ());
NS_LOG_LOGIC ("Popped " << item);
@@ -121,7 +121,7 @@ DropTailQueue<Item>::Remove (void)
{
NS_LOG_FUNCTION (this);
Ptr<Item> item = DoRemove (Head ());
Ptr<Item> item = DoRemove (begin ());
NS_LOG_LOGIC ("Removed " << item);
@@ -134,7 +134,7 @@ DropTailQueue<Item>::Peek (void) const
{
NS_LOG_FUNCTION (this);
return DoPeek (Head ());
return DoPeek (begin ());
}
// The following explicit template instantiation declarations prevent all the

View File

@@ -302,38 +302,72 @@ protected:
/// Const iterator.
typedef typename std::list<Ptr<Item> >::const_iterator ConstIterator;
/// Iterator.
typedef typename std::list<Ptr<Item> >::iterator Iterator;
/**
* \brief Get a const iterator which refers to the first item in the queue.
*
* Subclasses can browse the items in the queue by using an iterator
* Subclasses can browse the items in the queue by using a const iterator
*
* \code
* for (auto i = Head (); i != Tail (); ++i)
* for (auto i = begin (); i != end (); ++i)
* {
* (*i)->method (); // some method of the Item class
* (*i)->method (); // some const method of the Item class
* }
* \endcode
*
* \returns a const iterator which refers to the first item in the queue.
*/
ConstIterator Head (void) const;
ConstIterator begin (void) const;
/**
* \brief Get a const iterator which indicates past-the-last item in the queue.
* \brief Get an iterator which refers to the first item in the queue.
*
* Subclasses can browse the items in the queue by using an iterator
*
* \code
* for (auto i = Head (); i != Tail (); ++i)
* for (auto i = begin (); i != end (); ++i)
* {
* (*i)->method (); // some method of the Item class
* }
* \endcode
*
* \returns an iterator which refers to the first item in the queue.
*/
Iterator begin (void);
/**
* \brief Get a const iterator which indicates past-the-last item in the queue.
*
* Subclasses can browse the items in the queue by using a const iterator
*
* \code
* for (auto i = begin (); i != end (); ++i)
* {
* (*i)->method (); // some const method of the Item class
* }
* \endcode
*
* \returns a const iterator which indicates past-the-last item in the queue.
*/
ConstIterator Tail (void) const;
ConstIterator end (void) const;
/**
* \brief Get an iterator which indicates past-the-last item in the queue.
*
* Subclasses can browse the items in the queue by using an iterator
*
* \code
* for (auto i = begin (); i != end (); ++i)
* {
* (*i)->method (); // some method of the Item class
* }
* \endcode
*
* \returns an iterator which indicates past-the-last item in the queue.
*/
Iterator end (void);
/**
* Push an item in the queue
@@ -559,17 +593,29 @@ Queue<Item>::DoPeek (ConstIterator pos) const
}
template <typename Item>
typename Queue<Item>::ConstIterator Queue<Item>::Head (void) const
typename Queue<Item>::ConstIterator Queue<Item>::begin (void) const
{
return m_packets.cbegin ();
}
template <typename Item>
typename Queue<Item>::ConstIterator Queue<Item>::Tail (void) const
typename Queue<Item>::Iterator Queue<Item>::begin (void)
{
return m_packets.begin ();
}
template <typename Item>
typename Queue<Item>::ConstIterator Queue<Item>::end (void) const
{
return m_packets.cend ();
}
template <typename Item>
typename Queue<Item>::Iterator Queue<Item>::end (void)
{
return m_packets.end ();
}
template <typename Item>
void
Queue<Item>::DropBeforeEnqueue (Ptr<Item> item)

View File

@@ -122,8 +122,8 @@ WifiMacQueue::Enqueue (Ptr<WifiMacQueueItem> item)
// starting from the head of the queue, in order to make room for the new packet.
if (QueueBase::GetNPackets () == GetMaxSize ().GetValue ())
{
auto it = Head ();
while (it != Tail () && !TtlExceeded (it))
ConstIterator it = begin ();
while (it != end () && !TtlExceeded (it))
{
it++;
}
@@ -132,10 +132,10 @@ WifiMacQueue::Enqueue (Ptr<WifiMacQueueItem> item)
if (QueueBase::GetNPackets () == GetMaxSize ().GetValue () && m_dropPolicy == DROP_OLDEST)
{
NS_LOG_DEBUG ("Remove the oldest item in the queue");
DoRemove (Head ());
DoRemove (begin ());
}
return DoEnqueue (Tail (), item);
return DoEnqueue (end (), item);
}
bool
@@ -151,8 +151,8 @@ WifiMacQueue::PushFront (Ptr<WifiMacQueueItem> item)
// starting from the head of the queue, in order to make room for the new packet.
if (QueueBase::GetNPackets () == GetMaxSize ().GetValue ())
{
auto it = Head ();
while (it != Tail () && !TtlExceeded (it))
ConstIterator it = begin ();
while (it != end () && !TtlExceeded (it))
{
it++;
}
@@ -161,17 +161,17 @@ WifiMacQueue::PushFront (Ptr<WifiMacQueueItem> item)
if (QueueBase::GetNPackets () == GetMaxSize ().GetValue () && m_dropPolicy == DROP_OLDEST)
{
NS_LOG_DEBUG ("Remove the oldest item in the queue");
DoRemove (Head ());
DoRemove (begin ());
}
return DoEnqueue (Head (), item);
return DoEnqueue (begin (), item);
}
Ptr<WifiMacQueueItem>
WifiMacQueue::Dequeue (void)
{
NS_LOG_FUNCTION (this);
for (auto it = Head (); it != Tail (); )
for (ConstIterator it = begin (); it != end (); )
{
if (!TtlExceeded (it))
{
@@ -187,7 +187,7 @@ WifiMacQueue::DequeueByAddress (Mac48Address dest)
{
NS_LOG_FUNCTION (this << dest);
for (auto it = Head (); it != Tail (); )
for (ConstIterator it = begin (); it != end (); )
{
if (!TtlExceeded (it))
{
@@ -207,7 +207,7 @@ Ptr<WifiMacQueueItem>
WifiMacQueue::DequeueByTid (uint8_t tid)
{
NS_LOG_FUNCTION (this << +tid);
for (auto it = Head (); it != Tail (); )
for (ConstIterator it = begin (); it != end (); )
{
if (!TtlExceeded (it))
{
@@ -227,7 +227,7 @@ Ptr<WifiMacQueueItem>
WifiMacQueue::DequeueByTidAndAddress (uint8_t tid, Mac48Address dest)
{
NS_LOG_FUNCTION (this << dest);
for (auto it = Head (); it != Tail (); )
for (ConstIterator it = begin (); it != end (); )
{
if (!TtlExceeded (it))
{
@@ -248,7 +248,7 @@ Ptr<WifiMacQueueItem>
WifiMacQueue::DequeueFirstAvailable (const Ptr<QosBlockedDestinations> blockedPackets)
{
NS_LOG_FUNCTION (this);
for (auto it = Head (); it != Tail (); )
for (ConstIterator it = begin (); it != end (); )
{
if (!TtlExceeded (it))
{
@@ -269,7 +269,7 @@ Ptr<const WifiMacQueueItem>
WifiMacQueue::Peek (void) const
{
NS_LOG_FUNCTION (this);
for (auto it = Head (); it != Tail (); it++)
for (auto it = begin (); it != end (); it++)
{
// skip packets that stayed in the queue for too long. They will be
// actually removed from the queue by the next call to a non-const method
@@ -286,7 +286,7 @@ Ptr<const WifiMacQueueItem>
WifiMacQueue::PeekByTid (uint8_t tid)
{
NS_LOG_FUNCTION (this << +tid);
for (auto it = Head (); it != Tail (); )
for (ConstIterator it = begin (); it != end (); )
{
if (!TtlExceeded (it))
{
@@ -306,7 +306,7 @@ Ptr<const WifiMacQueueItem>
WifiMacQueue::PeekByTidAndAddress (uint8_t tid, Mac48Address dest)
{
NS_LOG_FUNCTION (this << dest);
for (auto it = Head (); it != Tail (); )
for (ConstIterator it = begin (); it != end (); )
{
if (!TtlExceeded (it))
{
@@ -327,7 +327,7 @@ Ptr<const WifiMacQueueItem>
WifiMacQueue::PeekFirstAvailable (const Ptr<QosBlockedDestinations> blockedPackets)
{
NS_LOG_FUNCTION (this);
for (auto it = Head (); it != Tail (); )
for (ConstIterator it = begin (); it != end (); )
{
if (!TtlExceeded (it))
{
@@ -349,7 +349,7 @@ WifiMacQueue::Remove (void)
{
NS_LOG_FUNCTION (this);
for (auto it = Head (); it != Tail (); )
for (ConstIterator it = begin (); it != end (); )
{
if (!TtlExceeded (it))
{
@@ -364,7 +364,7 @@ bool
WifiMacQueue::Remove (Ptr<const Packet> packet)
{
NS_LOG_FUNCTION (this << packet);
for (auto it = Head (); it != Tail (); )
for (ConstIterator it = begin (); it != end (); )
{
if (!TtlExceeded (it))
{
@@ -388,7 +388,7 @@ WifiMacQueue::GetNPacketsByAddress (Mac48Address dest)
uint32_t nPackets = 0;
for (auto it = Head (); it != Tail (); )
for (ConstIterator it = begin (); it != end (); )
{
if (!TtlExceeded (it))
{
@@ -409,7 +409,7 @@ WifiMacQueue::GetNPacketsByTidAndAddress (uint8_t tid, Mac48Address dest)
{
NS_LOG_FUNCTION (this << dest);
uint32_t nPackets = 0;
for (auto it = Head (); it != Tail (); )
for (ConstIterator it = begin (); it != end (); )
{
if (!TtlExceeded (it))
{
@@ -430,7 +430,7 @@ bool
WifiMacQueue::IsEmpty (void)
{
NS_LOG_FUNCTION (this);
for (auto it = Head (); it != Tail (); )
for (ConstIterator it = begin (); it != end (); )
{
if (!TtlExceeded (it))
{
@@ -447,7 +447,7 @@ WifiMacQueue::GetNPackets (void)
{
NS_LOG_FUNCTION (this);
// remove packets that stayed in the queue for too long
for (auto it = Head (); it != Tail (); )
for (ConstIterator it = begin (); it != end (); )
{
if (!TtlExceeded (it))
{
@@ -462,7 +462,7 @@ WifiMacQueue::GetNBytes (void)
{
NS_LOG_FUNCTION (this);
// remove packets that stayed in the queue for too long
for (auto it = Head (); it != Tail (); )
for (ConstIterator it = begin (); it != end (); )
{
if (!TtlExceeded (it))
{