A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
map-scheduler.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2006 INRIA
4
*
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License version 2 as
7
* published by the Free Software Foundation;
8
*
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
*
18
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19
* The idea to use a std c++ map came from GTNetS
20
*/
21
22
#include "
map-scheduler.h
"
23
#include "
event-impl.h
"
24
#include "
assert.h
"
25
#include "
log.h
"
26
#include <string>
27
34
namespace
ns3
{
35
36
NS_LOG_COMPONENT_DEFINE
(
"MapScheduler"
);
37
38
NS_OBJECT_ENSURE_REGISTERED
(MapScheduler);
39
40
TypeId
41
MapScheduler::GetTypeId
(
void
)
42
{
43
static
TypeId
tid =
TypeId
(
"ns3::MapScheduler"
)
44
.
SetParent
<
Scheduler
> ()
45
.SetGroupName (
"Core"
)
46
.AddConstructor<
MapScheduler
> ()
47
;
48
return
tid;
49
}
50
51
MapScheduler::MapScheduler
()
52
{
53
NS_LOG_FUNCTION
(
this
);
54
}
55
MapScheduler::~MapScheduler
()
56
{
57
NS_LOG_FUNCTION
(
this
);
58
}
59
60
void
61
MapScheduler::Insert
(
const
Event
&ev)
62
{
63
NS_LOG_FUNCTION
(
this
<< ev.
impl
<< ev.
key
.
m_ts
<< ev.
key
.
m_uid
);
64
std::pair<EventMapI,bool> result;
65
result =
m_list
.insert (std::make_pair (ev.
key
, ev.
impl
));
66
NS_ASSERT
(result.second);
67
}
68
69
bool
70
MapScheduler::IsEmpty
(
void
)
const
71
{
72
NS_LOG_FUNCTION
(
this
);
73
return
m_list
.empty ();
74
}
75
76
Scheduler::Event
77
MapScheduler::PeekNext
(
void
)
const
78
{
79
NS_LOG_FUNCTION
(
this
);
80
EventMapCI
i =
m_list
.begin ();
81
NS_ASSERT
(i !=
m_list
.end ());
82
83
Event
ev;
84
ev.
impl
= i->second;
85
ev.key = i->first;
86
NS_LOG_DEBUG
(
this
<< ev.impl << ev.key.m_ts << ev.key.m_uid);
87
return
ev;
88
}
89
Scheduler::Event
90
MapScheduler::RemoveNext
(
void
)
91
{
92
NS_LOG_FUNCTION
(
this
);
93
EventMapI
i =
m_list
.begin ();
94
NS_ASSERT
(i !=
m_list
.end ());
95
Event
ev;
96
ev.
impl
= i->second;
97
ev.key = i->first;
98
m_list
.erase (i);
99
NS_LOG_DEBUG
(
this
<< ev.impl << ev.key.m_ts << ev.key.m_uid);
100
return
ev;
101
}
102
103
void
104
MapScheduler::Remove
(
const
Event
&ev)
105
{
106
NS_LOG_FUNCTION
(
this
<< ev.
impl
<< ev.
key
.
m_ts
<< ev.
key
.
m_uid
);
107
EventMapI
i =
m_list
.find (ev.
key
);
108
NS_ASSERT
(i->second == ev.
impl
);
109
m_list
.erase (i);
110
}
111
112
}
// namespace ns3
ns3::MapScheduler::PeekNext
virtual Event PeekNext(void) const
Definition:
map-scheduler.cc:77
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:213
ns3::MapScheduler
a std::map event scheduler
Definition:
map-scheduler.h:44
event-impl.h
ns3::EventImpl declarations.
NS_OBJECT_ENSURE_REGISTERED
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition:
object-base.h:44
ns3::Scheduler::EventKey::m_ts
uint64_t m_ts
Event time stamp.
Definition:
scheduler.h:77
ns3::Scheduler::Event::impl
EventImpl * impl
Pointer to the event implementation.
Definition:
scheduler.h:90
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:67
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition:
log.h:201
ns3::MapScheduler::~MapScheduler
virtual ~MapScheduler()
Definition:
map-scheduler.cc:55
ns3::Scheduler::Event::key
EventKey key
Key for sorting and ordering Events.
Definition:
scheduler.h:91
ns3::MapScheduler::EventMapCI
std::map< Scheduler::EventKey, EventImpl * >::const_iterator EventMapCI
Definition:
map-scheduler.h:60
ns3::MapScheduler::RemoveNext
virtual Event RemoveNext(void)
This method cannot be invoked if the list is empty.
Definition:
map-scheduler.cc:90
ns3::Scheduler::EventKey::m_uid
uint32_t m_uid
Event unique id.
Definition:
scheduler.h:78
assert.h
Definition of assertion macros NS_ASSERT() and NS_ASSERT_MSG().
ns3::Scheduler
Maintain the event list.
Definition:
scheduler.h:66
ns3::MapScheduler::IsEmpty
virtual bool IsEmpty(void) const
Definition:
map-scheduler.cc:70
ns3::MapScheduler::EventMapI
std::map< Scheduler::EventKey, EventImpl * >::iterator EventMapI
Definition:
map-scheduler.h:59
ns3::Scheduler::Event
Scheduler event.
Definition:
scheduler.h:88
ns3::MapScheduler::MapScheduler
MapScheduler()
Definition:
map-scheduler.cc:51
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::MapScheduler::Insert
virtual void Insert(const Event &ev)
Definition:
map-scheduler.cc:61
ns3::MapScheduler::Remove
virtual void Remove(const Event &ev)
Definition:
map-scheduler.cc:104
NS_LOG_DEBUG
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition:
log.h:236
map-scheduler.h
Declaration of ns3::MapScheduler class.
ns3::MapScheduler::m_list
EventMap m_list
Definition:
map-scheduler.h:63
log.h
Debug message logging.
ns3::TypeId
a unique identifier for an interface.
Definition:
type-id.h:57
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Definition:
type-id.cc:638
ns3::MapScheduler::GetTypeId
static TypeId GetTypeId(void)
Definition:
map-scheduler.cc:41
src
core
model
map-scheduler.cc
Generated on Wed May 13 2015 14:59:11 for ns-3 by
1.8.9.1