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)
|
||||
|
||||
typedef unsigned int LIST_ARRAY_INDEX_TYPE;
|
||||
namespace OpenArena{
|
||||
typedef unsigned int LIST_ARRAY_INDEX_TYPE;
|
||||
|
||||
template <class ItemType>
|
||||
class listNode
|
||||
{
|
||||
public:
|
||||
template <class ItemType>
|
||||
class listNode
|
||||
{
|
||||
public:
|
||||
listNode();
|
||||
ItemType data;
|
||||
listNode<ItemType>* next;
|
||||
};
|
||||
};
|
||||
|
||||
template <class ItemType>
|
||||
class list
|
||||
{
|
||||
public:
|
||||
template <class ItemType>
|
||||
class list
|
||||
{
|
||||
public:
|
||||
list();
|
||||
~list();
|
||||
list(const list&);
|
||||
@@ -43,29 +44,29 @@ public:
|
||||
ItemType operator[](LIST_ARRAY_INDEX_TYPE) const;
|
||||
ItemType& operator[](LIST_ARRAY_INDEX_TYPE);
|
||||
|
||||
private:
|
||||
private:
|
||||
listNode<ItemType>* head;
|
||||
listNode<ItemType>* tail;
|
||||
listNode<ItemType>* currPos;
|
||||
};
|
||||
};
|
||||
|
||||
template <class ItemType>
|
||||
listNode<ItemType>::listNode()
|
||||
{
|
||||
template <class ItemType>
|
||||
listNode<ItemType>::listNode()
|
||||
{
|
||||
next = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
template <class ItemType>
|
||||
list<ItemType>::list()
|
||||
{
|
||||
template <class ItemType>
|
||||
list<ItemType>::list()
|
||||
{
|
||||
head = NULL;
|
||||
tail = NULL;
|
||||
currPos = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
template <class ItemType>
|
||||
list<ItemType>::~list()
|
||||
{
|
||||
template <class ItemType>
|
||||
list<ItemType>::~list()
|
||||
{
|
||||
currPos = NULL;
|
||||
while(head != NULL)
|
||||
{
|
||||
@@ -74,28 +75,28 @@ list<ItemType>::~list()
|
||||
delete tail;
|
||||
tail = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <class ItemType>
|
||||
list<ItemType>::list(const list<ItemType>& rtOp)
|
||||
{
|
||||
template <class ItemType>
|
||||
list<ItemType>::list(const list<ItemType>& rtOp)
|
||||
{
|
||||
head = NULL;
|
||||
tail = NULL;
|
||||
currPos = NULL;
|
||||
|
||||
operator=(rtOp);
|
||||
}
|
||||
}
|
||||
|
||||
template <class ItemType>
|
||||
void list<ItemType>::Clear()
|
||||
{
|
||||
template <class ItemType>
|
||||
void list<ItemType>::Clear()
|
||||
{
|
||||
while(head)
|
||||
Remove(head->data);
|
||||
}
|
||||
}
|
||||
|
||||
template <class ItemType>
|
||||
void list<ItemType>::operator=(const list<ItemType>& rtOp)
|
||||
{
|
||||
template <class ItemType>
|
||||
void list<ItemType>::operator=(const list<ItemType>& rtOp)
|
||||
{
|
||||
Clear();
|
||||
|
||||
if(!rtOp.IsEmpty())
|
||||
@@ -121,23 +122,23 @@ void list<ItemType>::operator=(const list<ItemType>& rtOp)
|
||||
|
||||
tail = temp2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <class ItemType>
|
||||
bool list<ItemType>::IsEmpty() const
|
||||
{
|
||||
template <class ItemType>
|
||||
bool list<ItemType>::IsEmpty() const
|
||||
{
|
||||
return head == NULL;
|
||||
}
|
||||
}
|
||||
|
||||
template <class ItemType>
|
||||
bool list<ItemType>::IsFull() const
|
||||
{
|
||||
template <class ItemType>
|
||||
bool list<ItemType>::IsFull() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
template <class ItemType>
|
||||
void list<ItemType>::Insert(ItemType newItem)
|
||||
{
|
||||
template <class ItemType>
|
||||
void list<ItemType>::Insert(ItemType newItem)
|
||||
{
|
||||
listNode<ItemType>* temp = head;
|
||||
listNode<ItemType>* temp2 = NULL;
|
||||
|
||||
@@ -174,11 +175,11 @@ void list<ItemType>::Insert(ItemType newItem)
|
||||
{
|
||||
tail = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <class ItemType>
|
||||
void list<ItemType>::Remove(ItemType target)
|
||||
{
|
||||
template <class ItemType>
|
||||
void list<ItemType>::Remove(ItemType target)
|
||||
{
|
||||
if(head != NULL)
|
||||
{
|
||||
listNode<ItemType>* temp = head;
|
||||
@@ -206,11 +207,11 @@ void list<ItemType>::Remove(ItemType target)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <class ItemType>
|
||||
bool list<ItemType>::PrevPosition()
|
||||
{
|
||||
template <class ItemType>
|
||||
bool list<ItemType>::PrevPosition()
|
||||
{
|
||||
if(currPos != head)
|
||||
{
|
||||
tail->next = currPos;
|
||||
@@ -232,11 +233,11 @@ bool list<ItemType>::PrevPosition()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <class ItemType>
|
||||
bool list<ItemType>::NextPosition()
|
||||
{
|
||||
template <class ItemType>
|
||||
bool list<ItemType>::NextPosition()
|
||||
{
|
||||
if(currPos != tail)
|
||||
{
|
||||
currPos = currPos->next;
|
||||
@@ -246,11 +247,11 @@ bool list<ItemType>::NextPosition()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <class ItemType>
|
||||
void list<ItemType>::Remove()
|
||||
{
|
||||
template <class ItemType>
|
||||
void list<ItemType>::Remove()
|
||||
{
|
||||
if(currPos != NULL)
|
||||
{
|
||||
tail->next = currPos;
|
||||
@@ -259,42 +260,42 @@ void list<ItemType>::Remove()
|
||||
tail->next = NULL;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
template <class ItemType>
|
||||
ItemType list<ItemType>::Retrieve() const
|
||||
{
|
||||
template <class ItemType>
|
||||
ItemType list<ItemType>::Retrieve() const
|
||||
{
|
||||
if(currPos != NULL)
|
||||
return currPos->data;
|
||||
}
|
||||
}
|
||||
|
||||
template <class ItemType>
|
||||
bool list<ItemType>::IsFirstPosition() const
|
||||
{
|
||||
template <class ItemType>
|
||||
bool list<ItemType>::IsFirstPosition() const
|
||||
{
|
||||
return currPos == head;
|
||||
}
|
||||
}
|
||||
|
||||
template <class ItemType>
|
||||
bool list<ItemType>::IsLastPosition() const
|
||||
{
|
||||
template <class ItemType>
|
||||
bool list<ItemType>::IsLastPosition() const
|
||||
{
|
||||
return currPos == tail;
|
||||
}
|
||||
}
|
||||
|
||||
template <class ItemType>
|
||||
void list<ItemType>::FirstPosition()
|
||||
{
|
||||
template <class ItemType>
|
||||
void list<ItemType>::FirstPosition()
|
||||
{
|
||||
currPos = head;
|
||||
}
|
||||
}
|
||||
|
||||
template <class ItemType>
|
||||
void list<ItemType>::LastPosition()
|
||||
{
|
||||
template <class ItemType>
|
||||
void list<ItemType>::LastPosition()
|
||||
{
|
||||
currPos = tail;
|
||||
}
|
||||
}
|
||||
|
||||
template <class ItemType>
|
||||
ItemType list<ItemType>::operator[](LIST_ARRAY_INDEX_TYPE index) const
|
||||
{
|
||||
template <class ItemType>
|
||||
ItemType list<ItemType>::operator[](LIST_ARRAY_INDEX_TYPE index) const
|
||||
{
|
||||
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.
|
||||
@@ -314,11 +315,11 @@ ItemType list<ItemType>::operator[](LIST_ARRAY_INDEX_TYPE index) const
|
||||
}
|
||||
return temp->data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <class ItemType>
|
||||
ItemType& list<ItemType>::operator[](LIST_ARRAY_INDEX_TYPE index)
|
||||
{
|
||||
template <class ItemType>
|
||||
ItemType& list<ItemType>::operator[](LIST_ARRAY_INDEX_TYPE index)
|
||||
{
|
||||
if(head == NULL)
|
||||
{
|
||||
tail = currPos = head = new listNode<ItemType>;
|
||||
@@ -339,11 +340,11 @@ ItemType& list<ItemType>::operator[](LIST_ARRAY_INDEX_TYPE index)
|
||||
}
|
||||
return (ItemType&)(temp->data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <class ItemType>
|
||||
unsigned int list<ItemType>::Length()
|
||||
{
|
||||
template <class ItemType>
|
||||
unsigned int list<ItemType>::Length()
|
||||
{
|
||||
if (head == NULL)
|
||||
{
|
||||
return 0;
|
||||
@@ -359,11 +360,11 @@ unsigned int list<ItemType>::Length()
|
||||
}
|
||||
return len;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<class ItemType>
|
||||
bool list<ItemType>::Contains(ItemType value) const
|
||||
{
|
||||
template<class ItemType>
|
||||
bool list<ItemType>::Contains(ItemType value) const
|
||||
{
|
||||
listNode<ItemType>* temp = head;
|
||||
while(temp != NULL)
|
||||
{
|
||||
@@ -374,6 +375,6 @@ bool list<ItemType>::Contains(ItemType value) const
|
||||
temp = temp->next;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user