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 "log.h"
14
15#include <string>
16
17/**
18 * @file
19 * @ingroup scheduler
20 * ns3::MapScheduler implementation.
21 */
22
23namespace ns3
24{
25
26NS_LOG_COMPONENT_DEFINE("MapScheduler");
27
29
32{
33 static TypeId tid = TypeId("ns3::MapScheduler")
35 .SetGroupName("Core")
36 .AddConstructor<MapScheduler>();
37 return tid;
38}
39
44
49
50void
52{
53 NS_LOG_FUNCTION(this << ev.impl << ev.key.m_ts << ev.key.m_uid);
54 std::pair<EventMapI, bool> result;
55 result = m_list.insert(std::make_pair(ev.key, ev.impl));
56 NS_ASSERT(result.second);
57}
58
59bool
61{
62 NS_LOG_FUNCTION(this);
63 return m_list.empty();
64}
65
68{
69 NS_LOG_FUNCTION(this);
70 auto i = m_list.begin();
71 NS_ASSERT(i != m_list.end());
72
73 Event ev;
74 ev.impl = i->second;
75 ev.key = i->first;
76 NS_LOG_DEBUG(this << ": " << ev.impl << ", " << ev.key.m_ts << ", " << ev.key.m_uid);
77 return ev;
78}
79
82{
83 NS_LOG_FUNCTION(this);
84 auto i = m_list.begin();
85 NS_ASSERT(i != m_list.end());
86 Event ev;
87 ev.impl = i->second;
88 ev.key = i->first;
89 m_list.erase(i);
90 NS_LOG_DEBUG("@" << this << ": " << ev.impl << ", " << ev.key.m_ts << ", " << ev.key.m_uid);
91 return ev;
92}
93
94void
96{
97 NS_LOG_FUNCTION(this << ev.impl << ev.key.m_ts << ev.key.m_uid);
98 auto i = m_list.find(ev.key);
99 NS_ASSERT(i->second == ev.impl);
100 m_list.erase(i);
101}
102
103} // namespace ns3
NS_ASSERT() and NS_ASSERT_MSG() macro definitions.
return result
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: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_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition log.h:260
#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