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 "event-impl.h"
13#include "log.h"
14
15#include <string>
16#include <utility>
17
18/**
19 * \file
20 * \ingroup scheduler
21 * ns3::ListScheduler implementation.
22 */
23
24namespace ns3
25{
26
27NS_LOG_COMPONENT_DEFINE("ListScheduler");
28
29NS_OBJECT_ENSURE_REGISTERED(ListScheduler);
30
31TypeId
33{
34 static TypeId tid = TypeId("ns3::ListScheduler")
36 .SetGroupName("Core")
37 .AddConstructor<ListScheduler>();
38 return tid;
39}
40
45
49
50void
52{
53 NS_LOG_FUNCTION(this << &ev);
54 for (auto i = m_events.begin(); i != m_events.end(); i++)
55 {
56 if (ev.key < i->key)
57 {
58 m_events.insert(i, ev);
59 return;
60 }
61 }
62 m_events.push_back(ev);
63}
64
65bool
67{
68 NS_LOG_FUNCTION(this);
69 return m_events.empty();
70}
71
74{
75 NS_LOG_FUNCTION(this);
76 return m_events.front();
77}
78
81{
82 NS_LOG_FUNCTION(this);
83 Event next = m_events.front();
84 m_events.pop_front();
85 return next;
86}
87
88void
90{
91 NS_LOG_FUNCTION(this << &ev);
92 for (auto i = m_events.begin(); i != m_events.end(); i++)
93 {
94 if (i->key.m_uid == ev.key.m_uid)
95 {
96 NS_ASSERT(ev.impl == i->impl);
97 m_events.erase(i);
98 return;
99 }
100 }
101 NS_ASSERT(false);
102}
103
104} // 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:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
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:55
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#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