Restructure repository to include all source folders
Move git root from Client/ to src/ to track all source code: - Client: Game client source (moved to Client/Client/) - Server: Game server source - GameTools: Development tools - CryptoSource: Encryption utilities - database: Database scripts - Script: Game scripts - rylCoder_16.02.2008_src: Legacy coder tools - GMFont, Game: Additional resources 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
143
GameTools/ZALLA3D BASECLASS/list.h
Normal file
143
GameTools/ZALLA3D BASECLASS/list.h
Normal file
@@ -0,0 +1,143 @@
|
||||
/*
|
||||
* A generic template list class.
|
||||
* Fairly typical of the list example you would
|
||||
* find in any c++ book.
|
||||
*/
|
||||
#ifndef GENERIC_LIST_H
|
||||
#define GENERIC_LIST_H
|
||||
|
||||
#pragma warning( disable : 4786 )
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
template <class Type> class List {
|
||||
public:
|
||||
List(int s=0);
|
||||
~List();
|
||||
void Insert(Type t,int n);
|
||||
void allocate(int s);
|
||||
void SetSize(int s);
|
||||
void Pack();
|
||||
void Add(Type);
|
||||
void AddUnique(Type);
|
||||
int Contains(Type);
|
||||
void Remove(Type);
|
||||
void DelIndex(int i);
|
||||
Type * element;
|
||||
int num;
|
||||
int array_size;
|
||||
Type &operator[](int i){assert(i>=0 && i<num); return element[i];}
|
||||
};
|
||||
|
||||
|
||||
template <class Type>
|
||||
List<Type>::List(int s){
|
||||
num=0;
|
||||
array_size = 0;
|
||||
element = NULL;
|
||||
if(s) {
|
||||
allocate(s);
|
||||
}
|
||||
}
|
||||
|
||||
template <class Type>
|
||||
List<Type>::~List<Type>(){
|
||||
num=0;
|
||||
delete [] element;
|
||||
}
|
||||
|
||||
template <class Type>
|
||||
void List<Type>::allocate(int s){
|
||||
assert(s>0);
|
||||
assert(s>=num);
|
||||
Type *old = element;
|
||||
array_size =s;
|
||||
element = new Type[array_size];
|
||||
assert(element);
|
||||
for(int i=0;i<num;i++){
|
||||
element[i]=old[i];
|
||||
}
|
||||
if(old)
|
||||
delete [] old;
|
||||
|
||||
}
|
||||
template <class Type>
|
||||
void List<Type>::SetSize(int s){
|
||||
if(s==0) { if(element) delete element;}
|
||||
else { allocate(s); }
|
||||
num=s;
|
||||
}
|
||||
template <class Type>
|
||||
void List<Type>::Pack(){
|
||||
allocate(num);
|
||||
}
|
||||
|
||||
template <class Type>
|
||||
void List<Type>::Add(Type t){
|
||||
assert(num<=array_size);
|
||||
if(num==array_size) {
|
||||
allocate((array_size)?array_size *2:16);
|
||||
}
|
||||
//int i;
|
||||
//for(i=0;i<num;i++) {
|
||||
// dissallow duplicates
|
||||
// assert(element[i] != t);
|
||||
//}
|
||||
element[num++] = t;
|
||||
}
|
||||
|
||||
template <class Type>
|
||||
int List<Type>::Contains(Type t){
|
||||
int i;
|
||||
int count=0;
|
||||
for(i=0;i<num;i++) {
|
||||
if(element[i] == t) count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
template <class Type>
|
||||
void List<Type>::AddUnique(Type t){
|
||||
if(!Contains(t)) Add(t);
|
||||
}
|
||||
|
||||
|
||||
template <class Type>
|
||||
void List<Type>::DelIndex(int i){
|
||||
assert(i<num);
|
||||
num--;
|
||||
while(i<num){
|
||||
element[i] = element[i+1];
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
template <class Type>
|
||||
void List<Type>::Remove(Type t){
|
||||
int i;
|
||||
for(i=0;i<num;i++) {
|
||||
if(element[i] == t) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
DelIndex(i);
|
||||
for(i=0;i<num;i++) {
|
||||
assert(element[i] != t);
|
||||
}
|
||||
}
|
||||
template <class Type>
|
||||
void List<Type>::Insert(Type t,int n){
|
||||
if(num==0)
|
||||
Add(t);
|
||||
else
|
||||
{
|
||||
Add(element[num-1]);
|
||||
for(int i=num-1;i>n;i--)
|
||||
{
|
||||
element[i+1]=element[i];
|
||||
}
|
||||
element[n]=t;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user