Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef __CSUTIL_COMPARATOR_H__
00020 #define __CSUTIL_COMPARATOR_H__
00021
00026 class csString;
00027 class csStringBase;
00028
00035 template <typename T1, typename T2 = T1>
00036 class csComparator
00037 {
00038 public:
00055 static int Compare(T1 const &r1, T2 const &r2)
00056 {
00057 if (r1 < r2) return -1;
00058 else if (r2 < r1) return 1;
00059 else return 0;
00060 }
00061 };
00062
00072 template <class T>
00073 class csComparatorString
00074 {
00075 public:
00076 static int Compare (T const& r1, T const& r2)
00077 {
00078 if (((const char*)r1) == 0)
00079 {
00080 return (((const char*)r2) == 0) ? 0 : 1;
00081 }
00082 else if (((const char*)r2) == 0)
00083 {
00084 return -1;
00085 }
00086 return strcmp ((const char*)r1, (const char*)r2);
00087 }
00088 };
00089
00093 template<>
00094 class csComparator<const char*, const char*> :
00095 public csComparatorString<const char*> {};
00096
00101 template<>
00102 class csComparator<csString, csString> :
00103 public csComparatorString<csString> {};
00104 template<>
00105 class csComparator<csStringBase, csStringBase> :
00106 public csComparatorString<csStringBase> {};
00118 template<class T>
00119 class csComparatorStruct
00120 {
00121 public:
00122 static int Compare (T const& r1, T const& r2)
00123 {
00124 return memcmp (&r1, &r2, sizeof (T));
00125 }
00126 };
00127
00130 #endif // __CSUTIL_COMPARATOR_H__