A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
list-scheduler.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2005 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  */
20 
21 #include "list-scheduler.h"
22 #include "event-impl.h"
23 #include "log.h"
24 #include <utility>
25 #include <string>
26 #include "assert.h"
27 
28 NS_LOG_COMPONENT_DEFINE ("ListScheduler");
29 
30 namespace ns3 {
31 
32 
33 NS_OBJECT_ENSURE_REGISTERED (ListScheduler)
34  ;
35 
36 TypeId
38 {
39  static TypeId tid = TypeId ("ns3::ListScheduler")
40  .SetParent<Scheduler> ()
41  .AddConstructor<ListScheduler> ()
42  ;
43  return tid;
44 }
45 
47 {
48  NS_LOG_FUNCTION (this);
49 }
51 {
52 }
53 
54 void
56 {
57  NS_LOG_FUNCTION (this << &ev);
58  for (EventsI i = m_events.begin (); i != m_events.end (); i++)
59  {
60  if (ev.key < i->key)
61  {
62  m_events.insert (i, ev);
63  return;
64  }
65  }
66  m_events.push_back (ev);
67 }
68 bool
70 {
71  NS_LOG_FUNCTION (this);
72  return m_events.empty ();
73 }
76 {
77  NS_LOG_FUNCTION (this);
78  return m_events.front ();
79 }
80 
83 {
84  NS_LOG_FUNCTION (this);
85  Event next = m_events.front ();
86  m_events.pop_front ();
87  return next;
88 }
89 
90 void
92 {
93  NS_LOG_FUNCTION (this << &ev);
94  for (EventsI i = m_events.begin (); i != m_events.end (); i++)
95  {
96  if (i->key.m_uid == ev.key.m_uid)
97  {
98  NS_ASSERT (ev.impl == i->impl);
99  m_events.erase (i);
100  return;
101  }
102  }
103  NS_ASSERT (false);
104 }
105 
106 } // namespace ns3
std::list< Event >::iterator EventsI
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:345
virtual Event RemoveNext(void)
This method cannot be invoked if the list is empty.
virtual void Remove(const Event &ev)
EventImpl * impl
Definition: scheduler.h:72
#define NS_ASSERT(condition)
Definition: assert.h:64
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
virtual Event PeekNext(void) const
virtual bool IsEmpty(void) const
Maintain the event list.
Definition: scheduler.h:57
virtual void Insert(const Event &ev)
static TypeId GetTypeId(void)
virtual ~ListScheduler()
NS_LOG_COMPONENT_DEFINE("ListScheduler")
a unique identifier for an interface.
Definition: type-id.h:49
TypeId SetParent(TypeId tid)
Definition: type-id.cc:611