A Discrete-Event Network Simulator
API
event-id.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2005 INRIA
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  */
20 #ifndef EVENT_ID_H
21 #define EVENT_ID_H
22 
23 #include <stdint.h>
24 #include "ptr.h"
25 #include "event-impl.h"
26 
33 namespace ns3 {
34 
35 class EventImpl;
36 
53 class EventId
54 {
55 public:
56 
58  enum UID
59  {
61  INVALID = 0,
63  NOW = 1,
65  DESTROY = 2,
67  RESERVED = 3,
69  VALID = 4
70  };
71 
73  EventId ();
82  EventId (const Ptr<EventImpl> &impl, uint64_t ts, uint32_t context, uint32_t uid);
87  void Cancel (void);
92  void Remove (void);
98  bool IsExpired (void) const;
104  bool IsRunning (void) const;
105 
106 public:
114  EventImpl * PeekEventImpl (void) const;
116  uint64_t GetTs (void) const;
118  uint32_t GetContext (void) const;
120  uint32_t GetUid (void) const;
129  friend bool operator == (const EventId &a, const EventId &b);
136  friend bool operator != (const EventId &a, const EventId &b);
143  friend bool operator < (const EventId &a, const EventId &b);
144 
145 private:
147  uint64_t m_ts;
148  uint32_t m_context;
149  uint32_t m_uid;
150 };
151 
152 /*************************************************
153  ** Inline implementations
154  ************************************************/
155 
156 inline
157 bool
158 operator == (const EventId &a, const EventId &b)
159 {
160  return
161  a.m_uid == b.m_uid
162  && a.m_context == b.m_context
163  && a.m_ts == b.m_ts
164  && a.m_eventImpl == b.m_eventImpl;
165 }
166 
167 inline
168 bool
169 operator != (const EventId &a, const EventId &b)
170 {
171  return !(a == b);
172 }
173 
174 inline
175 bool
176 operator < (const EventId &a, const EventId &b)
177 {
178  return (a.GetTs () < b.GetTs ());
179 }
180 
181 } // namespace ns3
182 
183 #endif /* EVENT_ID_H */
An identifier for simulation events.
Definition: event-id.h:54
UID
Special values of the event UID.
Definition: event-id.h:59
@ INVALID
Invalid UID value.
Definition: event-id.h:61
@ RESERVED
Reserved UID.
Definition: event-id.h:67
@ VALID
Schedule(), etc.
Definition: event-id.h:69
@ DESTROY
ScheduleDestroy() events.
Definition: event-id.h:65
@ NOW
ScheduleNow() events.
Definition: event-id.h:63
friend bool operator!=(const EventId &a, const EventId &b)
Test if two EventId's are not equal.
Definition: event-id.h:169
friend bool operator<(const EventId &a, const EventId &b)
Less than operator for two EventId's, based on time stamps.
Definition: event-id.h:176
uint32_t GetContext(void) const
Definition: event-id.cc:89
friend bool operator==(const EventId &a, const EventId &b)
Test if two EventId's are equal.
Definition: event-id.h:158
uint64_t m_ts
The virtual time stamp.
Definition: event-id.h:147
uint32_t m_uid
The unique id.
Definition: event-id.h:149
bool IsRunning(void) const
This method is syntactic sugar for !IsExpired().
Definition: event-id.cc:71
EventImpl * PeekEventImpl(void) const
Definition: event-id.cc:77
void Cancel(void)
This method is syntactic sugar for the ns3::Simulator::Cancel method.
Definition: event-id.cc:53
uint32_t GetUid(void) const
Definition: event-id.cc:95
void Remove(void)
This method is syntactic sugar for the ns3::Simulator::Remove method.
Definition: event-id.cc:59
bool IsExpired(void) const
This method is syntactic sugar for the ns3::Simulator::IsExpired method.
Definition: event-id.cc:65
uint64_t GetTs(void) const
Definition: event-id.cc:83
EventId()
Default constructor.
Definition: event-id.cc:35
uint32_t m_context
The context.
Definition: event-id.h:148
Ptr< EventImpl > m_eventImpl
The underlying event implementation.
Definition: event-id.h:146
A simulation event.
Definition: event-impl.h:45
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
ns3::EventImpl declarations.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
bool operator==(const EventId &a, const EventId &b)
Definition: event-id.h:158
bool operator<(const EventId &a, const EventId &b)
Definition: event-id.h:176
bool operator!=(Callback< R, T1, T2, T3, T4, T5, T6, T7, T8, T9 > a, Callback< R, T1, T2, T3, T4, T5, T6, T7, T8, T9 > b)
Inequality test.
Definition: callback.h:1612
ns3::Ptr smart pointer declaration and implementation.