A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
map-scheduler.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2006 INRIA
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
7 * The idea to use a std c++ map came from GTNetS
8 */
9
10#include "map-scheduler.h"
11
12#include "assert.h"
13#include "event-impl.h"
14#include "log.h"
15
16#include <string>
17
18/**
19 * \file
20 * \ingroup scheduler
21 * ns3::MapScheduler implementation.
22 */
23
24namespace ns3
25{
26
27NS_LOG_COMPONENT_DEFINE("MapScheduler");
28
29NS_OBJECT_ENSURE_REGISTERED(MapScheduler);
30
31TypeId
33{
34 static TypeId tid = TypeId("ns3::MapScheduler")
36 .SetGroupName("Core")
37 .AddConstructor<MapScheduler>();
38 return tid;
39}
40
45
50
51void
53{
54 NS_LOG_FUNCTION(this << ev.impl << ev.key.m_ts << ev.key.m_uid);
55 std::pair<EventMapI, bool> result;
56 result = m_list.insert(std::make_pair(ev.key, ev.impl));
57 NS_ASSERT(result.second);
58}
59
60bool
62{
63 NS_LOG_FUNCTION(this);
64 return m_list.empty();
65}
66
69{
70 NS_LOG_FUNCTION(this);
71 auto i = m_list.begin();
72 NS_ASSERT(i != m_list.end());
73
74 Event ev;
75 ev.impl = i->second;
76 ev.key = i->first;
77 NS_LOG_DEBUG(this << ": " << ev.impl << ", " << ev.key.m_ts << ", " << ev.key.m_uid);
78 return ev;
79}
80
83{
84 NS_LOG_FUNCTION(this);
85 auto i = m_list.begin();
86 NS_ASSERT(i != m_list.end());
87 Event ev;
88 ev.impl = i->second;
89 ev.key = i->first;
90 m_list.erase(i);
91 NS_LOG_DEBUG("@" << this << ": " << ev.impl << ", " << ev.key.m_ts << ", " << ev.key.m_uid);
92 return ev;
93}
94
95void
97{
98 NS_LOG_FUNCTION(this << ev.impl << ev.key.m_ts << ev.key.m_uid);
99 auto i = m_list.find(ev.key);
100 NS_ASSERT(i->second == ev.impl);
101 m_list.erase(i);
102}
103
104} // namespace ns3
NS_ASSERT() and NS_ASSERT_MSG() macro definitions.
a std::map event scheduler
void Remove(const Scheduler::Event &ev) override
Remove a specific event from the event list.
MapScheduler()
Constructor.
void Insert(const Scheduler::Event &ev) override
Insert a new Event in the schedule.
Scheduler::Event RemoveNext() override
Remove the earliest event from the event list.
Scheduler::Event PeekNext() const override
Get a pointer to the next event.
bool IsEmpty() const override
Test if the schedule is empty.
EventMap m_list
The event list.
static TypeId GetTypeId()
Register this type.
~MapScheduler() override
Destructor.
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_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:257
#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
Debug message logging.
ns3::MapScheduler declaration.
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
uint64_t m_ts
Event time stamp.
Definition scheduler.h:160
uint32_t m_uid
Event unique id.
Definition scheduler.h:161