00001 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 00002 /* 00003 * Copyright (c) 2006 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 * The idea to use a std c++ map came from GTNetS 00020 */ 00021 00022 #include "map-scheduler.h" 00023 #include "event-impl.h" 00024 #include "ns3/assert.h" 00025 #include "ns3/log.h" 00026 #include <string> 00027 00028 NS_LOG_COMPONENT_DEFINE ("MapScheduler"); 00029 00030 namespace ns3 { 00031 00032 NS_OBJECT_ENSURE_REGISTERED (MapScheduler); 00033 00034 TypeId 00035 MapScheduler::GetTypeId (void) 00036 { 00037 static TypeId tid = TypeId ("ns3::MapScheduler") 00038 .SetParent<Scheduler> () 00039 .AddConstructor<MapScheduler> () 00040 ; 00041 return tid; 00042 } 00043 00044 MapScheduler::MapScheduler () 00045 {} 00046 MapScheduler::~MapScheduler () 00047 {} 00048 00049 void 00050 MapScheduler::Insert (const Event &ev) 00051 { 00052 NS_LOG_FUNCTION (this << ev.impl << ev.key.m_ts << ev.key.m_uid); 00053 std::pair<EventMapI,bool> result; 00054 result = m_list.insert (std::make_pair (ev.key, ev.impl)); 00055 NS_ASSERT (result.second); 00056 } 00057 00058 bool 00059 MapScheduler::IsEmpty (void) const 00060 { 00061 return m_list.empty (); 00062 } 00063 00064 Scheduler::Event 00065 MapScheduler::PeekNext (void) const 00066 { 00067 NS_LOG_FUNCTION (this); 00068 EventMapCI i = m_list.begin (); 00069 NS_ASSERT (i != m_list.end ()); 00070 00071 Event ev; 00072 ev.impl = i->second; 00073 ev.key = i->first; 00074 NS_LOG_DEBUG (this << ev.impl << ev.key.m_ts << ev.key.m_uid); 00075 return ev; 00076 } 00077 Scheduler::Event 00078 MapScheduler::RemoveNext (void) 00079 { 00080 NS_LOG_FUNCTION (this); 00081 EventMapI i = m_list.begin (); 00082 NS_ASSERT (i != m_list.end ()); 00083 std::pair<Scheduler::EventKey, EventImpl*> next = *i; 00084 Event ev; 00085 ev.impl = i->second; 00086 ev.key = i->first; 00087 m_list.erase (i); 00088 NS_LOG_DEBUG (this << ev.impl << ev.key.m_ts << ev.key.m_uid); 00089 return ev; 00090 } 00091 00092 void 00093 MapScheduler::Remove (const Event &ev) 00094 { 00095 NS_LOG_FUNCTION (this << ev.impl << ev.key.m_ts << ev.key.m_uid); 00096 EventMapI i = m_list.find (ev.key); 00097 NS_ASSERT (i->second == ev.impl); 00098 m_list.erase (i); 00099 } 00100 00101 } // namespace ns3