00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00019 #ifndef __GenericKey_h
00020 #define __GenericKey_h
00021
00022 #ifdef NON_ANSI
00023 #include <iostream.h>
00024 #else
00025 #include <iostream>
00026 using namespace std;
00027 #endif
00028
00029
00030
00031 template <class KEY, class DATA>
00032 class GenericKey
00033 {
00034 public:
00035
00037 virtual bool operator==(GenericKey<KEY,DATA>& key) const
00038 {return (Key == key.Key);}
00040 virtual bool operator<(GenericKey<KEY,DATA>& key) const
00041 {return (Key < key.Key);}
00043 virtual bool operator>(GenericKey<KEY,DATA>& key) const
00044 {return (Key > key.Key);}
00045
00052 virtual int compare(const GenericKey<KEY,DATA>& val) const
00053 {return (Key < val.key() ? -1 : Key > val.key() ? 1 : 0);}
00055 virtual void write(ostream& os) const
00056 {os << Key << " " << Data;}
00058 virtual void read(istream& )
00059 {}
00060
00062 DATA& data()
00063 {return Data;}
00065 KEY& key()
00066 {return Key;}
00068 const KEY& key() const
00069 {return Key;}
00070
00071 protected:
00072
00074 KEY Key;
00076 DATA Data;
00077 };
00078
00079
00080 template <class KEY, class DATA>
00081 inline ostream& operator<<(ostream& output, GenericKey<KEY,DATA>& key)
00082 { key.write(output); return(output); }
00083
00084 template <class KEY, class DATA>
00085 inline istream& operator>>(istream& input, GenericKey<KEY,DATA>& key)
00086 { key.read(input); return(input); }
00087
00088 #endif