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

  1. /****************************************************************************
  2.     $Id: domac6.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 TLDomainAC6.
  10.  
  11.     $Log: domac6.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:10:52  RON
  15.     Update for release 012
  16.     Added partial support for SunPro C++ compiler
  17.     Revision 1.7  1995/01/06  15:57:42  ron
  18.     Corrected Revision keyword
  19.  
  20.     Revision 1.6  1994/11/16  15:38:54  ron
  21.     Added module info; rearranged #include directives
  22.  
  23.     Revision 1.5  1994/10/10  16:49:24  ron
  24.     Changed to <tlx\solve\ac6.h>
  25.  
  26.     Revision 1.4  1994/09/28  14:17:35  ron
  27.     Removed Macintosh-style #include references
  28.  
  29.     Revision 1.3  1994/09/27  20:22:20  ron
  30.     Changed path separator from / to \
  31.  
  32.     Revision 1.2  1994/09/26  15:42:15  ron
  33.     Changed include file references
  34.  
  35.     Revision 1.1  1994/08/16  18:13:01  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 "seq.cpp"
  53.     #pragma template_access public
  54.     #pragma template TLSeq<TLDomainElement>
  55. #elif defined(__BORLANDC__) || defined(__SC__) || defined(__WATCOMC__)
  56.     #include <tlx\501\template\assoc.cpp>
  57.     #include <tlx\501\template\seq.cpp>
  58. #elif defined(__SUNPRO_CC)
  59.     #include <tlx\501\template\assoc.cpp>
  60.     #include <tlx\501\template\seq.cpp>
  61. #elif defined(__IBMCPP__)
  62.   #if __IBMCPP__ < 300
  63.     #pragma implementation("tlx\\template\\assoc.cpp")
  64.     #pragma implementation("tlx\\template\\seq.cpp")
  65.   #else
  66.     #include <tlx\501\template\assoc.cpp>
  67.     #include <tlx\501\template\seq.cpp>
  68.   #endif
  69. #else
  70.     #error Unsupported compiler; contact Tarma Software Research
  71. #endif
  72.  
  73. /*-------------------------------------------------------------------------*/
  74.     TLDomainAC6::TLDomainAC6(size_t aCap, size_t aDelta)
  75.  
  76. /*  Constructor.
  77. ---------------------------------------------------------------------------*/
  78. : TLSeq<TLDomainElement>(aCap, aDelta)
  79. {
  80.     SetCompare(DECompare);
  81. }
  82.  
  83. /*-------------------------------------------------------------------------*/
  84.     int TLDomainAC6::DECompare
  85.     (
  86.         const TLDomainElement &    aEl1,
  87.     const TLDomainElement &    aEl2
  88.     )
  89.  
  90. /*  Static function to compare two domain elements in the sequence.
  91. ---------------------------------------------------------------------------*/
  92. {
  93.     tVarValue diff = aEl1.PeekValue() - aEl2.PeekValue();
  94.     return (diff < 0) ? -1 : (diff > 0) ? 1 : 0;
  95. }
  96.  
  97. /*-------------------------------------------------------------------------*/
  98.     index_t TLDomainAC6::EqualOrNextIndexOf(tVarValue aValue) const
  99.  
  100. /*  Returns the index of the given value in the domain, or of the next
  101.     higher element in the domain. This assumes that the domain is sorted.
  102. ---------------------------------------------------------------------------*/
  103. {
  104.     TLDomainElement el(aValue);
  105.  
  106.     for (index_t index = Mini(); index <= Maxi(); index++)
  107.     {
  108.     if (DECompare(PeekAt(index), el) >= 0)
  109.         return index;
  110.     }
  111.     return Maxi() + 1;
  112. }
  113.  
  114. /*-------------------------------------------------------------------------*/
  115.     TLDomainElement &TLDomainAC6::GetElement(tVarValue aValue)
  116.  
  117. /*  Returns a reference to the domain element containing the given value.
  118. ---------------------------------------------------------------------------*/
  119. {
  120.     index_t index = IndexOfValue(aValue);
  121.     if (!IsValidIndex(index))
  122.         THROW(TLXNotFound(LOCUS));
  123.     return PeekAt(index);
  124. }
  125.  
  126. /*-------------------------------------------------------------------------*/
  127.     const TLDomainElement &TLDomainAC6::GetElement(tVarValue aValue) const
  128.  
  129. /*  Returns a reference to the domain element containing the given value.
  130. ---------------------------------------------------------------------------*/
  131. {
  132.     index_t index = IndexOfValue(aValue);
  133.     if (!IsValidIndex(index))
  134.         THROW(TLXNotFound(LOCUS));
  135.     return PeekAt(index);
  136. }
  137.  
  138. /*-------------------------------------------------------------------------*/
  139.     index_t TLDomainAC6::IndexOfValue(tVarValue aValue) const
  140.  
  141. /*  Returns the index of the given value in the domain.
  142. ---------------------------------------------------------------------------*/
  143. {
  144.     TLDomainElement el(aValue);
  145.  
  146.     for (index_t index = Mini(); index <= Maxi(); index++)
  147.     {
  148.     if (DECompare(PeekAt(index), el) == 0)
  149.         return index;
  150.     }
  151.     return Maxi() + 1;
  152. }
  153.  
  154.