A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
list-scheduler.cc
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2005 INRIA
3
*
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License version 2 as
6
* published by the Free Software Foundation;
7
*
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
12
*
13
* You should have received a copy of the GNU General Public License
14
* along with this program; if not, write to the Free Software
15
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
*
17
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18
*/
19
20
#include "
list-scheduler.h
"
21
22
#include "
assert.h
"
23
#include "
event-impl.h
"
24
#include "
log.h
"
25
26
#include <string>
27
#include <utility>
28
35
namespace
ns3
36
{
37
38
NS_LOG_COMPONENT_DEFINE
(
"ListScheduler"
);
39
40
NS_OBJECT_ENSURE_REGISTERED
(ListScheduler);
41
42
TypeId
43
ListScheduler::GetTypeId
()
44
{
45
static
TypeId
tid =
TypeId
(
"ns3::ListScheduler"
)
46
.
SetParent
<
Scheduler
>()
47
.SetGroupName(
"Core"
)
48
.AddConstructor<
ListScheduler
>();
49
return
tid;
50
}
51
52
ListScheduler::ListScheduler
()
53
{
54
NS_LOG_FUNCTION
(
this
);
55
}
56
57
ListScheduler::~ListScheduler
()
58
{
59
}
60
61
void
62
ListScheduler::Insert
(
const
Event
& ev)
63
{
64
NS_LOG_FUNCTION
(
this
<< &ev);
65
for
(
auto
i =
m_events
.begin(); i !=
m_events
.end(); i++)
66
{
67
if
(ev.
key
< i->key)
68
{
69
m_events
.insert(i, ev);
70
return
;
71
}
72
}
73
m_events
.push_back(ev);
74
}
75
76
bool
77
ListScheduler::IsEmpty
()
const
78
{
79
NS_LOG_FUNCTION
(
this
);
80
return
m_events
.empty();
81
}
82
83
Scheduler::Event
84
ListScheduler::PeekNext
()
const
85
{
86
NS_LOG_FUNCTION
(
this
);
87
return
m_events
.front();
88
}
89
90
Scheduler::Event
91
ListScheduler::RemoveNext
()
92
{
93
NS_LOG_FUNCTION
(
this
);
94
Event
next =
m_events
.front();
95
m_events
.pop_front();
96
return
next;
97
}
98
99
void
100
ListScheduler::Remove
(
const
Event
& ev)
101
{
102
NS_LOG_FUNCTION
(
this
<< &ev);
103
for
(
auto
i =
m_events
.begin(); i !=
m_events
.end(); i++)
104
{
105
if
(i->key.m_uid == ev.
key
.
m_uid
)
106
{
107
NS_ASSERT
(ev.
impl
== i->impl);
108
m_events
.erase(i);
109
return
;
110
}
111
}
112
NS_ASSERT
(
false
);
113
}
114
115
}
// namespace ns3
assert.h
NS_ASSERT() and NS_ASSERT_MSG() macro definitions.
ns3::ListScheduler
a std::list event scheduler
Definition:
list-scheduler.h:66
ns3::ListScheduler::~ListScheduler
~ListScheduler() override
Destructor.
Definition:
list-scheduler.cc:57
ns3::ListScheduler::ListScheduler
ListScheduler()
Constructor.
Definition:
list-scheduler.cc:52
ns3::ListScheduler::m_events
Events m_events
The event list.
Definition:
list-scheduler.h:93
ns3::ListScheduler::RemoveNext
Scheduler::Event RemoveNext() override
Remove the earliest event from the event list.
Definition:
list-scheduler.cc:91
ns3::ListScheduler::Remove
void Remove(const Scheduler::Event &ev) override
Remove a specific event from the event list.
Definition:
list-scheduler.cc:100
ns3::ListScheduler::IsEmpty
bool IsEmpty() const override
Test if the schedule is empty.
Definition:
list-scheduler.cc:77
ns3::ListScheduler::PeekNext
Scheduler::Event PeekNext() const override
Get a pointer to the next event.
Definition:
list-scheduler.cc:84
ns3::ListScheduler::Insert
void Insert(const Scheduler::Event &ev) override
Insert a new Event in the schedule.
Definition:
list-scheduler.cc:62
ns3::ListScheduler::GetTypeId
static TypeId GetTypeId()
Register this type.
Definition:
list-scheduler.cc:43
ns3::Scheduler
Maintain the event list.
Definition:
scheduler.h:157
ns3::TypeId
a unique identifier for an interface.
Definition:
type-id.h:59
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition:
type-id.cc:931
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:66
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition:
log.h:202
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:240
NS_OBJECT_ENSURE_REGISTERED
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition:
object-base.h:46
list-scheduler.h
ns3::ListScheduler declaration.
log.h
Debug message logging.
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::Scheduler::Event
Scheduler event.
Definition:
scheduler.h:184
ns3::Scheduler::Event::key
EventKey key
Key for sorting and ordering Events.
Definition:
scheduler.h:186
ns3::Scheduler::Event::impl
EventImpl * impl
Pointer to the event implementation.
Definition:
scheduler.h:185
ns3::Scheduler::EventKey::m_uid
uint32_t m_uid
Event unique id.
Definition:
scheduler.h:172
src
core
model
list-scheduler.cc
Generated on Sun Mar 3 2024 17:10:55 for ns-3 by
1.9.1