📄 ptrlist.h
字号:
#ifndef _WDL_PTRLIST_H_
#define _WDL_PTRLIST_H_
#include "heapbuf.h"
template<class PTRTYPE> class WDL_PtrList
{
public:
WDL_PtrList()
{
}
~WDL_PtrList()
{
}
PTRTYPE **GetList() { return (PTRTYPE**)m_hb.Get(); }
PTRTYPE *Get(int index) { if (GetList() && index >= 0 && index < GetSize()) return GetList()[index]; return NULL; }
int GetSize(void) { return m_hb.GetSize()/sizeof(PTRTYPE *); }
PTRTYPE *Add(PTRTYPE *item)
{
int s=GetSize();
m_hb.Resize((s+1)*sizeof(PTRTYPE*));
return Set(s,item);
}
PTRTYPE *Set(int index, PTRTYPE *item)
{
if (index >= 0 && index < GetSize() && GetList()) return GetList()[index]=item;
return NULL;
}
void Delete(int index)
{
PTRTYPE **list=GetList();
int size=GetSize();
if (list && index >= 0 && index < size)
{
if (index < --size) memcpy(list+index,list+index+1,sizeof(PTRTYPE *)*(size-index));
m_hb.Resize(size * sizeof(PTRTYPE*));
}
}
void Empty()
{
m_hb.Resize(0);
}
private:
WDL_HeapBuf m_hb;
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -