home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 2.4 KB | 89 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWTMap.h
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef FWTMAP_H
- #define FWTMAP_H
-
- #ifndef SLSRTARR_H
- #include "SLSrtArr.h"
- #endif
-
- #ifndef FWPRIDEB_H
- #include "FWPriDeb.h"
- #endif
-
- //========================================================================================
- // Struct FW_TPair
- //========================================================================================
-
- template<class tKey, class tValue>
- class FW_TPair
- {
- public:
- FW_TPair(const tKey& key, const tValue& value)
- : fKey(key), fValue(value) {}
- FW_TPair(const tKey& key)
- : fKey(key), fValue() {}
-
- const tKey fKey;
- tValue fValue;
- };
-
- //========================================================================================
- // Class FW_TMap
- //========================================================================================
-
- template<class tKey, class tValue>
- class FW_TMap
- {
- //----------------------------------------------------------------------------------------
- // Constructors/Destructor
- //
- public:
- FW_TMap(FW_SortedArray_CompareFunction compare);
- ~FW_TMap();
-
- long GetLength() const;
-
- FW_TPair<tKey, tValue>* Find(FW_TPair<tKey, tValue>* item) const;
- // Find entry in the map whose key matches item->fKey
-
- FW_TPair<tKey, tValue>* Find(const tKey& key) const;
- // Find entry in the map whose key matches key
-
- FW_TPair<tKey, tValue>* Add(FW_TPair<tKey, tValue>* newItem);
- // Add newItem to the map.
-
- FW_TPair<tKey, tValue>* Add(const tKey& key, const tValue& value);
- // Create a pair and and it to the map.
-
- void Remove(FW_TPair<tKey, tValue>* item);
- // Remove entry in the map whose key matches item->fKey
-
- void Remove(const tKey& key);
- // Remove entry in the map whose key matches key
-
- tValue& operator[](const tKey& key);
- // Return a reference to the value for the given key
-
- public:
-
- FW_TPair<tKey, tValue>* GetItemAt(long index) const;
- // Return the entry at index. This method should only be used
- // as a low level accessor, for example in iterating across all
- // entries in the map. Note that Adding a new entry invalidates
- // any previous index:entry associations.
-
- private:
- FW_HSortedArray fRep;
- };
-
- #endif
-
-