home *** CD-ROM | disk | FTP | other *** search
/ Aminet 4 / Aminet 4 - November 1994.iso / aminet / dev / c / appsource.lha / APlusPlus / libsource / List.cxx < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-29  |  3.5 KB  |  181 lines

  1. /******************************************************************************
  2.  **
  3.  **   C++ Class Library for the Amiga© system software.
  4.  **
  5.  **   Copyright (C) 1994 by Armin Vogt  **  EMail: armin@uni-paderborn.de
  6.  **   All Rights Reserved.
  7.  **
  8.  **   $Source: apphome:RCS/libsource/List.cxx,v $
  9.  **   $Revision: 1.8 $
  10.  **   $Date: 1994/08/27 13:21:39 $
  11.  **   $Author: Armin_Vogt $
  12.  **
  13.  ******************************************************************************/
  14.  
  15.  
  16. #include <APlusPlus/exec/List.h>
  17.  
  18.  
  19. static const char rcs_id[] = "$Id: List.cxx,v 1.8 1994/08/27 13:21:39 Armin_Vogt Exp Armin_Vogt $";
  20.  
  21. MinNodeC::MinNodeC()
  22. {
  23.    neutralize();  // allows removing an unattached node
  24. }
  25.  
  26. void MinNodeC::remove()
  27. {
  28.    Remove((Node*)(MinNode*)this);
  29.    neutralize();
  30. }
  31.  
  32.  
  33. MinListC::MinListC()
  34. {
  35.    NewList((List*)(MinList*)this);
  36. }
  37.  
  38. MinNodeC* MinListC::remHead()
  39. {
  40.    MinNodeC* node = (MinNodeC*)RemHead((List*)(MinList*)this);
  41.    if (node) node->neutralize(); return node;
  42. }
  43.  
  44. MinNodeC* MinListC::remTail()
  45. {
  46.    MinNodeC* node = (MinNodeC*)RemTail((List*)(MinList*)this);
  47.    if (node) node->neutralize(); return node;
  48. }
  49.  
  50. void MinListC__Destruct(MinListC* list)
  51.    /* prevents a destructed list object from being used via still existing nodes.
  52.       The nodes within the list are being disconnected from the list.
  53.    */
  54. {
  55.    FOREACHSAFE(MinNodeC,list)
  56.    {
  57.       node->remove();
  58.    }
  59.    NEXTSAFE
  60. }
  61.  
  62. void NodeC::init(BYTE pri, const UBYTE* name, UBYTE type)
  63. {
  64.    ln_Pri = pri;
  65.    ln_Name = (char*)name;
  66.    ln_Type = type;
  67.    neutralize();
  68. }
  69. NodeC::NodeC(BYTE pri, UBYTE type)
  70. {
  71.    init(pri,NULL,type);
  72. }
  73.  
  74. NodeC::NodeC(BYTE pri, const UBYTE* name, UBYTE type)
  75. {
  76.    init(pri,name,type);
  77. }
  78.  
  79. NodeC::NodeC(const UBYTE* name, UBYTE type)
  80. {
  81.    init(0,name,type);
  82. }
  83.  
  84.  
  85. ListC::ListC(UBYTE type)
  86. {
  87.    lh_Type = type;
  88.    NewList((List*)this);
  89. }
  90.  
  91. BOOL MinListC__Member(const MinListC* list,const MinNodeC* find)
  92. {
  93.    FOREACHOF(MinNodeC,list)
  94.       if (node == find) return TRUE;
  95.  
  96.    return FALSE;
  97. }
  98.  
  99. MinNodeC* MinListC__RemoveSafely(MinListC* list,MinNodeC* node)
  100. {
  101.    if(list->member(node))
  102.    {
  103.       node->remove();
  104.    }
  105.  
  106.    return node;
  107. }
  108.  
  109. MinListC* MinNodeC::findList(void) const
  110.    /* check if the node is chained into a list, then run through the list to
  111.       the start nil node that is integrated into the MinList structure and
  112.       return the MinListC object of this structure.
  113.    */
  114. {
  115.    if (isLonelyNode()) return NULL;   // this node is not chained into a list
  116.  
  117.    MinNode* node;
  118.    MinNode* pred;
  119.  
  120.    node = (MinNode*)this;
  121.    while (NULL != (pred = node->mln_Pred))   node = pred;
  122.  
  123.    return (MinListC*)(MinList*)node;
  124. }
  125.  
  126. BOOL MinListC::apply(void* any)
  127.    /* It is safe for a MinNodeC object in the list to delete itself during the apply loop.
  128.    */
  129. {
  130.    FOREACHSAFE(MinNodeC,this)
  131.    {
  132.       if (node->applyMinNodeC(any)==FALSE) return FALSE;
  133.    }
  134.    NEXTSAFE
  135.    return TRUE;   // all nodes have been applied to
  136. }
  137.  
  138. BOOL ListC::apply(void* any)
  139.    /* It is safe for a NodeC object in the list to delete itself during the apply loop.
  140.    */
  141. {
  142.    FOREACHSAFE(NodeC,this)
  143.    {
  144.       if (node->applyNodeC(any)==FALSE) return FALSE;
  145.    }
  146.    NEXTSAFE
  147.  
  148.    return TRUE;   // all nodes have been applied to
  149. }
  150.  
  151. BOOL MinNodeC::applyMinNodeC(void* any)
  152. {
  153.    return FALSE;
  154. } // your subclass should overwrite this
  155.  
  156. BOOL NodeC::applyNodeC(void* any)
  157. {
  158.    return FALSE;
  159. } // your subclass should overwrite this
  160.  
  161. MinListC::~MinListC()
  162. {
  163.    MinListC__Destruct(this);
  164. }
  165.  
  166. MinNodeC::~MinNodeC()
  167. {
  168.    remove();
  169. }
  170.  
  171. ListC::~ListC()
  172. {
  173.    MinListC__Destruct((MinListC*)(MinList*)(List*)this);
  174. }
  175.  
  176. NodeC::~NodeC()
  177. {
  178.    remove();
  179. }
  180.  
  181.