Alex Bikfalvi
SimStream Documentation
SimEventList.cpp
00001 #include "Headers.h" 00002 #include "SimEventList.h" 00003 00004 CSimEventList::CSimEventList() 00005 { 00006 this->events = new multimap<__time, CSimEvent*>(); 00007 } 00008 00009 CSimEventList::CSimEventList(CSimModel* model) 00010 { 00011 this->events = new multimap<__time, CSimEvent*>(); 00012 00013 if(NULL == model) return; 00014 00015 __time time; 00016 for(__uint32 index = 0; index < model->Events(); index++) 00017 { 00018 try { 00019 CSimEvent* evt = model->Event(index, time); 00020 this->Add(time, evt); 00021 } catch(...) { } 00022 } 00023 } 00024 00025 CSimEventList::~CSimEventList() 00026 { 00027 for(multimap<__time, CSimEvent*>::iterator iter = this->events->begin(); iter != this->events->end(); iter++) 00028 delete iter->second; 00029 delete this->events; 00030 } 00031 00032 bool CSimEventList::HasEvents() 00033 { 00034 return this->events->begin() != this->events->end(); 00035 } 00036 00037 CSimEvent* CSimEventList::GetEvent(__time &time) 00038 { 00039 if(this->events->begin() == this->events->end()) return NULL; 00040 00041 multimap<__time, CSimEvent*>::iterator iter = this->events->begin(); 00042 CSimEvent* evt = iter->second; 00043 time = iter->first; 00044 this->events->erase(iter); 00045 return evt; 00046 } 00047 00048 __uint32 CSimEventList::Size() 00049 { 00050 return this->events->size(); 00051 } 00052 00053 void CSimEventList::Add(__time time, CSimEvent *evt) 00054 { 00055 assert(evt); 00056 this->events->insert(pair<__time, CSimEvent*>(time, evt)); 00057 } 00058 00059 void CSimEventList::Cancel(__time time, CSimEvent* evt) 00060 { 00061 assert(this->events->count(time)); 00062 00063 pair<multimap<__time, CSimEvent*>::iterator, multimap<__time, CSimEvent*>::iterator> bounds = 00064 this->events->equal_range(time); 00065 00066 for(multimap<__time, CSimEvent*>::iterator iter = bounds.first; iter != bounds.second; iter++) 00067 if(iter->second == evt) 00068 { 00069 this->events->erase(iter); 00070 return; 00071 } 00072 } 00073 00074 void CSimEventList::Clean() 00075 { 00076 for(multimap<__time, CSimEvent*>::iterator iter = this->events->begin(); iter != this->events->end(); iter++) 00077 iter->second->Clean(); 00078 }
Last updated: February 8, 2011