/******************************************************************************
 **
 **	C++ Class Library for the Amiga© system software.
 **
 **	Copyright (C) 1994 by Armin Vogt  **  EMail: armin@uni-paderborn.de
 **	All Rights Reserved.
 **
 **	$Source: apphome:APlusPlus/RCS/libsource/List.cxx,v $
 **	$Revision: 1.3 $
 **	$Date: 1994/04/23 21:01:51 $
 **	$Author: Armin_Vogt $
 **
 ******************************************************************************/


#include <APlusPlus/exec/List.h>


volatile static char rcs_id[] = "$Id: List.cxx,v 1.3 1994/04/23 21:01:51 Armin_Vogt Exp Armin_Vogt $";


void MinListC__Destruct(MinListC *list)
   /* prevents a destructed list object from being used via still existing nodes.
      The nodes within the list are being disconnected from the list.
   */
{
   FOREACHSAFE(MinNodeC,list)
   {
      node->remove();
   }
   NEXTSAFE
}

BOOL MinListC__Member(MinListC *list,MinNodeC *find)
{
   FOREACHOF(MinNodeC,list)
      if (node == find) return TRUE;

   return FALSE;
}

MinNodeC *MinListC__RemoveSafely(MinListC *list,MinNodeC *node)
{
   if(list->member(node))
   {
      node->remove();
   }

   return node;
}

MinListC *MinNodeC::findList(void)
   /* check if the node is chained into a list, then run through the list to
      the start nil node that is integrated into the MinList structure and
      return the MinListC object of this structure.
   */
{
   if (isLonelyNode()) return NULL;   // this node is not chained into a list

   MinNode *node,*pred;
   node = (MinNode*)this;
   while (NULL != (pred = node->mln_Pred))   node = pred;
   return (MinListC*)(MinList*)node;
}

BOOL MinListC::apply(void *any)
   /* It is safe for a MinNodeC object in the list to delete itself during the apply loop.
   */
{
   FOREACHSAFE(MinNodeC,this)
   {
      if (node->applyMinNodeC(any)==FALSE) return FALSE;
   }
   NEXTSAFE
   return TRUE;   // all nodes have been applied to
}

BOOL ListC::apply(void *any)
   /* It is safe for a NodeC object in the list to delete itself during the apply loop.
   */
{
   FOREACHSAFE(NodeC,this)
   {
      if (node->applyNodeC(any)==FALSE) return FALSE;
   }
   NEXTSAFE

   return TRUE;   // all nodes have been applied to
}

BOOL MinNodeC::applyMinNodeC(void *any)
{ 
   return FALSE; 
} // your subclass should overwrite this

BOOL NodeC::applyNodeC(void *any) 
{ 
   return FALSE; 
} // your subclass should overwrite this

MinListC::~MinListC()
{ 
   MinListC__Destruct(this);
}

MinNodeC::~MinNodeC()
{ 
	remove(); 
}
        
ListC::~ListC() 
{ 
   MinListC__Destruct((MinListC*)(MinList*)(List*)this); 
}

NodeC::~NodeC() 
{ 
	remove(); 
}

