home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / Found / FWCollec / FWTMap.h < prev    next >
Encoding:
Text File  |  1996-09-17  |  2.4 KB  |  89 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWTMap.h
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef FWTMAP_H
  11. #define FWTMAP_H
  12.  
  13. #ifndef SLSRTARR_H
  14. #include "SLSrtArr.h"
  15. #endif
  16.  
  17. #ifndef FWPRIDEB_H
  18. #include "FWPriDeb.h"
  19. #endif
  20.  
  21. //========================================================================================
  22. // Struct FW_TPair
  23. //========================================================================================
  24.  
  25. template<class tKey, class tValue>
  26. class FW_TPair
  27. {
  28. public:
  29.     FW_TPair(const tKey& key, const tValue& value)
  30.         : fKey(key), fValue(value) {}
  31.     FW_TPair(const tKey& key)
  32.         : fKey(key), fValue() {}
  33.     
  34.     const tKey    fKey;
  35.     tValue        fValue;
  36. };
  37.  
  38. //========================================================================================
  39. // Class FW_TMap
  40. //========================================================================================
  41.  
  42. template<class tKey, class tValue>
  43. class FW_TMap
  44. {
  45. //----------------------------------------------------------------------------------------
  46. //    Constructors/Destructor
  47. //
  48. public:
  49.     FW_TMap(FW_SortedArray_CompareFunction compare);
  50.     ~FW_TMap();
  51.  
  52.     long GetLength() const;
  53.  
  54.     FW_TPair<tKey, tValue>* Find(FW_TPair<tKey, tValue>* item) const;
  55.         // Find entry in the map whose key matches item->fKey
  56.  
  57.     FW_TPair<tKey, tValue>* Find(const tKey& key) const;
  58.         // Find entry in the map whose key matches key
  59.     
  60.     FW_TPair<tKey, tValue>* Add(FW_TPair<tKey, tValue>* newItem);
  61.         // Add newItem to the map.
  62.  
  63.     FW_TPair<tKey, tValue>* Add(const tKey& key, const tValue& value);
  64.         // Create a pair and and it to the map.
  65.         
  66.     void Remove(FW_TPair<tKey, tValue>* item);
  67.         // Remove entry in the map whose key matches item->fKey
  68.         
  69.     void Remove(const tKey& key);
  70.         // Remove entry in the map whose key matches key
  71.  
  72.     tValue& operator[](const tKey& key);
  73.         // Return a reference to the value for the given key
  74.     
  75. public:
  76.  
  77.     FW_TPair<tKey, tValue>* GetItemAt(long index) const;
  78.         // Return the entry at index.  This method should only be used
  79.         // as a low level accessor, for example in iterating across all
  80.         // entries in the map.  Note that Adding a new entry invalidates
  81.         // any previous index:entry associations.
  82.  
  83. private:
  84.     FW_HSortedArray fRep;
  85. };
  86.  
  87. #endif
  88.  
  89.