diff --git a/src/network/utils/drop-tail-queue.h b/src/network/utils/drop-tail-queue.h index adb9c411d..981cd23b8 100644 --- a/src/network/utils/drop-tail-queue.h +++ b/src/network/utils/drop-tail-queue.h @@ -52,8 +52,8 @@ public: virtual Ptr Peek (void) const; private: - using Queue::Head; - using Queue::Tail; + using Queue::begin; + using Queue::end; using Queue::DoEnqueue; using Queue::DoDequeue; using Queue::DoRemove; @@ -99,7 +99,7 @@ DropTailQueue::Enqueue (Ptr item) { NS_LOG_FUNCTION (this << item); - return DoEnqueue (Tail (), item); + return DoEnqueue (end (), item); } template @@ -108,7 +108,7 @@ DropTailQueue::Dequeue (void) { NS_LOG_FUNCTION (this); - Ptr item = DoDequeue (Head ()); + Ptr item = DoDequeue (begin ()); NS_LOG_LOGIC ("Popped " << item); @@ -121,7 +121,7 @@ DropTailQueue::Remove (void) { NS_LOG_FUNCTION (this); - Ptr item = DoRemove (Head ()); + Ptr item = DoRemove (begin ()); NS_LOG_LOGIC ("Removed " << item); @@ -134,7 +134,7 @@ DropTailQueue::Peek (void) const { NS_LOG_FUNCTION (this); - return DoPeek (Head ()); + return DoPeek (begin ()); } // The following explicit template instantiation declarations prevent all the diff --git a/src/network/utils/queue.h b/src/network/utils/queue.h index e8e168ef9..7c0316f34 100644 --- a/src/network/utils/queue.h +++ b/src/network/utils/queue.h @@ -302,38 +302,72 @@ protected: /// Const iterator. typedef typename std::list >::const_iterator ConstIterator; + /// Iterator. + typedef typename std::list >::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::DoPeek (ConstIterator pos) const } template -typename Queue::ConstIterator Queue::Head (void) const +typename Queue::ConstIterator Queue::begin (void) const { return m_packets.cbegin (); } template -typename Queue::ConstIterator Queue::Tail (void) const +typename Queue::Iterator Queue::begin (void) +{ + return m_packets.begin (); +} + +template +typename Queue::ConstIterator Queue::end (void) const { return m_packets.cend (); } +template +typename Queue::Iterator Queue::end (void) +{ + return m_packets.end (); +} + template void Queue::DropBeforeEnqueue (Ptr item) diff --git a/src/wifi/model/wifi-mac-queue.cc b/src/wifi/model/wifi-mac-queue.cc index 07d4ae93e..2f4b89f0c 100644 --- a/src/wifi/model/wifi-mac-queue.cc +++ b/src/wifi/model/wifi-mac-queue.cc @@ -122,8 +122,8 @@ WifiMacQueue::Enqueue (Ptr 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 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 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 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 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 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 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 WifiMacQueue::DequeueFirstAvailable (const Ptr 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 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 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 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 WifiMacQueue::PeekFirstAvailable (const Ptr 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 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)) {