A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
list-scheduler.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2005 INRIA
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
7 */
8
9#include "list-scheduler.h"
10
11#include "assert.h"
12#include "log.h"
13
14#include <string>
15
16/**
17 * @file
18 * @ingroup scheduler
19 * ns3::ListScheduler implementation.
20 */
21
22namespace ns3
23{
24
25NS_LOG_COMPONENT_DEFINE("ListScheduler");
26
28
31{
32 static TypeId tid = TypeId("ns3::ListScheduler")
34 .SetGroupName("Core")
35 .AddConstructor<ListScheduler>();
36 return tid;
37}
38
43
47
48void
50{
51 NS_LOG_FUNCTION(this << &ev);
52 for (auto i = m_events.begin(); i != m_events.end(); i++)
53 {
54 if (ev.key < i->key)
55 {
56 m_events.insert(i, ev);
57 return;
58 }
59 }
60 m_events.push_back(ev);
61}
62
63bool
65{
66 NS_LOG_FUNCTION(this);
67 return m_events.empty();
68}
69
72{
73 NS_LOG_FUNCTION(this);
74 return m_events.front();
75}
76
79{
80 NS_LOG_FUNCTION(this);
81 Event next = m_events.front();
82 m_events.pop_front();
83 return next;
84}
85
86void
88{
89 NS_LOG_FUNCTION(this << &ev);
90 for (auto i = m_events.begin(); i != m_events.end(); i++)
91 {
92 if (i->key.m_uid == ev.key.m_uid)
93 {
94 NS_ASSERT(ev.impl == i->impl);
95 m_events.erase(i);
96 return;
97 }
98 }
99 NS_ASSERT(false);
100}
101
102} // 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:146
a unique identifier for an interface.
Definition type-id.h:49
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:999
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:194
#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:35
ns3::ListScheduler declaration.
Debug message logging.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Scheduler event.
Definition scheduler.h:173
EventKey key
Key for sorting and ordering Events.
Definition scheduler.h:175
EventImpl * impl
Pointer to the event implementation.
Definition scheduler.h:174
uint32_t m_uid
Event unique id.
Definition scheduler.h:161