home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tlx501.zip / SRC / DLINK.CPP < prev    next >
C/C++ Source or Header  |  1996-07-08  |  4KB  |  146 lines

  1. /****************************************************************************
  2.     $Id: dlink.cpp 501.0 1995/03/07 12:26:12 RON Exp $
  3.  
  4.     Copyright (c) 1991-95 Tarma Software Research. All rights reserved.
  5.  
  6.     Project:    Tarma Library for C++ V5.0
  7.     Author:    Ron van der Wal
  8.  
  9.     Implementation of class TLDLink. This class represents an element in the
  10.     various list structures. Its member functions are geared towards linear
  11.     list implementations, so a circular list implementation must take some
  12.     extra care.
  13.  
  14.     $Log: dlink.cpp $
  15.     Revision 501.0  1995/03/07 12:26:12  RON
  16.     Updated for TLX 5.01
  17.     Revision 1.7  1995/01/31 16:30:10  RON
  18.     Update for release 012
  19.     Added partial support for SunPro C++ compiler
  20.     Revision 1.6  1995/01/06  15:57:39  ron
  21.     Corrected Revision keyword
  22.  
  23.     Revision 1.5  1994/11/16  15:38:37  ron
  24.     Added module info; rearranged #include directives
  25.  
  26.     Revision 1.4  1994/09/28  14:17:12  ron
  27.     Removed Macintosh-style #include references
  28.  
  29.     Revision 1.3  1994/09/27  20:22:16  ron
  30.     Changed path separator from / to \
  31.  
  32.     Revision 1.2  1994/09/26  15:41:51  ron
  33.     Changed include file references
  34.  
  35.     Revision 1.1  1994/08/16  18:12:59  ron
  36.     Initial revision
  37.  
  38. ****************************************************************************/
  39.  
  40. #include <tlx\501\_build.h>
  41.  
  42. TLX_MODULE_INFO("$Revision: 501.0 $");
  43.  
  44. #include <tlx\501\dlists.h>        // Class declaration
  45.  
  46. /*-------------------------------------------------------------------------*/
  47.     TLDLink::TLDLink()
  48.  
  49. /*  Default constructor. Sets both link fields to 0.
  50. ---------------------------------------------------------------------------*/
  51. : mNext(0), mPrev(0)
  52. {
  53. }
  54.  
  55. /*-------------------------------------------------------------------------*/
  56.     TLDLink::TLDLink(const TLDLink &)
  57.  
  58. /*  Copy constructor. Does not copy the link fields, but sets them to 0.
  59. ---------------------------------------------------------------------------*/
  60. : mNext(0), mPrev(0)
  61. {
  62. }
  63.  
  64. /*-------------------------------------------------------------------------*/
  65.     TLDLink::~TLDLink()
  66.  
  67. /*  Destructor. Makes sure that the instance is unlinked from its
  68.     neighbours.
  69. ---------------------------------------------------------------------------*/
  70. {
  71.     Unlink();
  72. }
  73.  
  74. /*-------------------------------------------------------------------------*/
  75.     void TLDLink::Append(TLDLink *aLink)
  76.  
  77. /*  Inserts 'aLink' after the current TLDLink. The current TLDLink must be
  78.     part of a chain, and 'aLink' must not currently be linked. It is an
  79.     error to pass a 0 pointer.
  80. ---------------------------------------------------------------------------*/
  81. {
  82.     TLX_ASSERT_PTR(aLink);
  83.     TLX_ASSERT_NULL(aLink->mNext);
  84.     TLX_ASSERT_NULL(aLink->mPrev);
  85.  
  86.     aLink->mNext = mNext;
  87.     aLink->mPrev = this;
  88.     if (mNext)
  89.     {
  90.     TLX_ASSERT(mNext->mPrev == this);
  91.     mNext->mPrev = aLink;
  92.     }
  93.     mNext = aLink;
  94. }
  95.  
  96. /*-------------------------------------------------------------------------*/
  97.     TLDLink &TLDLink::operator =(const TLDLink &)
  98.  
  99. /*  Overloading of the assignment operator. Does not copy the link fields.
  100. ---------------------------------------------------------------------------*/
  101. {
  102.     return *this;
  103. }
  104.  
  105. /*-------------------------------------------------------------------------*/
  106.     void TLDLink::Prepend(TLDLink *aLink)
  107.  
  108. /*  Inserts another link before the current one. The TLDLink instance
  109.     to be inserted must not currently be part of a chain. Also, it is
  110.     an error to pass a 0 pointer.
  111. ---------------------------------------------------------------------------*/
  112. {
  113.     TLX_ASSERT_PTR(aLink);
  114.     TLX_ASSERT_NULL(aLink->mNext);
  115.     TLX_ASSERT_NULL(aLink->mPrev);
  116.  
  117.     aLink->mNext = this;
  118.     aLink->mPrev = mPrev;
  119.     if (mPrev)
  120.     {
  121.     TLX_ASSERT(mPrev->mNext == this);
  122.     mPrev->mNext = aLink;
  123.     }
  124.     mPrev = aLink;
  125. }
  126.  
  127. /*-------------------------------------------------------------------------*/
  128.     void TLDLink::Unlink()
  129.  
  130. /*  Removes the current TLDLink from the list of which it is part.
  131. ---------------------------------------------------------------------------*/
  132. {
  133.     if (mNext)
  134.     {
  135.     TLX_ASSERT(mNext->mPrev == this);
  136.     mNext->mPrev = mPrev;
  137.     }
  138.     if (mPrev)
  139.     {
  140.     TLX_ASSERT(mPrev->mNext == this);
  141.     mPrev->mNext = mNext;
  142.     }
  143.     mNext = mPrev = 0;
  144. }
  145.  
  146.