home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2006 March / Gamestar_82_2006-03_dvd.iso / DVDStar / Editace / quake4_sdkv10.exe / source / idlib / containers / Pair.h < prev    next >
C/C++ Source or Header  |  2005-11-14  |  1KB  |  59 lines

  1. //----------------------------------------------------------------
  2. // Pair.cpp
  3. //
  4. // Copyright 2002-2004 Raven Software
  5. //----------------------------------------------------------------
  6.  
  7. #ifndef __PAIR_H__
  8. #define __PAIR_H__
  9.  
  10. template< class type1, class type2 >
  11. class rvPair {
  12. public:
  13.     rvPair() {};
  14.     rvPair( const type1& T1, const type2& T2 ) { first = T1; second = T2; };
  15.  
  16.     const type1& First( void ) const { return first; };
  17.     const type2& Second( void ) const { return second; };
  18.  
  19.     static int rvPairFirstCompare( const rvPair< type1, type2 > *a, const rvPair< type1, type2 > *b ) {
  20.         return b->First() - a->First();
  21.     }
  22.  
  23.     static int rvPairSecondCompare( const rvPair< type1, type2 > *a, const rvPair< type1, type2 > *b ) {
  24.         return  b->Second() - a->Second();
  25.     }
  26.  
  27.     static int rvPairFirstCompareDirect( const rvPair< type1, type2 > *a, const rvPair< type1, type2 > *b ) {
  28.         if( b->First() - a->First() < 0.001f || b->First() - a->First() < -0.001f ) {
  29.             return 0;
  30.         }
  31.  
  32.         if( a->First() > b->First() ) {
  33.             return -1;
  34.         } else if( a->First() < b->First() ) {
  35.             return 1;
  36.         } 
  37.         return 0;
  38.     }
  39.  
  40.     static int rvPairSecondCompareDirect( const rvPair< type1, type2 > *a, const rvPair< type1, type2 > *b ) {
  41.         if( b->Second() - a->Second() < 0.001f || b->Second() - a->Second() < -0.001f ) {
  42.             return 0;
  43.         }
  44.  
  45.         if( a->Second() > b->Second() ) {
  46.             return -1;
  47.         } else if( a->Second() < b->Second() ) {
  48.             return 1;
  49.         } 
  50.         return 0;
  51.     }
  52.  
  53. private:
  54.     type1 first;
  55.     type2 second;
  56. };
  57.  
  58. #endif
  59.