home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / yacl-012.zip / base / cmparatr.h < prev    next >
C/C++ Source or Header  |  1995-04-08  |  3KB  |  108 lines

  1.  
  2.  
  3. #ifndef _cmparatr_h_ /* Wed Aug  3 16:17:51 1994 */
  4. #define _cmparatr_h_
  5.  
  6.  
  7.  
  8.  
  9. /*
  10.  *
  11.  *          Copyright (C) 1994, M. A. Sridhar
  12.  *  
  13.  *
  14.  *     This software is Copyright M. A. Sridhar, 1994. You are free
  15.  *     to copy, modify or distribute this software  as you see fit,
  16.  *     and to use  it  for  any  purpose, provided   this copyright
  17.  *     notice and the following   disclaimer are included  with all
  18.  *     copies.
  19.  *
  20.  *                        DISCLAIMER
  21.  *
  22.  *     The author makes no warranties, either expressed or implied,
  23.  *     with respect  to  this  software, its  quality, performance,
  24.  *     merchantability, or fitness for any particular purpose. This
  25.  *     software is distributed  AS IS.  The  user of this  software
  26.  *     assumes all risks  as to its quality  and performance. In no
  27.  *     event shall the author be liable for any direct, indirect or
  28.  *     consequential damages, even if the  author has been  advised
  29.  *     as to the possibility of such damages.
  30.  *
  31.  */
  32.  
  33.  
  34. #ifdef __GNUC__
  35. #pragma implementation
  36. #endif
  37.  
  38.  
  39. #include "base/basicops.h"
  40.  
  41. // An AbstractComparator encapsulates an algorithm for comparing two objects
  42. // pointed to by void pointers. The comparison is done using the operator(),
  43. // and returns a {\tt short} value that is -1, 0 or +1 according to whether
  44. // the first operand is kess than, equal to or greater than the second.
  45. //
  46. // The default implementation uses comparison of pointer values.
  47.  
  48. class CL_EXPORT CL_AbstractComparator {
  49.  
  50. public:
  51.     ~CL_AbstractComparator () {};
  52.     
  53.     virtual short operator() (CL_VoidPtr p1, CL_VoidPtr p2) const
  54.         {return CL_Basics<CL_VoidPtr>::Compare (p1, p2);};
  55.     
  56. };
  57.  
  58.  
  59. // A Comparator is derived from an AbstractComparator, and is a template
  60. // class used for comparing two objects of the type of its template class.
  61.  
  62. template <class Base>
  63. class CL_EXPORT CL_Comparator: public CL_AbstractComparator {
  64.  
  65. public:
  66.     ~CL_Comparator () {};
  67.     
  68.     virtual short operator() (CL_VoidPtr p1, CL_VoidPtr p2) const;
  69.  
  70. };
  71.  
  72.  
  73. // BC++ 3.1 gives a strange "argument not used" warning here --
  74. // looks like a compiler bug. The pragma's don't remove the warning. :-(
  75. // That's the reason for the next two pragmas.
  76.  
  77. #ifdef __BORLANDC__
  78. #pragma warn -par
  79. #pragma warn -aus
  80. #endif
  81.  
  82. template <class Base>
  83. inline short CL_Comparator<Base>::operator() (CL_VoidPtr p1, CL_VoidPtr p2)
  84.     const
  85. {
  86.     if (p1 && p2) {
  87.         register const Base& r1 = CL_Basics<Base>::Deref (p1);
  88.         register const Base& r2 = CL_Basics<Base>::Deref (p2);
  89.         return  CL_Basics<Base>::Compare (r1, r2);
  90.     }
  91.     return CL_Basics<CL_VoidPtr>::Compare (p1, p2);
  92. }
  93.  
  94. // And if we undo the pragmas, the warnings are still emitted!! So we have
  95. // to leave them out, so some legitimate warnings might not be emitted.
  96. // Too bad.
  97. //
  98. // #ifdef __BORLANDC__
  99. // #pragma warn .par
  100. // #pragma warn .aus
  101. // #endif
  102.  
  103.  
  104.  
  105.  
  106. #endif /* _cmparatr_h_ */
  107.  
  108.