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
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
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
28
NS_LOG_COMPONENT_DEFINE
(
"MapScheduler"
);
29
30
namespace
ns3 {
31
32
NS_OBJECT_ENSURE_REGISTERED
(MapScheduler)
33
;
34
35
TypeId
36
MapScheduler::GetTypeId
(
void
)
37
{
38
static
TypeId
tid =
TypeId
(
"ns3::MapScheduler"
)
39
.
SetParent
<
Scheduler
> ()
40
.AddConstructor<MapScheduler> ()
41
;
42
return
tid;
43
}
44
45
MapScheduler::MapScheduler
()
46
{
47
NS_LOG_FUNCTION
(
this
);
48
}
49
MapScheduler::~MapScheduler
()
50
{
51
NS_LOG_FUNCTION
(
this
);
52
}
53
54
void
55
MapScheduler::Insert
(
const
Event
&ev)
56
{
57
NS_LOG_FUNCTION
(
this
<< ev.
impl
<< ev.
key
.
m_ts
<< ev.
key
.
m_uid
);
58
std::pair<EventMapI,bool> result;
59
result =
m_list
.insert (std::make_pair (ev.
key
, ev.
impl
));
60
NS_ASSERT
(result.second);
61
}
62
63
bool
64
MapScheduler::IsEmpty
(
void
)
const
65
{
66
NS_LOG_FUNCTION
(
this
);
67
return
m_list
.empty ();
68
}
69
70
Scheduler::Event
71
MapScheduler::PeekNext
(
void
)
const
72
{
73
NS_LOG_FUNCTION
(
this
);
74
EventMapCI
i =
m_list
.begin ();
75
NS_ASSERT
(i !=
m_list
.end ());
76
77
Event
ev;
78
ev.
impl
= i->second;
79
ev.key = i->first;
80
NS_LOG_DEBUG
(
this
<< ev.impl << ev.key.m_ts << ev.key.m_uid);
81
return
ev;
82
}
83
Scheduler::Event
84
MapScheduler::RemoveNext
(
void
)
85
{
86
NS_LOG_FUNCTION
(
this
);
87
EventMapI
i =
m_list
.begin ();
88
NS_ASSERT
(i !=
m_list
.end ());
89
Event
ev;
90
ev.
impl
= i->second;
91
ev.key = i->first;
92
m_list
.erase (i);
93
NS_LOG_DEBUG
(
this
<< ev.impl << ev.key.m_ts << ev.key.m_uid);
94
return
ev;
95
}
96
97
void
98
MapScheduler::Remove
(
const
Event
&ev)
99
{
100
NS_LOG_FUNCTION
(
this
<< ev.
impl
<< ev.
key
.
m_ts
<< ev.
key
.
m_uid
);
101
EventMapI
i =
m_list
.find (ev.
key
);
102
NS_ASSERT
(i->second == ev.
impl
);
103
m_list
.erase (i);
104
}
105
106
}
// namespace ns3
ns3::MapScheduler::PeekNext
virtual Event PeekNext(void) const
Definition:
map-scheduler.cc:71
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
Definition:
log.h:345
event-impl.h
ns3::Scheduler::EventKey::m_ts
uint64_t m_ts
Definition:
scheduler.h:65
ns3::Scheduler::Event::impl
EventImpl * impl
Definition:
scheduler.h:72
NS_ASSERT
#define NS_ASSERT(condition)
Definition:
assert.h:64
ns3::NS_OBJECT_ENSURE_REGISTERED
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
ns3::MapScheduler::~MapScheduler
virtual ~MapScheduler()
Definition:
map-scheduler.cc:49
ns3::Scheduler::Event::key
EventKey key
Definition:
scheduler.h:73
ns3::MapScheduler::EventMapCI
std::map< Scheduler::EventKey, EventImpl * >::const_iterator EventMapCI
Definition:
map-scheduler.h:54
ns3::MapScheduler::RemoveNext
virtual Event RemoveNext(void)
This method cannot be invoked if the list is empty.
Definition:
map-scheduler.cc:84
ns3::Scheduler::EventKey::m_uid
uint32_t m_uid
Definition:
scheduler.h:66
assert.h
ns3::Scheduler
Maintain the event list.
Definition:
scheduler.h:57
ns3::MapScheduler::IsEmpty
virtual bool IsEmpty(void) const
Definition:
map-scheduler.cc:64
ns3::MapScheduler::EventMapI
std::map< Scheduler::EventKey, EventImpl * >::iterator EventMapI
Definition:
map-scheduler.h:53
ns3::Scheduler::Event
Definition:
scheduler.h:70
ns3::MapScheduler::MapScheduler
MapScheduler()
Definition:
map-scheduler.cc:45
ns3::MapScheduler::Insert
virtual void Insert(const Event &ev)
Definition:
map-scheduler.cc:55
NS_LOG_COMPONENT_DEFINE
NS_LOG_COMPONENT_DEFINE("MapScheduler")
ns3::MapScheduler::Remove
virtual void Remove(const Event &ev)
Definition:
map-scheduler.cc:98
NS_LOG_DEBUG
#define NS_LOG_DEBUG(msg)
Definition:
log.h:289
map-scheduler.h
ns3::MapScheduler::m_list
EventMap m_list
Definition:
map-scheduler.h:57
log.h
ns3::TypeId
a unique identifier for an interface.
Definition:
type-id.h:49
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Definition:
type-id.cc:611
ns3::MapScheduler::GetTypeId
static TypeId GetTypeId(void)
Definition:
map-scheduler.cc:36
src
core
model
map-scheduler.cc
Generated on Sat Apr 19 2014 14:06:52 for ns-3 by
1.8.6