HTList.h
Upload User: zlh9724
Upload Date: 2007-01-04
Package Size: 1991k
Code Size: 3k
Category:

Browser Client

Development Platform:

Unix_Linux

  1. /*                                                                          Linked List Class
  2.                                        LIST OBJECT
  3.                                              
  4.  */
  5. /*
  6. **      (c) COPYRIGHT MIT 1995.
  7. **      Please first read the full copyright statement in the file COPYRIGH.
  8. */
  9. /*
  10.    The list object is a generic container for storing collections of things in order.  In
  11.    principle it could be implemented in many ways, but in practice knowing that it is a
  12.    linked list is important for speed.
  13.    
  14.    This module is implemented by HTList.c, and it is a part of the  W3C Reference Library.
  15.    
  16.  */
  17. #ifndef HTLIST_H
  18. #define HTLIST_H
  19. typedef struct _HTList HTList;
  20. struct _HTList {
  21.   void * object;
  22.   HTList * next;
  23. };
  24. /*
  25. Creation and Deletion Methods
  26.    These two functions create and deletes a list
  27.    
  28.  */
  29. extern HTList * HTList_new      (void);
  30. extern BOOL     HTList_delete   (HTList *me);
  31. /*
  32. Add an Element to List
  33.    A new list element is added to the beginning of the list so that it is first element
  34.    just after the head element.
  35.    
  36.  */
  37. extern BOOL     HTList_addObject (HTList *me, void *newObject);
  38. /*
  39.    You can also append an element to the end of the list (the end is the first entered
  40.    object) by using the following function:
  41.    
  42.  */
  43. extern BOOL HTList_appendObject (HTList * me, void * newObject);
  44. /*
  45. Remove List Elements
  46.  */
  47. extern BOOL     HTList_removeObject             (HTList *me, void *oldObject);
  48. extern void *   HTList_removeLastObject         (HTList *me);
  49. extern void *   HTList_removeFirstObject        (HTList *me);
  50. /*
  51. Size of a List
  52.    Two small function to ask for the size
  53.    
  54.  */
  55. #define         HTList_isEmpty(me)              (me ? me->next == NULL : YES)
  56. extern int      HTList_count                    (HTList *me);
  57. /*
  58. Reference List Elements By Index
  59.    In some situations is is required to use an index in order to refer to a list element.
  60.    This is for example the case if an element can be registered multiple times.
  61.    
  62.  */
  63. extern int      HTList_indexOf  (HTList *me, void *object);
  64. extern void *   HTList_objectAt (HTList *me, int position);
  65. /*
  66. Find Last Element Added
  67.  */
  68. #define         HTList_lastObject(me) 
  69.                 ((me) && (me)->next ? (me)->next->object : NULL)
  70. /*
  71. Traverse list
  72.    Fast macro to traverse the list.  Call it first with copy of list header: it returns
  73.    the first object and increments the passed list pointer.  Call it with the same
  74.    variable until it returns NULL.
  75.    
  76.  */
  77. #define         HTList_nextObject(me) 
  78.                 ((me) && ((me) = (me)->next) ? (me)->object : NULL)
  79. /*
  80. Free list
  81.  */
  82. #define HTList_free(x)  HT_FREE(x)
  83. #endif /* HTLIST_H */
  84. /*
  85.    end */