00001 #ifndef MMANN_COMPARE_ALGORITHMS_H 00002 #define MMANN_COMPARE_ALGORITHMS_H 00003 00011 00012 #include <string.h> 00013 00014 #ifdef min 00015 #undef min 00016 #endif 00017 00018 #define min(a,b) ((a)<(b)?(a):(b)) 00019 00021 template <class Data, class ConfigData> 00022 class ACompareNodesAlgorithm 00023 { 00024 public: 00030 virtual int Compare(const Data* Node1, const Data* Node2, const ConfigData* TConfigData) = 0; 00031 }; 00032 00036 template <class Data, class ConfigData> 00037 class SimpleCompareNodesAlgorithm : public ACompareNodesAlgorithm<Data, ConfigData> 00038 { 00039 public: 00045 virtual int Compare(const Data* Node1, const Data* Node2, const ConfigData* TConfigData); 00046 }; 00047 00048 template <class Data, class ConfigData> 00049 int SimpleCompareNodesAlgorithm<Data, ConfigData>::Compare(const Data* Node1, const Data* Node2, const ConfigData* TConfigData) 00050 { 00051 if (*Node1 < *Node2) 00052 return -1; 00053 if (*Node1 > *Node2) 00054 return 1; 00055 00056 return 0; 00057 } 00058 00063 template <class Data, class ConfigData> 00064 class CompareFunctionCompareNodesAlgorithm : public ACompareNodesAlgorithm<Data, ConfigData> 00065 { 00066 public: 00072 virtual int Compare(const Data* Node1, const Data* Node2, const ConfigData* TConfigData); 00073 }; 00074 00075 template <class Data, class ConfigData> 00076 int CompareFunctionCompareNodesAlgorithm<Data, ConfigData>::Compare(const Data* Node1, const Data* Node2, const ConfigData* TConfigData) 00077 { 00078 return ((Data*)Node1)->Compare(Node2); 00079 } 00080 00081 #endif