#ifndef _LISTING_H_
#define _LISTING_H_

#define ADD_LISTING_LOOP(a , b) { (a)++ ; (b) = (b)->pNext ;}
#define SUB_LISTING_LOOP(a , b) { (a)-- ; (b) = (b)->pPrev ;}

typedef struct tagListing LISTING;
typedef struct tagListing
{
	LISTING*   	pPrev;
	LISTING*    pNext;
	void FAR *   pUser;
	DWORD       dwReserved;
}LISTING,*LPLISTING;

typedef struct tagListingBoot
{
	LISTING*        pHead;
	LISTING*        pHeal;
	int		nLength;
}LISTINGBOOT;

BOOL InitListing(LISTING* pListing);

class CListManager
{
private:
	LISTINGBOOT	m_Root;
	void FAR        (*m_pDeleteFc)(void FAR *);
	int FAR         (*m_pCompareFc)(void FAR *,void FAR *);
private:
	BOOL            DeleteNode(void* pNode , BOOL bUser);
public:
	int             GetLength(){ return(m_Root.nLength);}
	LISTING*	GetHead(){return(m_Root.pHead);}
	LISTING*	GetHeal(){return(m_Root.pHeal);}

	static void     InitNode(LISTING* pNode);

	void		SetDeleteFc(void FAR (*pFc)(void FAR *)){ m_pDeleteFc = pFc;}
	void		SetCompareFc(int FAR (*pFc)(void FAR *,void FAR *)){ m_pCompareFc = pFc;}

	BOOL		AddHead(LISTING* pListing);
	BOOL		AddHeal(LISTING* pListing);
	BOOL	        AddUserToTail(void* pUser);

	BOOL            DeleteHead();
	BOOL            DeleteHeal();
	BOOL		DeleteAllNode();

	BOOL  		DeleteUser(void* pUser);
	BOOL		DeleteNode(LISTING* pNode);
	BOOL		DeleteNode(int nIndex);

	LISTING*        GetNode(int nIndex);
	void*           GetUser(int nIndex);

	LISTING*        Find(void FAR *pUser,int nSign = 0);

public:
	CListManager();
	~CListManager();

};

BOOL InitListing(LISTING* pListing);


#endif