A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
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
24
namespace
ns3
25
{
26
27
NS_LOG_COMPONENT_DEFINE
(
"MapScheduler"
);
28
29
NS_OBJECT_ENSURE_REGISTERED
(MapScheduler);
30
31
TypeId
32
MapScheduler::GetTypeId
()
33
{
34
static
TypeId
tid =
TypeId
(
"ns3::MapScheduler"
)
35
.
SetParent
<
Scheduler
>()
36
.SetGroupName(
"Core"
)
37
.AddConstructor<
MapScheduler
>();
38
return
tid;
39
}
40
41
MapScheduler::MapScheduler
()
42
{
43
NS_LOG_FUNCTION
(
this
);
44
}
45
46
MapScheduler::~MapScheduler
()
47
{
48
NS_LOG_FUNCTION
(
this
);
49
}
50
51
void
52
MapScheduler::Insert
(
const
Event
& ev)
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
60
bool
61
MapScheduler::IsEmpty
()
const
62
{
63
NS_LOG_FUNCTION
(
this
);
64
return
m_list
.empty();
65
}
66
67
Scheduler::Event
68
MapScheduler::PeekNext
()
const
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
81
Scheduler::Event
82
MapScheduler::RemoveNext
()
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
95
void
96
MapScheduler::Remove
(
const
Event
& ev)
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
assert.h
NS_ASSERT() and NS_ASSERT_MSG() macro definitions.
ns3::MapScheduler
a std::map event scheduler
Definition
map-scheduler.h:53
ns3::MapScheduler::Remove
void Remove(const Scheduler::Event &ev) override
Remove a specific event from the event list.
Definition
map-scheduler.cc:96
ns3::MapScheduler::MapScheduler
MapScheduler()
Constructor.
Definition
map-scheduler.cc:41
ns3::MapScheduler::Insert
void Insert(const Scheduler::Event &ev) override
Insert a new Event in the schedule.
Definition
map-scheduler.cc:52
ns3::MapScheduler::RemoveNext
Scheduler::Event RemoveNext() override
Remove the earliest event from the event list.
Definition
map-scheduler.cc:82
ns3::MapScheduler::PeekNext
Scheduler::Event PeekNext() const override
Get a pointer to the next event.
Definition
map-scheduler.cc:68
ns3::MapScheduler::IsEmpty
bool IsEmpty() const override
Test if the schedule is empty.
Definition
map-scheduler.cc:61
ns3::MapScheduler::m_list
EventMap m_list
The event list.
Definition
map-scheduler.h:82
ns3::MapScheduler::GetTypeId
static TypeId GetTypeId()
Register this type.
Definition
map-scheduler.cc:32
ns3::MapScheduler::~MapScheduler
~MapScheduler() override
Destructor.
Definition
map-scheduler.cc:46
ns3::Scheduler
Maintain the event list.
Definition
scheduler.h:146
ns3::TypeId
a unique identifier for an interface.
Definition
type-id.h:48
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition
type-id.cc:1001
event-impl.h
ns3::EventImpl declarations.
NS_ASSERT
#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
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition
log.h:191
NS_LOG_DEBUG
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition
log.h:257
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Definition
log-macros-enabled.h:229
NS_OBJECT_ENSURE_REGISTERED
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition
object-base.h:35
log.h
Debug message logging.
map-scheduler.h
ns3::MapScheduler declaration.
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::Scheduler::Event
Scheduler event.
Definition
scheduler.h:173
ns3::Scheduler::Event::key
EventKey key
Key for sorting and ordering Events.
Definition
scheduler.h:175
ns3::Scheduler::Event::impl
EventImpl * impl
Pointer to the event implementation.
Definition
scheduler.h:174
ns3::Scheduler::EventKey::m_ts
uint64_t m_ts
Event time stamp.
Definition
scheduler.h:160
ns3::Scheduler::EventKey::m_uid
uint32_t m_uid
Event unique id.
Definition
scheduler.h:161
src
core
model
map-scheduler.cc
Generated on Fri Nov 8 2024 13:58:59 for ns-3 by
1.11.0