/*
** Objektorientiertes Interface zu den Exec-Listen
**
** Etwas sicherer als 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
*/
#ifndef OOP_EXECLISTS_H
#include "ExecLists.h"
#endif
#ifndef _INCLUDE_PRAGMA_EXEC_LIB_H
#include <pragma/exec_lib.h>
#endif

/********************** class tMinNode *************************************/


tMinNodePtr	tMinNode ::	cleared ()
{
  if (this)
  { succ = 0;
    pred = 0;
  }
  return this;
}

BOOL		tMinNode ::	Is_Anywhere ()
{
  return (BOOL) (succ || pred);
}

tMinNodePtr	tMinNode ::	Remove ()
{ if (this
   && Is_Anywhere() )
  { :: Remove ((struct Node*) this);
    succ = 0;
    pred = 0;
  }
  return this;
}

/********************** class tMinList *************************************/


ULONG		tMinList ::	CountNodes ()
{ register ULONG	 cnt  = -1;
  register tMinNodePtr	node;
  for (node = head; node; node = node-> succ)
    cnt++;		/* wird mindestens 1x ausgeführt! */
  return cnt;
}

tMinNodePtr	tMinList ::	operator [] (ULONG n)
{ register ULONG	cnt  = n;
  register tMinNodePtr	node;
  if (cnt >= 0)
    for (node = head; node-> succ; node = node-> succ)
      if (cnt-- == 0)
	return node;
  return NULL;
}

tMinNodePtr	tMinList ::	RemHead ()
{
  return ( (tMinNodePtr) ::RemHead ((struct List *) this) )
	-> cleared ();
}
tMinNodePtr	tMinList ::	RemTail ()
{
  return ( (tMinNodePtr) ::RemTail ((struct List *) this) )
	-> cleared ();
}

tMinNodePtr	tMinList ::	AddHead (tMinNodePtr a)
{
  if (a)
  { a-> Remove ();
    :: AddHead ((struct List *) this, (struct Node *) a);
  }
  return a;
}
tMinNodePtr	tMinList ::	AddTail (tMinNodePtr a)
{
  if (a)
  { a-> Remove ();
    :: AddTail ((struct List *) this, (struct Node *) a);
  }
  return a;
}
tMinNodePtr	tMinList :: Insert  (tMinNodePtr a, tMinNodePtr Pred)
{
  if (a)
  { a-> Remove ();
    :: Insert ((struct List *) this, (struct Node *) a, (struct Node *) Pred);
  }
  return a;
}


/********************** class tNode ****************************************/

		tNode	::	tNode (char* Name)
{
  type = 0;
  pri = 0;
  name = Name;
}
		tNode	::	tNode (UBYTE t, BYTE p, char* n)
{
  type = t;
  pri = p;
  name = n;
}

/********************** class tList ****************************************/

		tList	::    tList (UBYTE t)
{
  type = t;
  pad = 0;
}

tNodePtr	tList	::    Enqueue (tNodePtr a)
{
  if (a)
  { a-> Remove ();
    :: Enqueue ((struct List *) this, (struct Node *) a);
  }
  return a;
}

/* Diese hier mag cppc nicht als inline - Funktion: */
tNodePtr	tList	::    FindName (char * Name)
{
  return (tNodePtr) :: FindName ((struct List *) this, Name);
}

/* <<<<<<<<<<<<<<<<<<<<<<< TEST-Teil. Bitte löschen! >>>>>>>>>>>>>>>>> */

#include <stream.h>
void NewList(struct List* L)
{
 if (L)
 { L-> lh_Head	= (struct Node*) & L-> lh_Tail;
   L-> lh_Tail	= 0;
   L-> lh_TailPred = (struct Node*) & L-> lh_Head;
 }
}

tList a;
tList b;
tNode i;
main()
{ tList c;
  tNode n;
  tNode m;
  a. AddHead (n);
  b. AddHead (&n);
  c. AddHead (m);
  c. AddHead (i);
  cout << "a: " << a. CountNodes() << '\n';
  cout << "b: " << b. CountNodes() << '\n';
  cout << "c: " << c. CountNodes() << '\n';
}

