PriorityQueueIterator.inl
Go to the documentation of this file.00001 //*** PriorityQueueIterator.inl *** 00002 00003 #include "Debug.h" 00004 00005 00006 //*** Constructor *** 00007 00008 template <class TYPE> 00009 PriorityQueueIterator<TYPE>::PriorityQueueIterator(const PriorityQueue<TYPE>& queue): 00010 queue_(&queue), 00011 get_(0) 00012 { 00013 MoveFirst(); // Make sure it is reset to the first item on initialization 00014 } 00015 00016 00017 //*** MoveFirst *** 00018 00019 template <class TYPE> 00020 void PriorityQueueIterator<TYPE>::MoveFirst() 00021 { 00022 get_=0; 00023 } 00024 00025 00026 //*** MoveNext*** 00027 00028 template <class TYPE> 00029 void PriorityQueueIterator<TYPE>::MoveNext() 00030 { 00031 if (get_<queue_.GetItemCount()) 00032 { 00033 get_++; 00034 } 00035 } 00036 00037 00038 //*** MoveLast *** 00039 00040 template <class TYPE> 00041 void PriorityQueueIterator<TYPE>::MoveLast() 00042 { 00043 get_=queue_->GetItemCount()-1; 00044 } 00045 00046 00047 //*** GetPrevious*** 00048 00049 template <class TYPE> 00050 void PriorityQueueIterator<TYPE>::MovePrevious() 00051 { 00052 if (get_>=0) 00053 { 00054 get_--; 00055 } 00056 } 00057 00058 00059 //*** GetCurrent *** 00060 00061 template <class TYPE> 00062 TYPE& PriorityQueueIterator<TYPE>::GetCurrent() const 00063 { 00064 Assert(get_>=0 && get_<queue_->GetItemCount(),"Invalid get location"); 00065 if (get_>=0 && get_<queue_->GetItemCount()) 00066 { 00067 return queue_->Get(get_); 00068 } 00069 00070 static TYPE defaultValue; 00071 return defaultValue; 00072 } 00073 00074 00075 //*** IsValid *** 00076 00077 template <class TYPE> 00078 bool PriorityQueueIterator<TYPE>::IsValid() const 00079 { 00080 if (get_>=0 && get_<queue_->GetItemCount()) 00081 { 00082 return true; 00083 } 00084 00085 return false; 00086 } 00087 00088 00089 //*** Find *** 00090 00091 template <class TYPE> 00092 bool PriorityQueueIterator<TYPE>::Find(const TYPE& data) 00093 { 00094 // Loop through all items 00095 for (int i=0; i<queue_->GetItemCount(); i++) 00096 { 00097 // Is the current item the one we are looking for? 00098 if (queue_->Get(i)==data) 00099 { 00100 // Yes, so set the get pointer to point at it 00101 get_=i; 00102 00103 // And return true to indicate it was found 00104 return true; 00105 } 00106 } 00107 00108 // The item was not found, so return false to indicate this 00109 return false; 00110 } 00111 00112 00113 //*** GetCurrentIndex *** 00114 00115 template <class TYPE> 00116 int PriorityQueueIterator<TYPE>::GetCurrentIndex() const 00117 { 00118 return get_; 00119 }
Reproduction/republishing of any material on this site without permission is strictly prohibited.
