diff --git a/headers/private/kernel/util/VectorMap.h b/headers/private/kernel/util/VectorMap.h index 359fa65846..350535831f 100644 --- a/headers/private/kernel/util/VectorMap.h +++ b/headers/private/kernel/util/VectorMap.h @@ -41,6 +41,10 @@ namespace VectorMapEntryStrategy { // Pair template > class Pair; + // ImplicitKey + template > + class ImplicitKey; } template @@ -72,12 +76,14 @@ class VectorMap { private: typedef _VECTOR_MAP_CLASS_NAME Class; typedef typename EntryStrategy::Entry _Entry; + typedef typename EntryStrategy::KeyReference KeyReference; typedef Vector<_Entry> ElementVector; public: - typedef VectorMapEntry Entry; - typedef VectorMapEntry - ConstEntry; + typedef VectorMapEntry + Entry; + typedef VectorMapEntry ConstEntry; typedef VectorMapIterator Iterator; typedef VectorMapIterator +template class VectorMapEntry { private: - typedef VectorMapEntry<_Key, _Value, Entry, Parent> Class; + typedef VectorMapEntry Class; public: VectorMapEntry() : fParent(NULL), fEntry(NULL) {} - inline const _Key &Key() const + inline KeyReference Key() const { return fParent->fEntryStrategy.GetKey(*fEntry); } @@ -171,13 +178,13 @@ private: typedef VectorMapIterator Iterator; public: - inline VectorMapIterator() + inline VectorMapIterator() : fParent(NULL), fIterator() { } - inline VectorMapIterator( + inline VectorMapIterator( const Iterator &other) : fParent(other.fParent), fIterator(other.fIterator) @@ -244,8 +251,7 @@ public: // private public: - inline VectorMapIterator(Parent *parent, - const EntryIterator &iterator) + inline VectorMapIterator(Parent *parent, const EntryIterator &iterator) : fParent(parent), fIterator(iterator) { @@ -690,9 +696,12 @@ _VECTOR_MAP_CLASS_NAME::_FindInsertionIndex(const Key &key, namespace VectorMapEntryStrategy { +// Pair template class Pair { public: + typedef const Key &KeyReference; + class Entry { public: Entry(const Key &key, const Value &value) @@ -702,7 +711,7 @@ public: Value value; }; - inline const Key &GetKey(const Entry &entry) const + inline KeyReference GetKey(const Entry &entry) const { return entry.key; } @@ -736,6 +745,48 @@ private: KeyOrder fCompare; }; +// ImplicitKey +template +class ImplicitKey { +public: + typedef Key KeyReference; + typedef Value Entry; + + inline KeyReference GetKey(const Entry &entry) const + { + return fGetKey(entry); + } + + inline const Value &GetValue(const Entry &entry) const + { + return entry; + } + + inline Value &GetValue(Entry &entry) const + { + return entry; + } + + inline Entry MakeEntry(const Key &, const Value &value) const + { + return value; + } + + inline bool AreCompatible(const Key &key, const Value &value) const + { + return (fGetKey(value) == key); + } + + inline int Compare(const Key &a, const Key &b) const + { + return fCompare(a, b); + } + +private: + KeyOrder fCompare; + _GetKey fGetKey; +}; + } // VectorMapEntryStrategy #endif // _VECTOR_MAP_H