list.h cstdlib src/ctrls.h src/level.h src/PluginManager.h OpenArena::listNode OpenArena::list OpenArena #ifndef__list_h__ #define__list_h__ #include<cstdlib> #pragmawarning(disable:4715) namespaceOpenArena{ typedefunsignedintLIST_ARRAY_INDEX_TYPE; template<classItemType> classlistNode { public: listNode(); ItemTypedata; listNode<ItemType>*next; }; template<classItemType> classlist { public: list(); ~list(); list(constlist&); boolIsEmpty()const; boolIsFull()const; voidInsert(ItemTypenewItem); voidRemove(ItemTypetarget); voidRemove(); ItemTypeRetrieve()const; boolPrevPosition(); boolNextPosition(); boolIsFirstPosition()const; boolIsLastPosition()const; voidFirstPosition(); voidLastPosition(); voidClear(); boolContains(ItemType)const; unsignedintLength(); voidoperator=(constlist<ItemType>&); ItemTypeoperator[](LIST_ARRAY_INDEX_TYPE)const; ItemType&operator[](LIST_ARRAY_INDEX_TYPE); private: listNode<ItemType>*head; listNode<ItemType>*tail; listNode<ItemType>*currPos; }; template<classItemType> listNode<ItemType>::listNode() { next=NULL; } template<classItemType> list<ItemType>::list() { head=NULL; tail=NULL; currPos=NULL; } template<classItemType> list<ItemType>::~list() { currPos=NULL; while(head!=NULL) { tail=head; head=head->next; deletetail; tail=NULL; } } template<classItemType> list<ItemType>::list(constlist<ItemType>&rtOp) { head=NULL; tail=NULL; currPos=NULL; operator=(rtOp); } template<classItemType> voidlist<ItemType>::Clear() { while(head) Remove(head->data); } template<classItemType> voidlist<ItemType>::operator=(constlist<ItemType>&rtOp) { Clear(); if(!rtOp.IsEmpty()) { listNode<ItemType>*temp=rtOp.head->next; listNode<ItemType>*temp2=NULL; if(temp!=NULL) { head=newlistNode<ItemType>; head->data=rtOp.head->data; tail=head; temp2=head; } while(temp!=NULL) { temp2->next=newlistNode<ItemType>; temp2=temp2->next; temp2->data=temp->data; temp=temp->next; } tail=temp2; } } template<classItemType> boollist<ItemType>::IsEmpty()const { returnhead==NULL; } template<classItemType> boollist<ItemType>::IsFull()const { returnfalse; } template<classItemType> voidlist<ItemType>::Insert(ItemTypenewItem) { listNode<ItemType>*temp=head; listNode<ItemType>*temp2=NULL; if(head==NULL) { temp=tail=head=newlistNode<ItemType>; } else { if(newItem<head->data) { temp2=head; temp=head=newlistNode<ItemType>; head->next=temp2; temp2=NULL; } else { //temp=head; while(temp->next!=NULL&&newItem>temp->next->data) { temp=temp->next; } temp2=temp->next; temp=temp->next=newlistNode<ItemType>; temp->next=temp2; temp2=NULL; } } temp->data=newItem; if(temp->next==NULL) { tail=temp; } } template<classItemType> voidlist<ItemType>::Remove(ItemTypetarget) { if(head!=NULL) { listNode<ItemType>*temp=head; listNode<ItemType>*temp2=head; while(temp->next!=NULL&&temp->data!=target) { temp2=temp; temp=temp->next; } if(temp->data==target) { if(temp!=head) { temp2->next=temp->next; deletetemp; } else { if(tail==head) tail=NULL; head=head->next; deletetemp2; } } } } template<classItemType> boollist<ItemType>::PrevPosition() { if(currPos!=head) { tail->next=currPos; currPos=head; if(currPos!=tail->next) { while(currPos->next!=tail->next) { currPos=currPos->next; } } tail->next=NULL; returntrue; } else { returnfalse; } } template<classItemType> boollist<ItemType>::NextPosition() { if(currPos!=tail) { currPos=currPos->next; returntrue; } else { returnfalse; } } template<classItemType> voidlist<ItemType>::Remove() { if(currPos!=NULL) { tail->next=currPos; currPos=currPos->next; deletetail->next; tail->next=NULL; } } template<classItemType> ItemTypelist<ItemType>::Retrieve()const { if(currPos!=NULL) returncurrPos->data; } template<classItemType> boollist<ItemType>::IsFirstPosition()const { returncurrPos==head; } template<classItemType> boollist<ItemType>::IsLastPosition()const { returncurrPos==tail; } template<classItemType> voidlist<ItemType>::FirstPosition() { currPos=head; } template<classItemType> voidlist<ItemType>::LastPosition() { currPos=tail; } template<classItemType> ItemTypelist<ItemType>::operator[](LIST_ARRAY_INDEX_TYPEindex)const { if(head==NULL) { //WeshouldthrowanexceptionherebutinsteadI'lljustreturnshitguessfornowifsomebodydoesthisthey'rejustfucked. } else { listNode<ItemType>*temp=head; LIST_ARRAY_INDEX_TYPEcurrent; for(current=0;current<index;current++) { if(temp->next==NULL) { temp->next=newlistNode<ItemType>; } temp=temp->next; } returntemp->data; } } template<classItemType> ItemType&list<ItemType>::operator[](LIST_ARRAY_INDEX_TYPEindex) { if(head==NULL) { tail=currPos=head=newlistNode<ItemType>; return(ItemType&)(head->data); } else { listNode<ItemType>*temp=head; LIST_ARRAY_INDEX_TYPEcurrent; for(current=0;current<index;current++) { if(temp->next==NULL) { temp->next=newlistNode<ItemType>; } temp=temp->next; } return(ItemType&)(temp->data); } } template<classItemType> unsignedintlist<ItemType>::Length() { if(head==NULL) { return0; } else { intlen=1; listNode<ItemType>temp=head->next; while(temp!=NULL) { temp=temp->next; len++; } returnlen; } } template<classItemType> boollist<ItemType>::Contains(ItemTypevalue)const { listNode<ItemType>*temp=head; while(temp!=NULL) { if(temp->data==value) { returntrue; } temp=temp->next; } returnfalse; } }; #endif