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 
59 void
61 {
62  NS_LOG_FUNCTION (this << &ev);
63  for (EventsI i = m_events.begin (); i != m_events.end (); i++)
64  {
65  if (ev.key < i->key)
66  {
67  m_events.insert (i, ev);
68  return;
69  }
70  }
71  m_events.push_back (ev);
72 }
73 bool
75 {
76  NS_LOG_FUNCTION (this);
77  return m_events.empty ();
78 }
81 {
82  NS_LOG_FUNCTION (this);
83  return m_events.front ();
84 }
85 
88 {
89  NS_LOG_FUNCTION (this);
90  Event next = m_events.front ();
91  m_events.pop_front ();
92  return next;
93 }
94 
95 void
97 {
98  NS_LOG_FUNCTION (this << &ev);
99  for (EventsI i = m_events.begin (); i != m_events.end (); i++)
100  {
101  if (i->key.m_uid == ev.key.m_uid)
102  {
103  NS_ASSERT (ev.impl == i->impl);
104  m_events.erase (i);
105  return;
106  }
107  }
108  NS_ASSERT (false);
109 }
110 
111 } // 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:94
#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:202
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:95
uint32_t m_uid
Event unique id.
Definition: scheduler.h:82
NS_ASSERT() and NS_ASSERT_MSG() macro definitions.
Maintain the event list.
Definition: scheduler.h:66
Scheduler event.
Definition: scheduler.h:92
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:915
ListScheduler()
Constructor.