A Discrete-Event Network Simulator
API
list-scheduler.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2005 INRIA
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18  */
19 
20 #include "list-scheduler.h"
21 
22 #include "assert.h"
23 #include "event-impl.h"
24 #include "log.h"
25 
26 #include <string>
27 #include <utility>
28 
35 namespace ns3
36 {
37 
38 NS_LOG_COMPONENT_DEFINE("ListScheduler");
39 
40 NS_OBJECT_ENSURE_REGISTERED(ListScheduler);
41 
42 TypeId
44 {
45  static TypeId tid = TypeId("ns3::ListScheduler")
47  .SetGroupName("Core")
48  .AddConstructor<ListScheduler>();
49  return tid;
50 }
51 
53 {
54  NS_LOG_FUNCTION(this);
55 }
56 
58 {
59 }
60 
61 void
63 {
64  NS_LOG_FUNCTION(this << &ev);
65  for (auto i = m_events.begin(); i != m_events.end(); i++)
66  {
67  if (ev.key < i->key)
68  {
69  m_events.insert(i, ev);
70  return;
71  }
72  }
73  m_events.push_back(ev);
74 }
75 
76 bool
78 {
79  NS_LOG_FUNCTION(this);
80  return m_events.empty();
81 }
82 
85 {
86  NS_LOG_FUNCTION(this);
87  return m_events.front();
88 }
89 
92 {
93  NS_LOG_FUNCTION(this);
94  Event next = m_events.front();
95  m_events.pop_front();
96  return next;
97 }
98 
99 void
101 {
102  NS_LOG_FUNCTION(this << &ev);
103  for (auto i = m_events.begin(); i != m_events.end(); i++)
104  {
105  if (i->key.m_uid == ev.key.m_uid)
106  {
107  NS_ASSERT(ev.impl == i->impl);
108  m_events.erase(i);
109  return;
110  }
111  }
112  NS_ASSERT(false);
113 }
114 
115 } // namespace ns3
NS_ASSERT() and NS_ASSERT_MSG() macro definitions.
a std::list event scheduler
~ListScheduler() override
Destructor.
ListScheduler()
Constructor.
Events m_events
The event list.
Scheduler::Event RemoveNext() override
Remove the earliest event from the event list.
void Remove(const Scheduler::Event &ev) override
Remove a specific event from the event list.
bool IsEmpty() const override
Test if the schedule is empty.
Scheduler::Event PeekNext() const override
Get a pointer to the next event.
void Insert(const Scheduler::Event &ev) override
Insert a new Event in the schedule.
static TypeId GetTypeId()
Register this type.
Maintain the event list.
Definition: scheduler.h:157
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:931
ns3::EventImpl declarations.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
ns3::ListScheduler declaration.
Debug message logging.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Scheduler event.
Definition: scheduler.h:184
EventKey key
Key for sorting and ordering Events.
Definition: scheduler.h:186
EventImpl * impl
Pointer to the event implementation.
Definition: scheduler.h:185
uint32_t m_uid
Event unique id.
Definition: scheduler.h:172