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

  1. /****************************************************************************
  2.     $Id: domelem.cpp 501.0 1995/03/07 12:26:14 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 TLDomainElement.
  10.  
  11.     $Log: domelem.cpp $
  12.     Revision 501.0  1995/03/07 12:26:14  RON
  13.     Updated for TLX 5.01
  14.     Revision 1.8  1995/02/28 15:11:20  RON
  15.     Update for release 012
  16.     Added partial support for SunPro C++ compiler
  17.     Revision 1.7  1995/01/06  15:57:44  ron
  18.     Corrected Revision keyword
  19.  
  20.     Revision 1.6  1994/11/16  15:39:08  ron
  21.     Added module info; rearranged #include directives
  22.  
  23.     Revision 1.5  1994/10/10  16:49:51  ron
  24.     Changed to <tlx\solve\ac6.h>
  25.  
  26.     Revision 1.4  1994/09/28  14:17:49  ron
  27.     Removed Macintosh-style #include references
  28.  
  29.     Revision 1.3  1994/09/27  20:22:23  ron
  30.     Changed path separator from / to \
  31.  
  32.     Revision 1.2  1994/09/26  15:42:34  ron
  33.     Changed include file references
  34.  
  35.     Revision 1.1  1994/08/16  18:13:02  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\solve\ac6.h>
  45.  
  46. /*---------------------------------------------------------------------------
  47.     Template source code
  48. ---------------------------------------------------------------------------*/
  49.  
  50. #if defined(THINK_CPLUS)
  51.     #include "assoc.cpp"
  52.     #include "pointer.cpp"
  53.     #pragma template_access public
  54.     #pragma template TLAssoc<tVarValue, TLSupportPtr>
  55. #elif defined(__BORLANDC__) || defined(_MSC_VER) || defined(__SC__) || defined(__WATCOMC__)
  56.     #include <tlx\501\template\assoc.cpp>
  57.     #include <tlx\501\template\pointer.cpp>
  58. #elif defined(__SUNPRO_CC)
  59.     #include <tlx\501\template\assoc.cpp>
  60.     #include <tlx\501\template\pointer.cpp>
  61. #elif defined(__IBMCPP__)
  62.   #if __IBMCPP__ < 300
  63.     #pragma implementation("tlx\\template\\assoc.cpp")
  64.     #pragma implementation("tlx\\template\\pointer.cpp")
  65.   #else
  66.     #include <tlx\501\template\assoc.cpp>
  67.     #include <tlx\501\template\pointer.cpp>
  68.   #endif
  69. #else
  70.     #error Unsupported compiler; contact Tarma Software Research
  71. #endif
  72.  
  73. /*-------------------------------------------------------------------------*/
  74.     TLDomainElement::TLDomainElement(tVarValue aValue)
  75.  
  76. /*  Constructor, also doubles as default constructor.
  77. ---------------------------------------------------------------------------*/
  78. : TLAssoc<tVarValue, TLSupportPtr>(aValue, 0)
  79. {
  80.     SupportList() = new TLSupportList;
  81.     SupportList()->BecomeOwner();
  82. }
  83.  
  84. /*-------------------------------------------------------------------------*/
  85.     void TLDomainElement::AddSupport(const VV_Assoc &aVV)
  86.  
  87. /*  Adds the given variable/value pair to the support list of the domain
  88.     element.
  89. ---------------------------------------------------------------------------*/
  90. {
  91.     TLX_ASSERT_PTR((TLSupportList *)SupportList());
  92.  
  93. #ifdef _TLXDBG
  94.     TLVarValueLink *vvlink = new TLVarValueLink(aVV);
  95.     TLX_ASSERT_PTR(vvlink);
  96.     SupportList()->Append(vvlink);
  97. #else
  98.     SupportList()->Append(new TLVarValueLink(aVV));
  99. #endif
  100. }
  101.  
  102. /*-------------------------------------------------------------------------*/
  103.     void TLDomainElement::ClearSupport()
  104.  
  105. /*  Clears the entire support list of the domain element.
  106. ---------------------------------------------------------------------------*/
  107. {
  108.     TLX_ASSERT_PTR((TLSupportList *)SupportList());
  109.     SupportList()->RemoveAll();
  110. }
  111.  
  112. /*-------------------------------------------------------------------------*/
  113.     bool TLDomainElement::NextIter(iter_t &aIter)
  114.  
  115. /*  Advances the iterator in the support list, returning nonzero if it
  116.     is still valid after the operation.
  117. ---------------------------------------------------------------------------*/
  118. {
  119.     TLVarValueLink *vvlink = (TLVarValueLink *)aIter.ptr;
  120.     TLX_ASSERT_PTR(vvlink);
  121.  
  122. #ifdef _TLXDBG
  123.     // Check that the passed-in iterator really does point into the
  124.     // support list.
  125.  
  126.     TLX_ASSERT_PTR((TLSupportList *)SupportList());
  127.     TLVarValueLink *rover;
  128.  
  129.     for (rover = SupportList()->PeekHead(); rover;
  130.      rover = (TLVarValueLink *)rover->Next())
  131.     {
  132.     if (*rover == *vvlink)
  133.         break;
  134.     }
  135.  
  136.     TLX_ASSERT_PTR(rover);
  137. #endif
  138.  
  139.     aIter.ptr = vvlink->Next();
  140.     return aIter.ptr != 0;
  141. }
  142.  
  143. /*-------------------------------------------------------------------------*/
  144.     TLDomainElement &TLDomainElement::operator =(const TLDomainElement &aEl)
  145.  
  146. /*  Overloading of the assignment operator.
  147. ---------------------------------------------------------------------------*/
  148. {
  149.     if (this != &aEl)
  150.     {
  151.     Key()   = aEl.Key();
  152.     Value() = aEl.Value();
  153.     }
  154.     return *this;
  155. }
  156.  
  157. /*-------------------------------------------------------------------------*/
  158.     const TLVarValueLink *TLDomainElement::PeekIter(const iter_t &aIter) const
  159.  
  160. /*  Returns a reference to the element to which the iterator points.
  161. ---------------------------------------------------------------------------*/
  162. {
  163.     TLVarValueLink *vvlink = (TLVarValueLink *)aIter.ptr;
  164.     TLX_ASSERT_PTR(vvlink);
  165.  
  166. #ifdef _TLXDBG
  167.     // Check that the passed-in iterator really does point into the
  168.     // support list.
  169.  
  170.     TLX_ASSERT_PTR((TLSupportList *)SupportList());
  171.     TLVarValueLink *rover;
  172.  
  173.     for (rover = SupportList()->PeekHead(); rover;
  174.      rover = (TLVarValueLink *)rover->Next())
  175.     {
  176.     if (*rover == *vvlink)
  177.         break;
  178.     }
  179.  
  180.     TLX_ASSERT_PTR(rover);
  181. #endif
  182.  
  183.     return vvlink;
  184. }
  185.  
  186. /*-------------------------------------------------------------------------*/
  187.     void TLDomainElement::RemoveSupport(const VV_Assoc &aVV)
  188.  
  189. /*  Removes the given variable/value pair from the support list of the
  190.     domain element.
  191. ---------------------------------------------------------------------------*/
  192. {
  193.     TLX_ASSERT_PTR((TLSupportList *)SupportList());
  194.  
  195.     for (TLVarValueLink *rover = SupportList()->PeekHead(); rover;
  196.      rover = (TLVarValueLink *)rover->Next())
  197.     {
  198.     if (*rover == aVV)
  199.     {
  200.         SupportList()->Extract(rover);
  201.         delete rover;
  202.         return;
  203.     }
  204.     }
  205. }
  206.  
  207. /*-------------------------------------------------------------------------*/
  208.     bool TLDomainElement::ResetIter(iter_t &aIter)
  209.  
  210. /*  Resets the iterator to point at the first element in the support list
  211.     of the domain element. Returns nonzero if the iterator is valid after
  212.     the operation.
  213. ---------------------------------------------------------------------------*/
  214. {
  215.     TLX_ASSERT_PTR((TLSupportList *)SupportList());
  216.     aIter.ptr = SupportList()->PeekHead();
  217.     return aIter.ptr != 0;
  218. }
  219.  
  220.