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 <utility>
24 #include <string>
25 #include "assert.h"
26 
27 namespace ns3 {
28 
29 
30 NS_OBJECT_ENSURE_REGISTERED (ListScheduler);
31 
32 TypeId
34 {
35  static TypeId tid = TypeId ("ns3::ListScheduler")
36  .SetParent<Scheduler> ()
37  .AddConstructor<ListScheduler> ()
38  ;
39  return tid;
40 }
41 
43 {
44 }
46 {
47 }
48 
49 void
51 {
52  for (EventsI i = m_events.begin (); i != m_events.end (); i++)
53  {
54  if (ev.key < i->key)
55  {
56  m_events.insert (i, ev);
57  return;
58  }
59  }
60  m_events.push_back (ev);
61 }
62 bool
64 {
65  return m_events.empty ();
66 }
69 {
70  return m_events.front ();
71 }
72 
75 {
76  Event next = m_events.front ();
77  m_events.pop_front ();
78  return next;
79 }
80 
81 void
83 {
84  for (EventsI i = m_events.begin (); i != m_events.end (); i++)
85  {
86  if (i->key.m_uid == ev.key.m_uid)
87  {
88  NS_ASSERT (ev.impl == i->impl);
89  m_events.erase (i);
90  return;
91  }
92  }
93  NS_ASSERT (false);
94 }
95 
96 } // namespace ns3