1 //===- HashEntry.h ---------------------------------------------------------===// 2 // 3 // The MCLinker Project 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #ifndef MCLD_ADT_HASHENTRY_H 11 #define MCLD_ADT_HASHENTRY_H 12 13 namespace mcld { 14 15 /** forward declaration **/ 16 template<typename HashEntryTy> 17 class EntryFactory; 18 19 /** \class HashEntry 20 * \brief HashEntry is the item in the bucket of hash table. 21 * 22 * mcld::HashEntry illustrates the demand from mcld::HashTable. 23 * Since HashTable can change the definition of the HashEntry by changing 24 * the template argument. class mcld::HashEntry here is used to show the 25 * basic interfaces that HashTable requests. You can define your own entry 26 * of the hash table which has no relation to mcld::HashEntry 27 * 28 * Since mcld::HashEntry here is a special class whose size is changing, 29 * derive a new class from it is risky. Make sure you understand what you 30 * are doing when you let a new class inherit from mcld::HashEntry. 31 */ 32 template <typename KeyType, typename ValueType, typename KeyCompare> 33 class HashEntry 34 { 35 public: 36 typedef KeyType key_type; 37 typedef ValueType value_type; 38 typedef KeyCompare key_compare; 39 40 private: 41 typedef HashEntry<KeyType, ValueType, KeyCompare> Self; 42 friend class EntryFactory<Self>; 43 44 private: 45 HashEntry(const KeyType& pKey); 46 ~HashEntry(); 47 48 public: key()49 KeyType& key() 50 { return m_Key; } 51 key()52 const KeyType& key() const 53 { return m_Key; } 54 value()55 ValueType& value() 56 { return m_Value; } 57 value()58 const ValueType& value() const 59 { return m_Value; } 60 setValue(const ValueType & pValue)61 void setValue(const ValueType& pValue) 62 { m_Value = pValue; } 63 64 bool compare(const key_type& pKey); 65 66 public: 67 KeyType m_Key; 68 ValueType m_Value; 69 }; 70 71 template <typename HashEntryTy> 72 class EntryFactory 73 { 74 public: 75 typedef HashEntryTy entry_type; 76 typedef typename HashEntryTy::key_type key_type; 77 typedef typename HashEntryTy::value_type value_type; 78 79 public: 80 EntryFactory(); 81 ~EntryFactory(); 82 83 HashEntryTy* produce(const key_type& pKey); 84 void destroy(HashEntryTy* pEntry); 85 }; 86 87 #include "HashEntry.tcc" 88 89 } // namespace of mcld 90 91 #endif 92 93