00001 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 00002 /* 00003 * Copyright (c) 2005 INRIA 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License version 2 as 00007 * published by the Free Software Foundation; 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 * 00018 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr> 00019 */ 00020 00021 #include "list-scheduler.h" 00022 #include "event-impl.h" 00023 #include <utility> 00024 #include <string> 00025 #include "ns3/assert.h" 00026 00027 namespace ns3 { 00028 00029 00030 NS_OBJECT_ENSURE_REGISTERED (ListScheduler); 00031 00032 TypeId 00033 ListScheduler::GetTypeId (void) 00034 { 00035 static TypeId tid = TypeId ("ns3::ListScheduler") 00036 .SetParent<Scheduler> () 00037 .AddConstructor<ListScheduler> () 00038 ; 00039 return tid; 00040 } 00041 00042 ListScheduler::ListScheduler () 00043 {} 00044 ListScheduler::~ListScheduler () 00045 {} 00046 00047 void 00048 ListScheduler::Insert (const Event &ev) 00049 { 00050 for (EventsI i = m_events.begin (); i != m_events.end (); i++) 00051 { 00052 if (ev.key < i->key) 00053 { 00054 m_events.insert (i, ev); 00055 return; 00056 } 00057 } 00058 m_events.push_back (ev); 00059 } 00060 bool 00061 ListScheduler::IsEmpty (void) const 00062 { 00063 return m_events.empty (); 00064 } 00065 Scheduler::Event 00066 ListScheduler::PeekNext (void) const 00067 { 00068 return m_events.front (); 00069 } 00070 00071 Scheduler::Event 00072 ListScheduler::RemoveNext (void) 00073 { 00074 Event next = m_events.front (); 00075 m_events.pop_front (); 00076 return next; 00077 } 00078 00079 void 00080 ListScheduler::Remove (const Event &ev) 00081 { 00082 for (EventsI i = m_events.begin (); i != m_events.end (); i++) 00083 { 00084 if (i->key.m_uid == ev.key.m_uid) 00085 { 00086 NS_ASSERT (ev.impl == i->impl); 00087 m_events.erase (i); 00088 return; 00089 } 00090 } 00091 NS_ASSERT (false); 00092 } 00093 00094 } // namespace ns3