1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
|
#ifndef __MAPEX_H__
#define __MAPEX_H__
#if _MSC_VER < 0x0600
#pragma warning(disable : 4786) //identifier was truncated to '255' characters in the debug information
#endif
#ifndef __AFXTEMPL_H__
#include <afxtempl.h>
#endif
// specialization for CString
// extract of CMapStringToPtr::HashKey(LPCTSTR key) const :)
template<>
inline UINT AFXAPI HashKey<CString> (CString strKey)
{
LPCSTR key = strKey;
UINT nHash = 0;
while (*key)
{
nHash = (nHash<<5) + nHash + *key++;
}
return nHash;
}
template<>
inline UINT AFXAPI HashKey<CString&> (CString& strKey)
{
LPCSTR key = strKey;
UINT nHash = 0;
while (*key)
{
nHash = (nHash<<5) + nHash + *key++;
}
return nHash;
}
template<class KEY, class ARG_KEY, class VALUE, class ARG_VALUE>
class CMapEx : public CMap<KEY, ARG_KEY, VALUE, ARG_VALUE>
{
public:
CMapEx(int nBlockSize = 10);
// copy constructor
CMapEx(const CMapEx &x);
// assigment operator
CMapEx &operator = (const CMapEx& x);
//The List element currently at this index like CArray
VALUE GetAt(int nIndex,KEY &rKey) const;
//Gets the number of elements in this List like CArray
int GetSize( ) const;
};
template<class KEY, class ARG_KEY, class VALUE, class ARG_VALUE>
inline CMapEx<KEY, ARG_KEY, VALUE, ARG_VALUE>::CMapEx(int nBlockSize)
:CMap<KEY, ARG_KEY, VALUE, ARG_VALUE>(nBlockSize)
{
}
template<class KEY, class ARG_KEY, class VALUE, class ARG_VALUE>
inline CMapEx<KEY, ARG_KEY, VALUE, ARG_VALUE>::CMapEx(const CMapEx &x)
{
*this = x;
}
template<class KEY, class ARG_KEY, class VALUE, class ARG_VALUE>
inline CMapEx<KEY, ARG_KEY, VALUE, ARG_VALUE> &
CMapEx<KEY, ARG_KEY, VALUE, ARG_VALUE>::operator = (const CMapEx& x)
{
KEY rKey;
VALUE rValue;
POSITION pos = x.GetStartPosition();
RemoveAll();
while(pos != NULL)
{
x.GetNextAssoc(pos,rKey,rValue);
SetAt(rKey,rValue);
}
return *this;
}
template<class KEY, class ARG_KEY, class VALUE, class ARG_VALUE>
inline VALUE CMapEx<KEY, ARG_KEY, VALUE, ARG_VALUE>::GetAt(int nIndex,KEY &rKey) const
{
ASSERT(nIndex >= 0 && nIndex < GetCount());
POSITION pos = GetStartPosition();
VALUE rValue;
do
{
GetNextAssoc(pos,rKey,rValue);
}while(nIndex --);
return rValue;
}
template<class KEY, class ARG_KEY, class VALUE, class ARG_VALUE>
inline int CMapEx<KEY, ARG_KEY, VALUE, ARG_VALUE>::GetSize( ) const
{
return GetCount();
}
#endif |
Partager