Changed Moved template List<class> into namespace OpenArena
~g2k
This commit is contained in:
203
include/list.h
203
include/list.h
@@ -5,21 +5,22 @@
|
|||||||
|
|
||||||
#pragma warning(disable:4715)
|
#pragma warning(disable:4715)
|
||||||
|
|
||||||
typedef unsigned int LIST_ARRAY_INDEX_TYPE;
|
namespace OpenArena{
|
||||||
|
typedef unsigned int LIST_ARRAY_INDEX_TYPE;
|
||||||
|
|
||||||
template <class ItemType>
|
template <class ItemType>
|
||||||
class listNode
|
class listNode
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
listNode();
|
listNode();
|
||||||
ItemType data;
|
ItemType data;
|
||||||
listNode<ItemType>* next;
|
listNode<ItemType>* next;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class ItemType>
|
template <class ItemType>
|
||||||
class list
|
class list
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
list();
|
list();
|
||||||
~list();
|
~list();
|
||||||
list(const list&);
|
list(const list&);
|
||||||
@@ -43,29 +44,29 @@ public:
|
|||||||
ItemType operator[](LIST_ARRAY_INDEX_TYPE) const;
|
ItemType operator[](LIST_ARRAY_INDEX_TYPE) const;
|
||||||
ItemType& operator[](LIST_ARRAY_INDEX_TYPE);
|
ItemType& operator[](LIST_ARRAY_INDEX_TYPE);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
listNode<ItemType>* head;
|
listNode<ItemType>* head;
|
||||||
listNode<ItemType>* tail;
|
listNode<ItemType>* tail;
|
||||||
listNode<ItemType>* currPos;
|
listNode<ItemType>* currPos;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class ItemType>
|
template <class ItemType>
|
||||||
listNode<ItemType>::listNode()
|
listNode<ItemType>::listNode()
|
||||||
{
|
{
|
||||||
next = NULL;
|
next = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class ItemType>
|
template <class ItemType>
|
||||||
list<ItemType>::list()
|
list<ItemType>::list()
|
||||||
{
|
{
|
||||||
head = NULL;
|
head = NULL;
|
||||||
tail = NULL;
|
tail = NULL;
|
||||||
currPos = NULL;
|
currPos = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class ItemType>
|
template <class ItemType>
|
||||||
list<ItemType>::~list()
|
list<ItemType>::~list()
|
||||||
{
|
{
|
||||||
currPos = NULL;
|
currPos = NULL;
|
||||||
while(head != NULL)
|
while(head != NULL)
|
||||||
{
|
{
|
||||||
@@ -74,28 +75,28 @@ list<ItemType>::~list()
|
|||||||
delete tail;
|
delete tail;
|
||||||
tail = NULL;
|
tail = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class ItemType>
|
template <class ItemType>
|
||||||
list<ItemType>::list(const list<ItemType>& rtOp)
|
list<ItemType>::list(const list<ItemType>& rtOp)
|
||||||
{
|
{
|
||||||
head = NULL;
|
head = NULL;
|
||||||
tail = NULL;
|
tail = NULL;
|
||||||
currPos = NULL;
|
currPos = NULL;
|
||||||
|
|
||||||
operator=(rtOp);
|
operator=(rtOp);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class ItemType>
|
template <class ItemType>
|
||||||
void list<ItemType>::Clear()
|
void list<ItemType>::Clear()
|
||||||
{
|
{
|
||||||
while(head)
|
while(head)
|
||||||
Remove(head->data);
|
Remove(head->data);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class ItemType>
|
template <class ItemType>
|
||||||
void list<ItemType>::operator=(const list<ItemType>& rtOp)
|
void list<ItemType>::operator=(const list<ItemType>& rtOp)
|
||||||
{
|
{
|
||||||
Clear();
|
Clear();
|
||||||
|
|
||||||
if(!rtOp.IsEmpty())
|
if(!rtOp.IsEmpty())
|
||||||
@@ -121,23 +122,23 @@ void list<ItemType>::operator=(const list<ItemType>& rtOp)
|
|||||||
|
|
||||||
tail = temp2;
|
tail = temp2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class ItemType>
|
template <class ItemType>
|
||||||
bool list<ItemType>::IsEmpty() const
|
bool list<ItemType>::IsEmpty() const
|
||||||
{
|
{
|
||||||
return head == NULL;
|
return head == NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class ItemType>
|
template <class ItemType>
|
||||||
bool list<ItemType>::IsFull() const
|
bool list<ItemType>::IsFull() const
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class ItemType>
|
template <class ItemType>
|
||||||
void list<ItemType>::Insert(ItemType newItem)
|
void list<ItemType>::Insert(ItemType newItem)
|
||||||
{
|
{
|
||||||
listNode<ItemType>* temp = head;
|
listNode<ItemType>* temp = head;
|
||||||
listNode<ItemType>* temp2 = NULL;
|
listNode<ItemType>* temp2 = NULL;
|
||||||
|
|
||||||
@@ -174,11 +175,11 @@ void list<ItemType>::Insert(ItemType newItem)
|
|||||||
{
|
{
|
||||||
tail = temp;
|
tail = temp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class ItemType>
|
template <class ItemType>
|
||||||
void list<ItemType>::Remove(ItemType target)
|
void list<ItemType>::Remove(ItemType target)
|
||||||
{
|
{
|
||||||
if(head != NULL)
|
if(head != NULL)
|
||||||
{
|
{
|
||||||
listNode<ItemType>* temp = head;
|
listNode<ItemType>* temp = head;
|
||||||
@@ -206,11 +207,11 @@ void list<ItemType>::Remove(ItemType target)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class ItemType>
|
template <class ItemType>
|
||||||
bool list<ItemType>::PrevPosition()
|
bool list<ItemType>::PrevPosition()
|
||||||
{
|
{
|
||||||
if(currPos != head)
|
if(currPos != head)
|
||||||
{
|
{
|
||||||
tail->next = currPos;
|
tail->next = currPos;
|
||||||
@@ -232,11 +233,11 @@ bool list<ItemType>::PrevPosition()
|
|||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class ItemType>
|
template <class ItemType>
|
||||||
bool list<ItemType>::NextPosition()
|
bool list<ItemType>::NextPosition()
|
||||||
{
|
{
|
||||||
if(currPos != tail)
|
if(currPos != tail)
|
||||||
{
|
{
|
||||||
currPos = currPos->next;
|
currPos = currPos->next;
|
||||||
@@ -246,11 +247,11 @@ bool list<ItemType>::NextPosition()
|
|||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class ItemType>
|
template <class ItemType>
|
||||||
void list<ItemType>::Remove()
|
void list<ItemType>::Remove()
|
||||||
{
|
{
|
||||||
if(currPos != NULL)
|
if(currPos != NULL)
|
||||||
{
|
{
|
||||||
tail->next = currPos;
|
tail->next = currPos;
|
||||||
@@ -259,42 +260,42 @@ void list<ItemType>::Remove()
|
|||||||
tail->next = NULL;
|
tail->next = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class ItemType>
|
template <class ItemType>
|
||||||
ItemType list<ItemType>::Retrieve() const
|
ItemType list<ItemType>::Retrieve() const
|
||||||
{
|
{
|
||||||
if(currPos != NULL)
|
if(currPos != NULL)
|
||||||
return currPos->data;
|
return currPos->data;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class ItemType>
|
template <class ItemType>
|
||||||
bool list<ItemType>::IsFirstPosition() const
|
bool list<ItemType>::IsFirstPosition() const
|
||||||
{
|
{
|
||||||
return currPos == head;
|
return currPos == head;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class ItemType>
|
template <class ItemType>
|
||||||
bool list<ItemType>::IsLastPosition() const
|
bool list<ItemType>::IsLastPosition() const
|
||||||
{
|
{
|
||||||
return currPos == tail;
|
return currPos == tail;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class ItemType>
|
template <class ItemType>
|
||||||
void list<ItemType>::FirstPosition()
|
void list<ItemType>::FirstPosition()
|
||||||
{
|
{
|
||||||
currPos = head;
|
currPos = head;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class ItemType>
|
template <class ItemType>
|
||||||
void list<ItemType>::LastPosition()
|
void list<ItemType>::LastPosition()
|
||||||
{
|
{
|
||||||
currPos = tail;
|
currPos = tail;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class ItemType>
|
template <class ItemType>
|
||||||
ItemType list<ItemType>::operator[](LIST_ARRAY_INDEX_TYPE index) const
|
ItemType list<ItemType>::operator[](LIST_ARRAY_INDEX_TYPE index) const
|
||||||
{
|
{
|
||||||
if(head == NULL)
|
if(head == NULL)
|
||||||
{
|
{
|
||||||
//We should throw an exception here but instead I'll just return shit guess for now if somebody does this they're just fucked.
|
//We should throw an exception here but instead I'll just return shit guess for now if somebody does this they're just fucked.
|
||||||
@@ -314,11 +315,11 @@ ItemType list<ItemType>::operator[](LIST_ARRAY_INDEX_TYPE index) const
|
|||||||
}
|
}
|
||||||
return temp->data;
|
return temp->data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class ItemType>
|
template <class ItemType>
|
||||||
ItemType& list<ItemType>::operator[](LIST_ARRAY_INDEX_TYPE index)
|
ItemType& list<ItemType>::operator[](LIST_ARRAY_INDEX_TYPE index)
|
||||||
{
|
{
|
||||||
if(head == NULL)
|
if(head == NULL)
|
||||||
{
|
{
|
||||||
tail = currPos = head = new listNode<ItemType>;
|
tail = currPos = head = new listNode<ItemType>;
|
||||||
@@ -339,11 +340,11 @@ ItemType& list<ItemType>::operator[](LIST_ARRAY_INDEX_TYPE index)
|
|||||||
}
|
}
|
||||||
return (ItemType&)(temp->data);
|
return (ItemType&)(temp->data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class ItemType>
|
template <class ItemType>
|
||||||
unsigned int list<ItemType>::Length()
|
unsigned int list<ItemType>::Length()
|
||||||
{
|
{
|
||||||
if (head == NULL)
|
if (head == NULL)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
@@ -359,11 +360,11 @@ unsigned int list<ItemType>::Length()
|
|||||||
}
|
}
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class ItemType>
|
template<class ItemType>
|
||||||
bool list<ItemType>::Contains(ItemType value) const
|
bool list<ItemType>::Contains(ItemType value) const
|
||||||
{
|
{
|
||||||
listNode<ItemType>* temp = head;
|
listNode<ItemType>* temp = head;
|
||||||
while(temp != NULL)
|
while(temp != NULL)
|
||||||
{
|
{
|
||||||
@@ -374,6 +375,6 @@ bool list<ItemType>::Contains(ItemType value) const
|
|||||||
temp = temp->next;
|
temp = temp->next;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user