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
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Groups
Pages
map-scheduler.cc
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
TypeId
35
MapScheduler::GetTypeId (
void
)
36
{
37
static
TypeId tid = TypeId (
"ns3::MapScheduler"
)
38
.SetParent<Scheduler> ()
39
.AddConstructor<MapScheduler> ()
40
;
41
return
tid;
42
}
43
44
MapScheduler::MapScheduler ()
45
{
46
NS_LOG_FUNCTION
(
this
);
47
}
48
MapScheduler::~MapScheduler ()
49
{
50
NS_LOG_FUNCTION
(
this
);
51
}
52
53
void
54
MapScheduler::Insert
(
const
Event
&ev)
55
{
56
NS_LOG_FUNCTION
(
this
<< ev.impl << ev.key.m_ts << ev.key.m_uid);
57
std::pair<EventMapI,bool> result;
58
result = m_list.insert (std::make_pair (ev.key, ev.impl));
59
NS_ASSERT
(result.second);
60
}
61
62
bool
63
MapScheduler::IsEmpty
(
void
)
const
64
{
65
NS_LOG_FUNCTION
(
this
);
66
return
m_list.empty ();
67
}
68
69
Scheduler::Event
70
MapScheduler::PeekNext
(
void
)
const
71
{
72
NS_LOG_FUNCTION
(
this
);
73
EventMapCI i = m_list.begin ();
74
NS_ASSERT
(i != m_list.end ());
75
76
Event
ev;
77
ev.impl = i->second;
78
ev.key = i->first;
79
NS_LOG_DEBUG
(
this
<< ev.impl << ev.key.m_ts << ev.key.m_uid);
80
return
ev;
81
}
82
Scheduler::Event
83
MapScheduler::RemoveNext
(
void
)
84
{
85
NS_LOG_FUNCTION
(
this
);
86
EventMapI i = m_list.begin ();
87
NS_ASSERT
(i != m_list.end ());
88
Event
ev;
89
ev.impl = i->second;
90
ev.key = i->first;
91
m_list.erase (i);
92
NS_LOG_DEBUG
(
this
<< ev.impl << ev.key.m_ts << ev.key.m_uid);
93
return
ev;
94
}
95
96
void
97
MapScheduler::Remove
(
const
Event
&ev)
98
{
99
NS_LOG_FUNCTION
(
this
<< ev.impl << ev.key.m_ts << ev.key.m_uid);
100
EventMapI i = m_list.find (ev.key);
101
NS_ASSERT
(i->second == ev.impl);
102
m_list.erase (i);
103
}
104
105
}
// namespace ns3
ns3::MapScheduler::PeekNext
virtual Event PeekNext(void) const
Definition:
map-scheduler.cc:70
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
Definition:
log.h:311
NS_ASSERT
#define NS_ASSERT(condition)
Definition:
assert.h:64
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Definition:
log.h:122
ns3::MapScheduler::RemoveNext
virtual Event RemoveNext(void)
Definition:
map-scheduler.cc:83
ns3::MapScheduler::IsEmpty
virtual bool IsEmpty(void) const
Definition:
map-scheduler.cc:63
ns3::Scheduler::Event
Definition:
scheduler.h:64
ns3::MapScheduler::Insert
virtual void Insert(const Event &ev)
Definition:
map-scheduler.cc:54
ns3::MapScheduler::Remove
virtual void Remove(const Event &ev)
Definition:
map-scheduler.cc:97
NS_LOG_DEBUG
#define NS_LOG_DEBUG(msg)
Definition:
log.h:255
src
core
model
map-scheduler.cc
Generated on Sun Mar 16 2014 11:25:02 for ns-3 by
1.8.6