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 
34 namespace ns3 {
35 
36 NS_LOG_COMPONENT_DEFINE ("ListScheduler");
37 
38 NS_OBJECT_ENSURE_REGISTERED (ListScheduler);
39 
40 TypeId
42 {
43  static TypeId tid = TypeId ("ns3::ListScheduler")
44  .SetParent<Scheduler> ()
45  .SetGroupName ("Core")
46  .AddConstructor<ListScheduler> ()
47  ;
48  return tid;
49 }
50 
52 {
53  NS_LOG_FUNCTION (this);
54 }
56 {}
57 
58 void
60 {
61  NS_LOG_FUNCTION (this << &ev);
62  for (EventsI i = m_events.begin (); i != m_events.end (); i++)
63  {
64  if (ev.key < i->key)
65  {
66  m_events.insert (i, ev);
67  return;
68  }
69  }
70  m_events.push_back (ev);
71 }
72 bool
74 {
75  NS_LOG_FUNCTION (this);
76  return m_events.empty ();
77 }
80 {
81  NS_LOG_FUNCTION (this);
82  return m_events.front ();
83 }
84 
87 {
88  NS_LOG_FUNCTION (this);
89  Event next = m_events.front ();
90  m_events.pop_front ();
91  return next;
92 }
93 
94 void
96 {
97  NS_LOG_FUNCTION (this << &ev);
98  for (EventsI i = m_events.begin (); i != m_events.end (); i++)
99  {
100  if (i->key.m_uid == ev.key.m_uid)
101  {
102  NS_ASSERT (ev.impl == i->impl);
103  m_events.erase (i);
104  return;
105  }
106  }
107  NS_ASSERT (false);
108 }
109 
110 } // namespace ns3
virtual bool IsEmpty(void) const
Test if the schedule is empty.
#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 Scheduler::Event RemoveNext(void)
Remove the earliest event from the event list.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
EventImpl * impl
Pointer to the event implementation.
Definition: scheduler.h:183
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:67
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
virtual void Insert(const Scheduler::Event &ev)
Insert a new Event in the schedule.
ns3::ListScheduler declaration.
EventKey key
Key for sorting and ordering Events.
Definition: scheduler.h:184
uint32_t m_uid
Event unique id.
Definition: scheduler.h:171
NS_ASSERT() and NS_ASSERT_MSG() macro definitions.
Maintain the event list.
Definition: scheduler.h:155
Scheduler event.
Definition: scheduler.h:181
static TypeId GetTypeId(void)
Register this type.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
virtual ~ListScheduler()
Destructor.
virtual Scheduler::Event PeekNext(void) const
Get a pointer to the next event.
virtual void Remove(const Scheduler::Event &ev)
Remove a specific event from the event list.
Events m_events
The event list.
std::list< Scheduler::Event >::iterator EventsI
Events iterator.
Debug message logging.
a unique identifier for an interface.
Definition: type-id.h:58
a std::list event scheduler
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:923
ListScheduler()
Constructor.