Skip to content

Commit

Permalink
Initial revision
Browse files Browse the repository at this point in the history
  • Loading branch information
jtraub committed Feb 11, 2001
1 parent 13a09bb commit b87f2b0
Show file tree
Hide file tree
Showing 59 changed files with 31,309 additions and 0 deletions.
128 changes: 128 additions & 0 deletions alist.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
// START A3HEADER
//
// This source file is part of the Atlantis PBM game program.
// Copyright (C) 1995-1999 Geoff Dunbar
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program, in the file license.txt. If not, write
// to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.
//
// See the Atlantis Project web page for details:
// http://www.prankster.com/project
//
// END A3HEADER
#include "alist.h"

AListElem::~AListElem() {
}

AList::AList() {
list = 0;
lastelem = 0;
num = 0;
}

AList::~AList() {
DeleteAll();
}

void AList::DeleteAll() {
AListElem * temp;
while (list) {
temp = list->next;
delete list;
list = temp;
}
lastelem = 0;
num = 0;
}

void AList::Empty() {
AListElem * temp;
while (list) {
temp = list->next;
list->next = 0;
list = temp;
}
lastelem = 0;
num = 0;
}

void AList::Insert(AListElem * e) {
num ++;
e->next = list;
list = e;
if (!lastelem) lastelem = list;
}

void AList::Add(AListElem * e) {
num ++;
if (list) {
lastelem->next = e;
e->next = 0;
lastelem = e;
} else {
list = e;
e->next = 0;
lastelem = list;
}
}

AListElem * AList::Next(AListElem * e) {
if (!e) return 0;
return e->next;
}

AListElem * AList::First() {
return list;
}

AListElem * AList::Get(AListElem * e) {
AListElem * temp = list;
while (temp) {
if (temp == e) return temp;
temp = temp->next;
}
return 0;
}

char AList::Remove(AListElem * e) {
AListElem * temp = list;
if (!e) return 0;
if (!list) return 0;
if (list==e) {
list=list->next;
num--;
if (lastelem == e) lastelem = 0;
return 1;
}

AListElem * p = list;
temp = list->next;
while (temp) {
if (temp==e) {
p->next = temp->next;
num--;
if (p->next == 0) lastelem = p;
return 1;
}
p=temp;
temp=temp->next;
}
return 0;
}

int AList::Num() {
return num;
}
65 changes: 65 additions & 0 deletions alist.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// START A3HEADER
//
// This source file is part of the Atlantis PBM game program.
// Copyright (C) 1995-1999 Geoff Dunbar
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program, in the file license.txt. If not, write
// to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.
//
// See the Atlantis Project web page for details:
// http://www.prankster.com/project
//
// END A3HEADER
#ifndef ALIST_CLASS
#define ALIST_CLASS

class AListElem;
class AList;

class AListElem {
public:
virtual ~AListElem();

AListElem * next;
};

class AList {
public:
AList();
~AList();
void DeleteAll();
void Empty(); /* Clears the list without deleting members */

AListElem * Get(AListElem *);
char Remove(AListElem *);
void Insert(AListElem *); /* into the front */
void Add(AListElem *); /* to the back */
AListElem * Next(AListElem *);
AListElem * First();
int Num();
private:
AListElem *list;
AListElem *lastelem;
int num;
};

#define forlist(l) AListElem * elem, * _elem2; \
for ( elem=(l)->First(), \
_elem2 = (elem ? (l)->Next(elem) : 0); \
elem; \
elem = _elem2, \
_elem2 = (_elem2 ? ((l)->Next(_elem2)) : 0))

#endif
Loading

0 comments on commit b87f2b0

Please sign in to comment.