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 * 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 * The idea to use a std c++ map came from GTNetS
19 */
20
21#include "map-scheduler.h"
22
23#include "assert.h"
24#include "event-impl.h"
25#include "log.h"
26
27#include <string>
28
35namespace ns3
36{
37
38NS_LOG_COMPONENT_DEFINE("MapScheduler");
39
40NS_OBJECT_ENSURE_REGISTERED(MapScheduler);
41
42TypeId
44{
45 static TypeId tid = TypeId("ns3::MapScheduler")
47 .SetGroupName("Core")
48 .AddConstructor<MapScheduler>();
49 return tid;
50}
51
53{
54 NS_LOG_FUNCTION(this);
55}
56
58{
59 NS_LOG_FUNCTION(this);
60}
61
62void
64{
65 NS_LOG_FUNCTION(this << ev.impl << ev.key.m_ts << ev.key.m_uid);
66 std::pair<EventMapI, bool> result;
67 result = m_list.insert(std::make_pair(ev.key, ev.impl));
68 NS_ASSERT(result.second);
69}
70
71bool
73{
74 NS_LOG_FUNCTION(this);
75 return m_list.empty();
76}
77
80{
81 NS_LOG_FUNCTION(this);
82 EventMapCI i = m_list.begin();
83 NS_ASSERT(i != m_list.end());
84
85 Event ev;
86 ev.impl = i->second;
87 ev.key = i->first;
88 NS_LOG_DEBUG(this << ": " << ev.impl << ", " << ev.key.m_ts << ", " << ev.key.m_uid);
89 return ev;
90}
91
94{
95 NS_LOG_FUNCTION(this);
96 EventMapI i = m_list.begin();
97 NS_ASSERT(i != m_list.end());
98 Event ev;
99 ev.impl = i->second;
100 ev.key = i->first;
101 m_list.erase(i);
102 NS_LOG_DEBUG("@" << this << ": " << ev.impl << ", " << ev.key.m_ts << ", " << ev.key.m_uid);
103 return ev;
104}
105
106void
108{
109 NS_LOG_FUNCTION(this << ev.impl << ev.key.m_ts << ev.key.m_uid);
110 EventMapI i = m_list.find(ev.key);
111 NS_ASSERT(i->second == ev.impl);
112 m_list.erase(i);
113}
114
115} // namespace ns3
NS_ASSERT() and NS_ASSERT_MSG() macro definitions.
a std::map event scheduler
Definition: map-scheduler.h:64
void Remove(const Scheduler::Event &ev) override
Remove a specific event from the event list.
MapScheduler()
Constructor.
std::map< Scheduler::EventKey, EventImpl * >::const_iterator EventMapCI
EventMap const iterator.
Definition: map-scheduler.h:90
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.
std::map< Scheduler::EventKey, EventImpl * >::iterator EventMapI
EventMap iterator.
Definition: map-scheduler.h:88
EventMap m_list
The event list.
Definition: map-scheduler.h:93
static TypeId GetTypeId()
Register this type.
~MapScheduler() override
Destructor.
Maintain the event list.
Definition: scheduler.h:157
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:936
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:66
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:268
#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:46
Debug message logging.
ns3::MapScheduler declaration.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Scheduler event.
Definition: scheduler.h:184
EventKey key
Key for sorting and ordering Events.
Definition: scheduler.h:186
EventImpl * impl
Pointer to the event implementation.
Definition: scheduler.h:185
uint64_t m_ts
Event time stamp.
Definition: scheduler.h:171
uint32_t m_uid
Event unique id.
Definition: scheduler.h:172