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 TypeId
37 {
38  static TypeId tid = TypeId ("ns3::ListScheduler")
39  .SetParent<Scheduler> ()
40  .AddConstructor<ListScheduler> ()
41  ;
42  return tid;
43 }
44 
46 {
47  NS_LOG_FUNCTION (this);
48 }
50 {
51 }
52 
53 void
54 ListScheduler::Insert (const Event &ev)
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
90 ListScheduler::Remove (const Event &ev)
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
std::list< Event >::iterator EventsI
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
virtual Event RemoveNext(void)
This method cannot be invoked if the list is empty.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register the class in the ns-3 factory.
Definition: object-base.h:38
virtual void Remove(const Event &ev)
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:61
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:170
virtual Event PeekNext(void) const
virtual bool IsEmpty(void) const
Maintain the event list.
Definition: scheduler.h:58
virtual void Insert(const Event &ev)
static TypeId GetTypeId(void)
virtual ~ListScheduler()
a unique identifier for an interface.
Definition: type-id.h:49
TypeId SetParent(TypeId tid)
Definition: type-id.cc:610