A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
list-scheduler.cc
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 TypeId
36 ListScheduler::GetTypeId (void)
37 {
38  static TypeId tid = TypeId ("ns3::ListScheduler")
39  .SetParent<Scheduler> ()
40  .AddConstructor<ListScheduler> ()
41  ;
42  return tid;
43 }
44 
45 ListScheduler::ListScheduler ()
46 {
47  NS_LOG_FUNCTION (this);
48 }
49 ListScheduler::~ListScheduler ()
50 {
51 }
52 
53 void
55 {
56  NS_LOG_FUNCTION (this << &ev);
57  for (EventsI i = m_events.begin (); i != m_events.end (); i++)
58  {
59  if (ev.key < i->key)
60  {
61  m_events.insert (i, ev);
62  return;
63  }
64  }
65  m_events.push_back (ev);
66 }
67 bool
69 {
70  NS_LOG_FUNCTION (this);
71  return m_events.empty ();
72 }
75 {
76  NS_LOG_FUNCTION (this);
77  return m_events.front ();
78 }
79 
82 {
83  NS_LOG_FUNCTION (this);
84  Event next = m_events.front ();
85  m_events.pop_front ();
86  return next;
87 }
88 
89 void
91 {
92  NS_LOG_FUNCTION (this << &ev);
93  for (EventsI i = m_events.begin (); i != m_events.end (); i++)
94  {
95  if (i->key.m_uid == ev.key.m_uid)
96  {
97  NS_ASSERT (ev.impl == i->impl);
98  m_events.erase (i);
99  return;
100  }
101  }
102  NS_ASSERT (false);
103 }
104 
105 } // namespace ns3
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:311
virtual Event RemoveNext(void)
virtual void Remove(const Event &ev)
#define NS_ASSERT(condition)
Definition: assert.h:64
#define NS_LOG_COMPONENT_DEFINE(name)
Definition: log.h:122
virtual Event PeekNext(void) const
virtual bool IsEmpty(void) const
virtual void Insert(const Event &ev)