/*	List.h - Generic List Handling Routines
*
*******************************************************************************
* Copyright (c) 1996-97 Digi International Inc., All Rights Reserved          *
*                                                                             *
* This  software  contains  proprietary  and  confidential   information   of *
* Digi International  Inc.   By  accepting  transfer  of this copy, Recipient *
* agrees to retain this software in  confidence,  to  prevent  disclosure  to *
* others,  and  to make no  use of this software other than that for which it *
* was delivered.  This is an unpublished copyright work  Digi   International *
* Inc.    Except   as   permitted   by  federal  law,  17 USC 117, copying is *
* strictly prohibited.                                                        *
*                                                                             *
* Digi  International  Inc.  CONFIDENTIAL  -   (Digi    International    Inc. *
* Confidential  when   combined   with   the   aggregated  modules  for  this *
* product) OBJECT CODE ONLY SOURCE MATERIALS                                  *
*                                                                             *
* (C) COPYRIGHT Digi International Inc. 1996-97                               *
*                                                                             *
* All Rights Reserved                                                         *
*                                                                             *
* US   Government   Users   Restricted   Rights   -   Use,   duplication   or *
* disclosure  restricted by GSA ADP Schedule Contract with Digi International *
* Inc.                                                                        *
*                                                                             *
*******************************************************************************
*
*/

#if !defined(__LIST_H__)
#define	__LIST_H__

typedef struct LIST
{
	struct LIST * pNext;
	struct LIST * pPrevious;
}
LIST;

#define	DataToList(p)	((p) == NULL ? NULL : ((LIST *) (((BYTE *) (p)) - sizeof (LIST))))
#define	ListToData(p)	((p) == NULL ? NULL : ((void *) (((BYTE *) (p)) + sizeof (LIST))))

#define	FirstItem(h)	ListToData((h)->pNext)
#define	PreviousItem(p)	ListToData(DataToList(p)->pPrevious)
#define	NextItem(p)		ListToData(DataToList(p)->pNext)

#define	IsEmpty(h)		(FirstItem(h) == NULL)
#define Init(h)			((h)->pNext = NULL, (h)->pPrevious = NULL)

typedef BOOL (CALLBACK *ONEACH_FUNCTION)(void * const pvData, void * const pvUserData);
typedef void (CALLBACK *ONALL_FUNCTION)(void * const pvData, void * const pvUserData);

void * WINAPI Add(LIST * const pHead, void const * const pDataToAdd, size_t const cbData);
void * WINAPI Find(LIST const * const pHead, void const * const pDataToFind, size_t const cbDataToFind, size_t const cbOffsetDataToFind);
size_t WINAPI Count(LIST const * const pHead);
VOID WINAPI ForEach(LIST const * const pHead, ONEACH_FUNCTION OnEachFunction, void * const pvUserData);
VOID WINAPI ForAll(LIST const * const pHead, ONALL_FUNCTION OnAllFunction, void * const pvUserData);
VOID WINAPI Delete(LIST * const pHead, void const * const pDataToDelete);
VOID WINAPI Clear(LIST * const pHead);

#endif