From acba76fba1cc8a7b0ad4b0fc9c8c4e50306aacc4 Mon Sep 17 00:00:00 2001 From: "Peter D. Barnes, Jr." Date: Sun, 17 Sep 2017 21:31:33 -0700 Subject: [PATCH] [core] Implement operator< (EventId,EventId) --- src/core/model/event-id.cc | 14 ------------- src/core/model/event-id.h | 41 ++++++++++++++++++++++++++++++++++---- 2 files changed, 37 insertions(+), 18 deletions(-) diff --git a/src/core/model/event-id.cc b/src/core/model/event-id.cc index 120efb530..a90ceef22 100644 --- a/src/core/model/event-id.cc +++ b/src/core/model/event-id.cc @@ -92,19 +92,5 @@ EventId::GetUid (void) const return m_uid; } -bool operator == (const EventId &a, const EventId &b) -{ - return - a.m_uid == b.m_uid && - a.m_context == b.m_context && - a.m_ts == b.m_ts && - a.m_eventImpl == b.m_eventImpl; -} -bool operator != (const EventId &a, const EventId &b) -{ - return !(a == b); -} - - } // namespace ns3 diff --git a/src/core/model/event-id.h b/src/core/model/event-id.h index 816f9ecaf..61185bdb7 100644 --- a/src/core/model/event-id.h +++ b/src/core/model/event-id.h @@ -97,7 +97,6 @@ public: uint32_t GetUid (void) const; /**@}*/ -private: /** * Test if two EventId's are equal. * \param [in] a The first EventId. @@ -112,15 +111,49 @@ private: * \return \c true if the \p a and \p b are not the same event. */ friend bool operator != (const EventId &a, const EventId &b); - + /** + * Less than operator for two EventId's, based on time stamps. + * \param [in] a The first EventId. + * \param [in] b The second EventId. + * \return \c true if \p a occurs before \p b. + */ + friend bool operator < (const EventId &a, const EventId &b); + +private: Ptr m_eventImpl; /**< The underlying event implementation. */ uint64_t m_ts; /**< The virtual time stamp. */ uint32_t m_context; /**< The context. */ uint32_t m_uid; /**< The unique id. */ }; -bool operator == (const EventId &a, const EventId &b); -bool operator != (const EventId &a, const EventId &b); +/************************************************* + ** Inline implementations + ************************************************/ + +inline +bool +operator == (const EventId &a, const EventId &b) +{ + return + a.m_uid == b.m_uid && + a.m_context == b.m_context && + a.m_ts == b.m_ts && + a.m_eventImpl == b.m_eventImpl; +} + +inline +bool +operator != (const EventId &a, const EventId &b) +{ + return !(a == b); +} + +inline +bool +operator < (const EventId &a, const EventId &b) +{ + return (a.GetTs () < b.GetTs ()); +} } // namespace ns3