core/vbl/vbl_sort.h
Go to the documentation of this file.
00001 // This is core/vbl/vbl_sort.h
00002 #ifndef vbl_sort_h_
00003 #define vbl_sort_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \brief Collection of common predicates for sorting
00010 // \author Andrew W. Fitzgibbon, Oxford RRG
00011 // \date   19 Nov 97
00012 //
00013 // \verbatim
00014 // Modifications
00015 // 971119 AWF Initial version.
00016 // PDA (Manchester) 21/03/2001: Tidied up the documentation
00017 // \endverbatim
00018 
00019 int vbl_sort_double_ascending(double const&, double const&);
00020 int vbl_sort_double_descending(double const&, double const&);
00021 
00022 int vbl_sort_int_ascending(int const&, int const&);
00023 int vbl_sort_int_descending(int const&, int const&);
00024 
00025 
00026 //: Collection of common predicates for sorting
00027 template <class T>
00028 struct vbl_sort_helper
00029 {
00030   static int ascend(const void* a, const void* b) {
00031     T const& ta = *((T const*)a);
00032     T const& tb = *((T const*)b);
00033     return tb > ta ? -1 : tb == ta ? 0 : 1;
00034   }
00035   static int descend(const void* a, const void* b) {
00036     return - ascend(a,b);
00037   }
00038 };
00039 
00040 #define VBL_SORT_INSTANTIATE(T) \
00041 template struct vbl_sort_helper<T >
00042 
00043 #endif // vbl_sort_h_