A Discrete-Event Network Simulator
API
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 namespace ns3 {
29 
30 NS_LOG_COMPONENT_DEFINE ("ListScheduler");
31 
32 NS_OBJECT_ENSURE_REGISTERED (ListScheduler);
33 
34 TypeId
36 {
37  static TypeId tid = TypeId ("ns3::ListScheduler")
38  .SetParent<Scheduler> ()
39  .AddConstructor<ListScheduler> ()
40  ;
41  return tid;
42 }
43 
45 {
46  NS_LOG_FUNCTION (this);
47 }
49 {
50 }
51 
52 void
53 ListScheduler::Insert (const Event &ev)
54 {
55  NS_LOG_FUNCTION (this << &ev);
56  for (EventsI i = m_events.begin (); i != m_events.end (); i++)
57  {
58  if (ev.key < i->key)
59  {
60  m_events.insert (i, ev);
61  return;
62  }
63  }
64  m_events.push_back (ev);
65 }
66 bool
68 {
69  NS_LOG_FUNCTION (this);
70  return m_events.empty ();
71 }
74 {
75  NS_LOG_FUNCTION (this);
76  return m_events.front ();
77 }
78 
81 {
82  NS_LOG_FUNCTION (this);
83  Event next = m_events.front ();
84  m_events.pop_front ();
85  return next;
86 }
87 
88 void
89 ListScheduler::Remove (const Event &ev)
90 {
91  NS_LOG_FUNCTION (this << &ev);
92  for (EventsI i = m_events.begin (); i != m_events.end (); i++)
93  {
94  if (i->key.m_uid == ev.key.m_uid)
95  {
96  NS_ASSERT (ev.impl == i->impl);
97  m_events.erase (i);
98  return;
99  }
100  }
101  NS_ASSERT (false);
102 }
103 
104 } // 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 "...
ns3::EventImpl declarations.
virtual Event RemoveNext(void)
This method cannot be invoked if the list is empty.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:44
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:201
virtual Event PeekNext(void) const
virtual bool IsEmpty(void) const
Maintain the event list.
Definition: scheduler.h:66
virtual void Insert(const Event &ev)
Scheduler event.
Definition: scheduler.h:88
static TypeId GetTypeId(void)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
virtual ~ListScheduler()
Debug message logging.
a unique identifier for an interface.
Definition: type-id.h:51
TypeId SetParent(TypeId tid)
Definition: type-id.cc:631