00001 #ifndef _PRIORITYLIST_H_ 00002 #define _PRIORITYLIST_H_ 00003 00004 #include <map> 00005 00006 #ifndef DOXYSKIP 00007 using namespace std; 00008 #endif 00009 00011 template <class Rule> 00012 class PriorityPair : public pair<int,Rule*> { 00013 public: 00015 PriorityPair(int prioriry, Rule *rule) : pair<int,Rule*>(prioriry,rule) {}; 00017 PriorityPair(Constant *prioriry, Rule *rule) : pair<int,Rule*>(prioriry->toInt(),rule) { 00018 delete prioriry; 00019 }; 00020 }; 00021 00023 template <class Rule> 00024 class PriorityList : public multimap<int,Rule*>{ 00025 public: 00026 00028 ~PriorityList(){ 00029 typename multimap<int,Rule*>::iterator rulesIt = begin(); 00030 typename multimap<int,Rule*>::iterator rulesEnd = end(); 00031 while (rulesIt!=rulesEnd){ 00032 delete rulesIt->second; 00033 rulesIt++; 00034 }; 00035 }; 00036 00038 typename multimap<int,Rule*>::iterator insert(PriorityPair<Rule> *pair) { 00039 typename multimap<int,Rule*>::iterator it = multimap<int,Rule*>::insert(*pair); 00040 delete pair; 00041 return it; 00042 }; 00043 00045 typename multimap<int,Rule*>::iterator insert(const PriorityPair<Rule> &pair) { 00046 return multimap<int,Rule*>::insert(pair); 00047 }; 00048 00050 PriorityList* append(const PriorityList &toAppend){ 00051 typename multimap<int,Rule*>::const_iterator it = toAppend.begin(); 00052 typename multimap<int,Rule*>::const_iterator eit = toAppend.end(); 00053 while (it!=eit){ 00054 multimap<int,Rule*>::insert(*it); 00055 it++; 00056 }; 00057 return this; 00058 }; 00060 PriorityList* append(PriorityList *toAppend){ 00061 append(*toAppend); 00062 toAppend->clear(); 00063 delete toAppend; 00064 return this; 00065 }; 00066 }; 00067 00068 #endif