///////////////////////////////////////////////////////////////////////////// // class CMap - a mapping from fixed length 'KEY's to fixed size 'VALUE's. // // NOTE: ARG_KEY must be either an lvalue or a reference type; no pointers; // that is, the type of &ARG_KEY must be the same as &KEY. // Same for ARG_VALUE/VALUE. // // This template class uses the MapKeyToValue implementation in compobj.dll. ///////////////////////////////////////////////////////////////////////////// //$DECLARE_TEMPLATE //////////////////////////////////////////////////////////////////////////// template class FAR CMap { public: // Construction CMap(DWORD memctx = MEMCTX_SAME, UINT nBlockSize=10) : m_mkv(memctx, sizeof(VALUE), sizeof(KEY), nBlockSize) { } // Attributes // number of elements int GetCount() const { return m_mkv.GetCount(); } BOOL IsEmpty() const { return GetCount() == 0; } // Lookup BOOL Lookup(ARG_KEY key, VALUE FAR& value) const { return m_mkv.Lookup((LPVOID)&key, sizeof(KEY), (LPVOID)&value); } BOOL LookupHKey(HMAPKEY hKey, VALUE FAR& value) const { return m_mkv.LookupHKey(hKey, (LPVOID)&value); } BOOL LookupAdd(ARG_KEY key, VALUE FAR& value) const { return m_mkv.LookupAdd((LPVOID)&key, sizeof(KEY), (LPVOID)&value); } // Add/Delete // add a new (key, value) pair BOOL SetAt(ARG_KEY key, ARG_VALUE value) { return m_mkv.SetAt((LPVOID)&key, sizeof(KEY), (LPVOID)&value); } BOOL SetAtHKey(HMAPKEY hKey, ARG_VALUE value) { return m_mkv.SetAtHKey(hKey, (LPVOID)&value); } // removing existing (key, ?) pair BOOL RemoveKey(ARG_KEY key) { return m_mkv.RemoveKey((LPVOID)&key, sizeof(KEY)); } BOOL RemoveHKey(HMAPKEY hKey) { return m_mkv.RemoveHKey(hKey); } void RemoveAll() { m_mkv.RemoveAll(); } // iterating all (key, value) pairs POSITION GetStartPosition() const { return m_mkv.GetStartPosition(); } void GetNextAssoc(POSITION FAR& rNextPosition, KEY FAR& rKey, VALUE FAR& rValue) const { m_mkv.GetNextAssoc(&rNextPosition, (LPVOID)&rKey, NULL, (LPVOID)&rValue); } HMAPKEY GetHKey(ARG_KEY key) const { return m_mkv.GetHKey((LPVOID)&key, sizeof(KEY)); } #ifdef _DEBUG void AssertValid() const { m_mkv.AssertValid(); } #endif private: CMapKeyToValue m_mkv; };