mfc CMap 相关操作函数都有哪些?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mfc CMap 相关操作函数都有哪些?相关的知识,希望对你有一定的参考价值。

比如:
插入
包含(contain)
删除
个数
等等。。。

这是AfxTempl.h中的相关内容,可以参考一下:


/////////////////////////////////////////////////////////////////////////////
// CMap<KEY, ARG_KEY, VALUE, ARG_VALUE>
template<class KEY, class ARG_KEY, class VALUE, class ARG_VALUE>
class CMap : public CObject

protected:
// Association
struct CAssoc

CAssoc* pNext;
UINT nHashValue;  // needed for efficient iteration
KEY key;
VALUE value;
;
public:
// Construction
CMap(int nBlockSize = 10);
// Attributes
// number of elements
int GetCount() const;
BOOL IsEmpty() const;
// Lookup
BOOL Lookup(ARG_KEY key, VALUE& rValue) const;
// Operations
// Lookup and add if not there
VALUE& operator[](ARG_KEY key);
// add a new (key, value) pair
void SetAt(ARG_KEY key, ARG_VALUE newValue);
// removing existing (key, ?) pair
BOOL RemoveKey(ARG_KEY key);
void RemoveAll();
// iterating all (key, value) pairs
POSITION GetStartPosition() const;
void GetNextAssoc(POSITION& rNextPosition, KEY& rKey, VALUE& rValue) const;
// advanced features for derived classes
UINT GetHashTableSize() const;
void InitHashTable(UINT hashSize, BOOL bAllocNow = TRUE);
// Implementation
protected:
CAssoc** m_pHashTable;
UINT m_nHashTableSize;
int m_nCount;
CAssoc* m_pFreeList;
struct CPlex* m_pBlocks;
int m_nBlockSize;
CAssoc* NewAssoc();
void FreeAssoc(CAssoc*);
CAssoc* GetAssocAt(ARG_KEY, UINT&) const;
public:
~CMap();
void Serialize(CArchive&);
#ifdef _DEBUG
void Dump(CDumpContext&) const;
void AssertValid() const;
#endif
;

 测试一下:

#include <Afxtempl.h>
void test()

    CMap<int, int, CString, CString> mapStudent;
    mapStudent.SetAt(1, "A");
    mapStudent.SetAt(2, "A");
    mapStudent.SetAt(3, "A");
    mapStudent.SetAt(4, "A");
    mapStudent.SetAt(5, "A");
    mapStudent.GetCount();
    mapStudent.RemoveKey(1);
    mapStudent.RemoveKey(2);
    mapStudent.GetCount();

参考技术A 你可以在网上直接艘一下

以上是关于mfc CMap 相关操作函数都有哪些?的主要内容,如果未能解决你的问题,请参考以下文章

试图为 MFC 的 CMap 编写一个 for_each 算法

在 MFC 中,可以在工作线程中执行 UI 相关操作(绘制绘图)吗?

Python开发中常用的模块都有哪些?

MFC文件读写操作

python学习,需要都有哪些基础呢?

将 MFC CMap 用于 CString int 对