home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / winbase / debug / deb / linklist.h < prev    next >
C/C++ Source or Header  |  1997-10-05  |  5KB  |  118 lines

  1. // ************************************************************************
  2. //
  3. //                      Microsoft Developer Support
  4. //             Copyright (c) 1992-1997 Microsoft Corporation
  5. //
  6. // ************************************************************************
  7. // HEADER    : LinkList.H - Ordered Double Linked List Package
  8. // PURPOSE   : Provide a general, sorted, double linked list package
  9. // FUNCTIONS :
  10. //   CreateList        - allocate memory for a new list, registers the
  11. //                       ordering function
  12. //   CreateNode        - allocate memory fpr a new node that can be put
  13. //                       into the linked list
  14. //   InsertNode        - insert a new node into the list
  15. //   SetCurrentNode    - finds the 1st occurence of a node that matches
  16. //                       a key(s) according to the match function
  17. //                       and sets it as the current node
  18. //   SetCurrentNodeEx  - finds the Nth occurence of a node that matches
  19. //                       a key(s) according to the match function
  20. //                       and sets it as the current node
  21. //   GetCurrentNode    - get the current node
  22. //   GetFirstNode      - get the first (left-most) node in the list
  23. //   GetLastNode       - get the last (right-most) node in the list
  24. //   GetNextNode       - get the next (right) node from the current
  25. //   GetPrevNode       - get the previous (left) node from the current
  26. //   DeleteCurrentNode - deletes the current node from the list and
  27. //                       frees the memory associated with it
  28. //   DestroyNode       - deallocates the memory associated with a node
  29. //   DestroyList       - deallocates the memory associated with a list,
  30. //                       does not delete any of the nodes
  31. //   GetListError      - gets the current list error
  32. //
  33. // COMMENTS  : The application must serialize access to the linked list
  34. //
  35. //   Format of the Ordering and Matching functions is as follows:
  36. //   -----------------------------------------------------------
  37. //
  38. //   int OrderFunc( PNODE pNodeOne, PNODE pNodeTwo )
  39. //   {
  40. //     if( (pNodeOne->pNodeData).SortKey < (pNodeTwo->pNodeData).SortKey )
  41. //       return( LIST_LEFT_OF );
  42. //     if( (pNodeOne->pNodeData).SortKey > (pNodeTwo->pNodeData).SortKey )
  43. //       return( LIST_RIGHT_OF );
  44. //     return( LIST_MATCH );
  45. //   }
  46. //
  47. // ************************************************************************
  48. #ifndef LINKLIST_H
  49.  
  50.  #define LINKLIST_H
  51.  
  52.  #ifdef __cplusplus
  53.  extern "C" { /* Assume C declarations for C++ */
  54.  #endif /* __cplusplus */
  55.  
  56.  // public typedefs and defines
  57.  // -----------------------------------------------------------------------
  58.  #define LIST_NO_ERROR                 1
  59.  #define LIST_ERROR_NO_NODE           -1
  60.  #define LIST_ERROR_NO_MATCH          -2
  61.  #define LIST_ERROR_NO_FREE_MEM       -3
  62.  #define LIST_ERROR_DEREFERENCE_NULL -99
  63.  
  64.  #define LIST_LEFT_OF   -1
  65.  #define LIST_MATCH      0
  66.  #define LIST_RIGHT_OF   1
  67.  
  68.  #ifndef TRUE
  69.    #define TRUE  1
  70.    #define FALSE 0
  71.    typedef int   BOOL;
  72.  #endif
  73.  
  74.  typedef void* PVOID;
  75.  
  76.  //-- definition of a node
  77.  typedef struct NODE_STRUCT* PNODE;
  78.  typedef struct NODE_STRUCT {
  79.            PVOID pNodeData;
  80.            PNODE pLeftLink;
  81.            PNODE pRightLink;
  82.          } NODE;
  83.  
  84.  //-- definition of a list
  85.  typedef struct LIST_STRUCT* PLIST;
  86.  typedef struct LIST_STRUCT {
  87.            PVOID pListData;
  88.            PNODE pFirstNode;
  89.            PNODE pCurrentNode;
  90.            PNODE pLastNode;
  91.            int   (*OrderFunction)(PNODE, PNODE);
  92.            int   ListError;
  93.          } LIST;
  94.  
  95.  // public function prototypes
  96.  // -----------------------------------------------------------------------
  97.  BOOL CreateList( PLIST* ppList, int (*OrderFunction)( PNODE pNodeOne, PNODE pNodeTwo ) );
  98.  BOOL CreateNode( PNODE* ppNewNode );
  99.  BOOL InsertNode( PLIST pList, PNODE pNewNode );
  100.  BOOL SetCurrentNode( PLIST pList, PNODE pKeyNode, int (*MatchFunction)( PNODE pNodeOne, PNODE pNodeTwo ) );
  101.  BOOL SetCurrentNodeEx( PLIST pList, PNODE pKeyNode, int (*MatchFunction)( PNODE pNodeOne, PNODE pNodeTwo ), int Occurence );
  102.  BOOL GetCurrentNode( PLIST pList, PNODE* ppNode );
  103.  BOOL GetFirstNode( PLIST pList, PNODE* ppNode );
  104.  BOOL GetLastNode( PLIST pList, PNODE* ppNode );
  105.  BOOL GetNextNode( PLIST pList, PNODE* ppNode );
  106.  BOOL GetPrevNode( PLIST pList, PNODE* ppNode );
  107.  BOOL DeleteCurrentNode( PLIST pList );
  108.  BOOL DestroyNode( PNODE pNode );
  109.  BOOL DestroyList( PLIST pList );
  110.  int  GetListError( PLIST pList );
  111.  
  112.  #ifdef __cplusplus
  113.  }
  114.  #endif /* __cplusplus */
  115.  
  116.  
  117. #endif // LINKLIST_H
  118.