examples/Makefile.am, examples/Makefile.def, examples/adder/Makefile.am, examples/calculator/Makefile.am, examples/cmilner/Makefile.am, examples/fdd/Makefile.am, examples/internal/Makefile.am, examples/milner/Makefile.am, examples/money/Makefile.am, examples/queen/Makefile.am, examples/solitar/Makefile.am, m4/debug.m4, m4/gccwarns.m4, ChangeLog, INSTALL: New files. * config, makefile, src/makefile, doc/makefile, examples/adder/makefile, examples/calculator/makefile examples/cmilner/makefile, examples/fdd/makefile, examples/internal/makefile, examples/milner/makefile, examples/money/makefile, examples/queen/makefile, examples/solitare/makefile : Delete. * examples/adder/adder.cxx, examples/fdd/statespace.cxx, examples/internal/bddtest.cxx, examples/milner/milner.cxx, examples/money/money.cxx, examples/queen/queen.cxx, examples/solitare/solitare.cxx: Include iostream. * examples/calculator/parser.y: Rename as ... * examples/calculator/parser.yxx: ... this. Remove spurious comas in %token, %right, and %left arguments. * examples/calculator/parser.h: Rename as ... * examples/calculator/parser_.h: ... this, because the bison rule with output parser.h (not tokens.h) from parser.y. * examples/calculator/lexer.l: Rename as ... * examples/calculator/lexer.lxx: ... this. Include parser.h instead of tokens.h. * examples/calculator/slist.h (voidSList::voisSListElem, SList::ite): Fix friend usage. * src/kernel.h (DEFAULT_CLOCK): Default to 60 if not already defined. * README: Update build instruction, and file listing.
235 lines
4.9 KiB
C++
235 lines
4.9 KiB
C++
/*************************************************************************
|
|
$Header: /Volumes/CVS/repository/spot/spot/buddy/examples/calculator/Attic/slist.h,v 1.2 2003/05/05 13:44:55 aduret Exp $
|
|
FILE: slist.h
|
|
DESCR: Single linked list
|
|
AUTH: Jorn Lind
|
|
DATE: (C)
|
|
*************************************************************************/
|
|
|
|
#ifndef _SLIST_H
|
|
#define _SLIST_H
|
|
|
|
#include <string.h>
|
|
|
|
|
|
/* === Base void list ==================================================*/
|
|
|
|
class voidSList;
|
|
|
|
class voidSList
|
|
{
|
|
protected:
|
|
class voidSListElem
|
|
{
|
|
public:
|
|
void *data;
|
|
voidSListElem *next;
|
|
~voidSListElem(void) { delete next; }
|
|
|
|
private:
|
|
voidSListElem(void *d) { data=d; next=NULL; }
|
|
friend class voidSList;
|
|
};
|
|
|
|
public:
|
|
voidSList(void) { head=tail=NULL; len=0; }
|
|
~voidSList(void) { delete head; }
|
|
void *append(void *);
|
|
void *append(voidSListElem *p, void *d);
|
|
void *insert(void *);
|
|
int size(void) const { return len; }
|
|
int empty(void) const { return len==0; }
|
|
void reverse(void);
|
|
void eraseHead(void);
|
|
void eraseAll(void) { delete head; head=tail=NULL; len=0; }
|
|
|
|
protected:
|
|
int len;
|
|
voidSListElem *head, *tail;
|
|
};
|
|
|
|
|
|
#ifdef IMPLEMENTSLIST
|
|
|
|
void *voidSList::append(void *d)
|
|
{
|
|
voidSListElem *elem = new voidSListElem(d);
|
|
|
|
if (tail)
|
|
tail->next = elem;
|
|
else
|
|
head = elem;
|
|
|
|
tail = elem;
|
|
len++;
|
|
|
|
return elem->data;
|
|
}
|
|
|
|
|
|
void *voidSList::append(voidSListElem *p, void *d)
|
|
{
|
|
voidSListElem *elem = new voidSListElem(d);
|
|
|
|
if (p)
|
|
{
|
|
elem->next = p->next;
|
|
p->next = elem;
|
|
if (p == tail)
|
|
tail = p->next;
|
|
}
|
|
else
|
|
{
|
|
if (tail)
|
|
tail->next = elem;
|
|
else
|
|
head = elem;
|
|
tail = elem;
|
|
}
|
|
|
|
len++;
|
|
|
|
return elem->data;
|
|
}
|
|
|
|
|
|
void *voidSList::insert(void *d)
|
|
{
|
|
voidSListElem *elem = new voidSListElem(d);
|
|
|
|
if (tail == NULL)
|
|
tail = elem;
|
|
|
|
elem->next = head;
|
|
head = elem;
|
|
len++;
|
|
|
|
return elem->data;
|
|
}
|
|
|
|
|
|
void voidSList::reverse(void)
|
|
{
|
|
voidSListElem *newTail = head;
|
|
voidSListElem *tmpHead = NULL;
|
|
|
|
if (len < 2)
|
|
return ;
|
|
|
|
while (head != NULL)
|
|
{
|
|
voidSListElem *tmpNext = head->next;
|
|
|
|
head->next = tmpHead;
|
|
tmpHead = head;
|
|
|
|
head = tmpNext;
|
|
}
|
|
|
|
tail = newTail;
|
|
head = tmpHead;
|
|
}
|
|
|
|
|
|
void voidSList::eraseHead(void)
|
|
{
|
|
if (head != NULL)
|
|
{
|
|
head = head->next;
|
|
if (head == NULL)
|
|
tail = NULL;
|
|
len--;
|
|
}
|
|
}
|
|
|
|
#endif /* IMPLEMENTSLIST */
|
|
|
|
|
|
/* === Base void list ==================================================*/
|
|
|
|
//sorting
|
|
|
|
template <class T>
|
|
class SList : private voidSList
|
|
{
|
|
public:
|
|
class ite
|
|
{
|
|
public:
|
|
ite(void) { next=NULL; }
|
|
ite(const ite &start) { next=start.next;}
|
|
ite(voidSListElem *start) { next=start; }
|
|
int more(void) const { return next!=NULL; }
|
|
ite &operator=(const ite &start) { next=start.next; return *this; }
|
|
ite operator++(void)
|
|
{ if (next) next=next->next; return *this; }
|
|
ite operator++(int)
|
|
{ ite tmp=*this; if (next) next=next->next; return tmp; }
|
|
T &operator*(void) const { return *((T*)next->data); }
|
|
int operator==(ite x) { return x.next==next; }
|
|
private:
|
|
voidSListElem *next;
|
|
friend class SList<T>;
|
|
};
|
|
|
|
~SList(void) { for (ite x=first() ; x.more() ; x++) delete &(*x); }
|
|
T &append(const T &d) { return *((T*)voidSList::append(new T(d))); }
|
|
T &insert(const T &d) { return *((T*)voidSList::insert(new T(d))); }
|
|
T &head(void) const { return *((T*)voidSList::head->data); }
|
|
T &tail(void) const { return *((T*)voidSList::tail->data); }
|
|
ite first(void) const { return ite(voidSList::head); }
|
|
int empty(void) const { return voidSList::empty(); }
|
|
int size(void) const { return voidSList::size(); }
|
|
void reverse(void) { voidSList::reverse(); }
|
|
void filter(int (*)(T&));
|
|
void append(SList<T> &l)
|
|
{ for (ite x=l.first() ; x.more() ; x++) append(*x); }
|
|
T &append(ite &i, const T &d)
|
|
{ return *((T*)voidSList::append(i.next, new T(d))); }
|
|
void eraseHead(void)
|
|
{ delete ((T*)voidSList::head->data); voidSList::eraseHead(); }
|
|
void eraseAll(void)
|
|
{ for (ite x=first() ; x.more() ; x++) delete &(*x); voidSList::eraseAll();}
|
|
void map(void (*f)(T&))
|
|
{ for (ite x=first() ; x.more() ; x++) f(*x); }
|
|
};
|
|
|
|
|
|
template <class T>
|
|
void SList<T>::filter(int (*f)(T&))
|
|
{
|
|
voidSListElem *prev=NULL, *next=voidSList::head;
|
|
|
|
while (next)
|
|
{
|
|
if (f(*((T*)next->data)))
|
|
{
|
|
prev = next;
|
|
next = next->next;
|
|
}
|
|
else
|
|
{
|
|
voidSListElem *n = next->next;
|
|
|
|
if (prev == NULL)
|
|
voidSList::head = next->next;
|
|
else
|
|
prev->next = next->next;
|
|
if (voidSList::head == NULL)
|
|
voidSList::tail = NULL;
|
|
|
|
delete next->data;
|
|
next->next = NULL;
|
|
delete next;
|
|
|
|
next = n;
|
|
len--;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
#endif /* _SLIST_H */
|
|
|
|
|
|
/* EOF */
|