diff --git a/libs/libsupport/KeyMap.h b/libs/libsupport/KeyMap.h index 6546706..d63388e 100644 --- a/libs/libsupport/KeyMap.h +++ b/libs/libsupport/KeyMap.h @@ -12,44 +12,48 @@ template class KeyMap { public: - uint32 CountItems(); + uint32 CountItems() const; void AddItem(KEY k, TYPE t); - TYPE ValueFor(KEY, bool* found = NULL); + TYPE ValueFor(KEY, bool* found = NULL) const; void RemoveItemAt(int32 position); void RemoveItemFor(KEY); - TYPE ValueAt(int32 position); - KEY KeyAt(int32 position); + KEY KeyAt(uint32 position) const; + TYPE ValueAt(uint32 position) const; - List Values(); + List Values() const; private: - std::map fMap; - typedef typename std::map::iterator fIter; + std::map fMap; + typedef typename std::map::iterator fIter; + typedef typename std::map::const_iterator fConstIter; }; template -uint32 KeyMap::CountItems() +inline uint32 +KeyMap::CountItems() const { return fMap.size(); } template -void KeyMap::AddItem(KEY k, TYPE t) +inline void +KeyMap::AddItem(KEY k, TYPE t) { fMap[k] = t; } template -TYPE KeyMap::ValueFor(KEY k, bool* found) +inline TYPE +KeyMap::ValueFor(KEY k, bool* found) const { - fIter i = fMap.find(k); + fConstIter i = fMap.find(k); if (found) { if (i == fMap.end()) @@ -65,7 +69,8 @@ TYPE KeyMap::ValueFor(KEY k, bool* found) template -void KeyMap::RemoveItemAt(int32 position) +inline void +KeyMap::RemoveItemAt(int32 position) { fIter i = fMap.begin(); std::advance(i, position); @@ -74,25 +79,16 @@ void KeyMap::RemoveItemAt(int32 position) template -void KeyMap::RemoveItemFor(KEY k) +inline void +KeyMap::RemoveItemFor(KEY k) { fMap.erase(k); } template -TYPE KeyMap::ValueAt(int32 position) -{ - fIter i = fMap.begin(); - std::advance(i, position); - if (i == fMap.end()) - return NULL; - return i->second; -} - - -template -KEY KeyMap::KeyAt(int32 position) +inline KEY +KeyMap::KeyAt(uint32 position) const { fIter i = fMap.begin(); std::advance(i, position); @@ -103,7 +99,20 @@ KEY KeyMap::KeyAt(int32 position) template -List KeyMap::Values() +inline TYPE +KeyMap::ValueAt(uint32 position) const +{ + fConstIter i = fMap.begin(); + std::advance(i, position); + if (i == fMap.end()) + return NULL; + return i->second; +} + + +template +inline List +KeyMap::Values() const { List list;