📄 ptrcontrol.h
字号:
/*
作者:kyo wang
你可以使用并传播此代码,但必须保留此注释部分
*/
#ifndef __PTRCTRL_HEADER__
#define __PTRCTRL_HEADER__
#include "commdef.h"
#define PTRCTRLDLL_API __declspec(dllexport)
typedef struct tagFINDDATA
{
int nStartPos ;
int nFindPos ;
} FINDDATA ;
typedef int (__stdcall *FINDFUNC)(void *pData, void *pParam) ;
/* SAMPLE
int __stdcall SampleFind(void *pData, void *pParam)
{
WCHAR *wszName = (WCHAR *)pData ;
WCHAR *wszName = (WCHAR *)pParam ;
if ( wcsicmp(wszGroupName1, wszGroupName2) == 0 )
{
return 1 ;
}
else
{
return 0 ;
}
}
CPtrListCtrl a ;
a.AddData(L"123456") ;
a.AddData(L"223456") ;
a.AddData(L"323456") ;
a.FindFirst(L"123456", SampleFind) ;
*/
typedef void * (__stdcall* AllocFunc)(size_t size, long lMMFParam) ;
typedef void * (__stdcall* ReAllocFunc)(void *data, size_t size, long lMMFParam) ;
typedef void (__stdcall* FreeFunc)(void *data, long lMMFParam) ;
class PTRCTRLDLL_API CPtrCtrl
{
public:
// modify a node
virtual int Set(int nPos, void *pNewData) = NULL ;
// add a node, return insert position
virtual int AddData(void* pData, int nPos=-1) = NULL ;
// add a array, the source array will be copied to current array,
// return list member count
virtual int AddPtrCtrl(CPtrCtrl *pPtrCtrl, int nPos=-1) = NULL ;
// copy a list, the source list will be copied to current list
// return list member count
virtual int CopyPtrCtrl(CPtrCtrl *pPtrCtrl) = NULL ;
// check if special pos available
virtual bool IsDataAvailable(int nPos) = NULL ;
// find data at special pos
// if no data in pos, return NULL,
// NOTE : sometimes, data is NULL, so you should check if the
// data is available
virtual void * GetAt(int nPos) = NULL ;
virtual void * GetHead(void) = NULL ;
virtual void * GetTail(void) = NULL ;
virtual int FindFirst(void *pData, FINDFUNC pfn=NULL) = NULL ;
virtual int FindNext(void *pData, FINDFUNC pfn=NULL) = NULL ;
// delete node at special pos
virtual void * DeleteAt(int nPos, int nCount=1) = NULL ;
virtual void * DeleteHead(void) = NULL ;
virtual void * DeleteTail(void) = NULL ;
// delete all
virtual void DeleteAll(void) = NULL ;
virtual void ClearAll(void) = NULL ;
virtual int GetSize(void) const= NULL ;
virtual int GetCount(void) const = NULL ;
virtual bool IsEmpty(void) const= NULL ;
// class name
virtual const char *GetClassName(void) const=NULL ;
// memeory manage function
virtual long GetMMFParam(void) const=NULL ;
virtual AllocFunc GetMMFAllocFunc(void) const=NULL ;
virtual ReAllocFunc GetMMFReAllocFunc(void) const=NULL ;
virtual FreeFunc GetMMFFreeFunc(void) const=NULL ;
};
class CPtrListCtrl ;
PTRCTRLDLL_API
CPtrListCtrl __stdcall operator+(CPtrListCtrl &sPtrCtrlAdd1, CPtrListCtrl &sPtrCtrlAdd2) ;
class PTRCTRLDLL_API CPtrListCtrl : public CPtrCtrl
{
typedef struct tagDATALIST
{
void *pData ;
struct tagDATALIST *next ;
struct tagDATALIST *pre ;
} DATALIST, * PDATALIST;
public:
CPtrListCtrl() ;
CPtrListCtrl(CPtrCtrl *pPtrCtrlInit) ;
CPtrListCtrl(long lMMFParam, AllocFunc pfMMFAlloc,
ReAllocFunc pfMMFReAlloc, FreeFunc pfMMFFree) ;
public:
~CPtrListCtrl() ;
public:
// modify a node
int Set(int nPos, void *pNewData) ;
// add a node, return insert position
int AddData(void* pData, int nPos=-1) ;
// add a list, the source list will be copied to current list,
// return list member count
int AddPtrCtrl(CPtrCtrl *pPtrCtrl, int nPos=-1) ;
// copy a list, the source list will be copied to current list
// return list member count
int CopyPtrCtrl(CPtrCtrl *pPtrCtrl) ;
// check if special pos available
bool IsDataAvailable(int nPos) ;
// find data at special pos
// if no data in pos, return NULL,
// NOTE : sometimes, data is NULL, so you should check if the
// data is available
void * GetAt(int nPos) ;
void * GetHead(void) ;
void * GetTail(void) ;
int FindFirst(void *pData, FINDFUNC pfn=NULL) ;
int FindNext(void *pData, FINDFUNC pfn=NULL) ;
void FindAll(CPtrCtrl *pPtrCtrl, void *pData, FINDFUNC pfn=NULL) ;
// delete node at special pos
void * DeleteAt(int nPos, int nCount=1) ;
void * DeleteHead(void) ;
void * DeleteTail(void) ;
// delete all
void DeleteAll(void) ;
void ClearAll(void) ;
int GetSize(void) const{return m_nSize;}
int GetCount(void) const{return m_nSize;}
bool IsEmpty(void) const{return (m_nSize <= 0);}
const char *GetClassName() const{return "CPtrListCtrl";}
long GetMMFParam(void) const{return m_lMMFParam;}
AllocFunc GetMMFAllocFunc(void) const{return m_pfMMFAlloc;}
ReAllocFunc GetMMFReAllocFunc(void) const{return m_pfMMFReAlloc;}
FreeFunc GetMMFFreeFunc(void) const{return m_pfMMFFree;}
CPtrListCtrl& operator=(CPtrCtrl &sPtrCtrlInit) ;
CPtrListCtrl& operator+=(CPtrCtrl &sPtrCtrlAdd) ;
private:
void * DeleteOne(int nPos) ;
PDATALIST SearchToPos(int nPos) ;
void SetCurPos(int nPos, PDATALIST pList) ;
void SetFindData(int nStartPos, int nFindPos) ;
bool FindDataAtPos(int nFindPos, void *pData, FINDFUNC pfn) ;
private:
DATALIST m_DataListHeader ;
PDATALIST m_pDataListTailer ;
PDATALIST m_pDataListCurPtr ;
int m_nSize ;
int m_nCurPos ;
FINDDATA m_FindData ;
public:
// Memory Manage Func
const long m_lMMFParam ;
const AllocFunc m_pfMMFAlloc ;
const ReAllocFunc m_pfMMFReAlloc ;
const FreeFunc m_pfMMFFree ;
};
class CPtrArrayCtrl ;
PTRCTRLDLL_API
CPtrArrayCtrl __stdcall operator+(CPtrArrayCtrl &sPtrCtrlAdd1, CPtrArrayCtrl &sPtrCtrlAdd2) ;
class PTRCTRLDLL_API CPtrArrayCtrl : public CPtrCtrl
{
typedef unsigned long DATAPTR ;
public:
CPtrArrayCtrl() ;
CPtrArrayCtrl(CPtrCtrl *pPtrCtrlInit) ;
CPtrArrayCtrl(long lMMFParam, AllocFunc pfMMFAlloc,
ReAllocFunc pfMMFReAlloc, FreeFunc pfMMFFree) ;
public:
~CPtrArrayCtrl() ;
public:
// modify a node
int Set(int nPos, void *pNewData) ;
// add a data, return insert position
int AddData(void* pData, int nPos=-1) ;
// add a array, the source array will be copied to current array,
// return list member count
int AddPtrCtrl(CPtrCtrl *pPtrCtrl, int nPos=-1) ;
// copy a array, the source list will be copied to current array
// return list member count
int CopyPtrCtrl(CPtrCtrl *pPtrCtrl) ;
// check if special pos available
bool IsDataAvailable(int nPos) ;
// find data at special pos
// if no data in pos, return NULL,
// NOTE : sometimes, data is NULL, so you should check if the
// data is available
void * GetAt(int nPos) ;
void * GetHead(void) ;
void * GetTail(void) ;
int FindFirst(void *pData, FINDFUNC pfn=NULL) ;
int FindNext(void *pData, FINDFUNC pfn=NULL) ;
void FindAll(CPtrCtrl *pPtrCtrl, void *pData, FINDFUNC pfn=NULL) ;
// delete data at special pos
void * DeleteAt(int nPos, int nCount=1) ;
void * DeleteHead(void) ;
void * DeleteTail(void) ;
// delete all
void DeleteAll(void) ;
void ClearAll(void) ;
int GetSize(void) const{return m_nSize;}
int GetCount(void) const{return m_nSize;}
bool IsEmpty(void) const{return (m_nSize <= 0);}
const char *GetClassName() const{return "CPtrArrayCtrl";}
long GetMMFParam(void) const{return m_lMMFParam;}
AllocFunc GetMMFAllocFunc(void) const{return m_pfMMFAlloc;}
ReAllocFunc GetMMFReAllocFunc(void) const{return m_pfMMFReAlloc;}
FreeFunc GetMMFFreeFunc(void) const{return m_pfMMFFree;}
CPtrArrayCtrl& operator=(CPtrCtrl &sPtrCtrlInit) ;
CPtrArrayCtrl& operator+=(CPtrCtrl &sPtrCtrlAdd) ;
int GetCapability(void) ;
private:
bool OnSizeChange(int nNewSize) ;
void SetCurPos(int nPos) ;
void SetFindData(int nStartPos, int nFindPos) ;
bool FindDataAtPos(int nFindPos, void *pData, FINDFUNC pfn) ;
private:
DATAPTR * m_pDataPtrAarry ;
int m_nSize ;
int m_nCapability ;
int m_nCurPos ;
FINDDATA m_FindData ;
// Memory Manage Func
long m_lMMFParam ;
AllocFunc m_pfMMFAlloc ;
ReAllocFunc m_pfMMFReAlloc ;
FreeFunc m_pfMMFFree ;
};
#endif //__PTRCTRL_HEADER__
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -