Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. // Creator - MatthewGolder
  2. #ifndef MAP_H
  3. #define MAP_H
  4. #include "Vector.h"
  5.  
  6. #define FOR_EACH_MAP(map, count, iteratorName) for(unsigned int iteratorName = 0; iteratorName < count; iteratorName++)
  7.  
  8. template<typename K, typename V>
  9. class MapEntry
  10. {
  11. public:
  12.     MapEntry<K, V>(void);
  13.     MapEntry<K, V>(const K& key, const V& value);
  14.     bool operator== (const MapEntry<K,V>& rhs)const{return _key == rhs._key && _value == rhs._value;}
  15.     bool operator!= (const MapEntry<K,V>& rhs)const{return !(*this == rhs);}
  16.  
  17.     K& First(void);
  18.     const K& First(void)const;
  19.     void First(const K& key);
  20.     V& Second(void);
  21.     const V& Second(void)const;
  22.     void Second(const V& value);
  23. private:
  24.     K _key;
  25.     V _value;
  26.  };
  27.  
  28. template<typename K, typename V>
  29. class Map
  30. {
  31. public:
  32.     typedef MapEntry<K, V> MapElements;
  33.  
  34.     Map(void);
  35.     ~Map(void);
  36.  
  37.     MapEntry<K, V>& operator[](unsigned int i);
  38.     const MapEntry<K, V>& operator[](unsigned int i)const;
  39.     MapEntry<K, V>& Element(unsigned int i);
  40.     const MapEntry<K, V>& Element(unsigned int i)const;
  41.  
  42.     void Insert(const MapEntry<K, V> entry);
  43.     void Insert(const K& key, const V& value);
  44.  
  45.     int FindKey(const K& key)const;
  46.  
  47.     bool Contains    (const K& key)const;
  48.     bool Compare     (const MapElements& lhs, const MapElements& rhs)const;
  49.     bool CompareKey  (const K& lhs, const K& rhs)const;
  50.     bool CompareValue(const V& lhs, const V& rhs)const;
  51.  
  52.     void Remove(unsigned int elem);
  53.     void Remove(const K& key);
  54.     void Clear(void);
  55.  
  56.     unsigned int Count   (void)const{return _mapTable.Count();}
  57.     unsigned int Capacity(void)const{return _mapTable.Capacity();}
  58.  
  59. private:
  60.     Vector<MapElements> _mapTable;
  61. };
  62. #include "Map.inl"
  63. #endif
  64.