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
NS_ASSERT() and NS_ASSERT_MSG() macro definitions.
a std::list event scheduler
virtual void Insert(const Scheduler::Event &ev)
Insert a new Event in the schedule.
virtual Scheduler::Event RemoveNext(void)
Remove the earliest event from the event list.
virtual ~ListScheduler()
Destructor.
virtual Scheduler::Event PeekNext(void) const
Get a pointer to the next event.
std::list< Scheduler::Event >::iterator EventsI
Events iterator.
virtual bool IsEmpty(void) const
Test if the schedule is empty.
ListScheduler()
Constructor.
Events m_events
The event list.
static TypeId GetTypeId(void)
Register this type.
virtual void Remove(const Scheduler::Event &ev)
Remove a specific event from the event list.
Maintain the event list.
Definition: scheduler.h:156
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
ns3::EventImpl declarations.
#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
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
ns3::ListScheduler declaration.
Debug message logging.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Scheduler event.
Definition: scheduler.h:182
EventKey key
Key for sorting and ordering Events.
Definition: scheduler.h:184
EventImpl * impl
Pointer to the event implementation.
Definition: scheduler.h:183
uint32_t m_uid
Event unique id.
Definition: scheduler.h:171