/*
** Objektorientiertes Interface zu den Exec-Listen
**
** Etwas sicherer als normale Exec-Listen, da Remove() succ und pred löscht!
**
** (C) 1992 Christian Spreuer. Alle Rechte vorbehalten.
** insbesondere ist diese Datei NICHT Public-Domain!
**
** 17.6.1992: Erzeugt
** 20.6.1992: Getestet, NewList eingeführt
*/
#ifndef OOP_EXECLISTS_H
#define OOP_EXECLISTS_H

#ifndef EXEC_LISTS_H
#include <exec/lists.h>
#endif

/* <<<<<<<<<<<<<< BEGIN TEMPORARY >>>>>>>>>>>>> */
/* Hallo Jens!
** Diese Funktion fehlt noch in der Library, und somit in den Includes:
*/
extern	void NewList (struct List *);
/*  move.l  4(sp),a0
/*;    move.l  a0,d0 ; wer's ganz korrekt haben will...
/*;    beq.s   failed
/*  lea     4(a0),a1
/*  move.l  a1,(a0)  ; head = & tail;
/*  clr.l   (a1)     ; tail = 0;
/*  move.l  a0,8(a0) ; tailpred = &head;
/*failed:
/*  rts
/*
/**/
/* <<<<<<<<<<<<<< END TEMPORARY >>>>>>>>>>>>>>> */

/* Hier werden folgende Klassen deklariert: */
typedef class tMinNode *tMinNodePtr;
typedef class tMinList *tMinListPtr;
typedef class tNode    *tNodePtr;
typedef class tList    *tListPtr;

/* aus Kompatibilitätsgründen ist hier nichts "virtual" */

class tMinNode {
	friend class tMinList;

	tMinNodePtr	succ;
	tMinNodePtr	pred;
	tMinNodePtr	cleared ();

public:
			tMinNode ()     { cleared (); }
			~tMinNode ()    { Remove (); }
	tMinNodePtr	Succ()          { return succ; }
	tMinNodePtr	Pred()          { return pred; }
	tMinNodePtr	Remove ();
	BOOL		Is_Anywhere (); /* Befindet sich this in einer Liste? */
};

class tMinList {
	tMinNodePtr	head;
	tMinNodePtr	tail;
	tMinNodePtr	tailpred;
public:
			tMinList ()     { :: NewList ((struct List *) this); }
			~tMinList ()    { while (RemHead ()); }
	BOOL		Is_Empty ()     { return tailpred == (tMinNodePtr) & head; }
	ULONG		CountNodes ();  /* Anzahl der Elemente */
	tMinNodePtr	Head ()         { return head; }
	tMinNodePtr	Tail ()         { return tail; }
	tMinNodePtr	operator [] (ULONG n); /* N-tes Element in der Liste (Erstes ist Index 0) */

	tMinNodePtr	RemHead ();
	tMinNodePtr	RemTail ();

	tMinNodePtr	AddHead (tMinNodePtr);
	tMinNodePtr	AddTail (tMinNodePtr);
	tMinNodePtr	AddHead (tMinNode & a) { return AddHead (&a); }
	tMinNodePtr	AddTail (tMinNode & a) { return AddTail (&a); }
	tMinNodePtr	Insert	(tMinNodePtr, tMinNodePtr Pred);
};

class tNode : public tMinNode {
	UBYTE		type;
	BYTE		pri;		/* Priority, for sorting */
	char		*name;		/* ID string, null terminated */
public:
	LONG		Type()                          { return type; }
	LONG		Pri()                           { return pri;  }
	char*		Name()                          { return name;  }
			tNode (char* Name = 0);
			tNode (UBYTE t, BYTE p=0, char* n=0);
			~tNode () {}
}; /* Note: still word aligned */

class tList : public tMinList {
	UBYTE		type;
	UBYTE		pad;
public:
			tList (UBYTE t=0);
			~tList() {}
	LONG		Type()                          { return type; }
	tNodePtr	Enqueue (tNodePtr);
/* Diese hier mag cppc nicht als inline - Funktion: */
	tNodePtr	FindName (char* Name); /*  { return (tNodePtr) :: FindName ((struct List *) this, Name); } */
}; /* Note: still word aligned */

#endif /* OOP_EXECLISTS_H */

