home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / lib / libpics / htlist.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  4.9 KB  |  159 lines

  1.  
  2. /*  W3 Copyright statement 
  3. Copyright 1995 by: Massachusetts Institute of Technology (MIT), INRIA</H2>
  4.  
  5. This W3C software is being provided by the copyright holders under the
  6. following license. By obtaining, using and/or copying this software,
  7. you agree that you have read, understood, and will comply with the
  8. following terms and conditions: 
  9.  
  10. Permission to use, copy, modify, and distribute this software and its
  11. documentation for any purpose and without fee or royalty is hereby
  12. granted, provided that the full text of this NOTICE appears on
  13. <EM>ALL</EM> copies of the software and documentation or portions
  14. thereof, including modifications, that you make. 
  15.  
  16. <B>THIS SOFTWARE IS PROVIDED "AS IS," AND COPYRIGHT HOLDERS MAKE NO
  17. REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED.  BY WAY OF EXAMPLE,
  18. BUT NOT LIMITATION, COPYRIGHT HOLDERS MAKE NO REPRESENTATIONS OR
  19. WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR
  20. THAT THE USE OF THE SOFTWARE OR DOCUMENTATION WILL NOT INFRINGE ANY
  21. THIRD PARTY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS.
  22. COPYRIGHT HOLDERS WILL BEAR NO LIABILITY FOR ANY USE OF THIS SOFTWARE
  23. OR DOCUMENTATION.
  24.  
  25. The name and trademarks of copyright holders may NOT be used
  26. in advertising or publicity pertaining to the software without
  27. specific, written prior permission.  Title to copyright in this
  28. software and any associated documentation will at all times remain
  29. with copyright holders. 
  30. */
  31. /*                                                    W3C Reference Library libwww List Class
  32.                                       THE LIST CLASS
  33.                                              
  34.  */
  35. /*
  36. **      (c) COPYRIGHT MIT 1995.
  37. **      Please first read the full copyright statement in the file COPYRIGH.
  38. */
  39. /*
  40.  
  41.    The list class defines a generic container for storing collections of things in order.
  42.    In principle it could be implemented in many ways, but in practice knowing that it is a
  43.    linked list is important for speed.
  44.    
  45.    This module is implemented by HTList.c, and it is a part of the W3C Reference Library.
  46.    
  47.  */
  48. #ifndef HTLIST_H
  49. #define HTLIST_H
  50.  
  51. /* --- BEGIN added by mharmsen@netscape.com on 7/10/97 --- */
  52. #ifndef BOOL
  53. #define BOOL char
  54. #endif
  55. /* --- END added by mharmsen@netscape.com on 7/10/97 --- */
  56.  
  57. typedef struct _HTList HTList;
  58.  
  59. struct _HTList {
  60.   void * object;
  61.   HTList * next;
  62. };
  63. /*
  64.  
  65. CREATION AND DELETION METHODS
  66.  
  67.    These two functions create and deletes a list
  68.    
  69.  */
  70. extern HTList * HTList_new      (void);
  71. extern BOOL     HTList_delete   (HTList *me);
  72. /*
  73.  
  74. ADD AN ELEMENT TO LIST
  75.  
  76.    A new list element is added to the beginning of the list so that it is first element
  77.    just after the head element.
  78.    
  79.  */
  80. extern BOOL HTList_addObject (HTList *me, void *newObject);
  81. /*
  82.  
  83.    You can also append an element to the end of the list (the end is the first entered
  84.    object) by using the following function:
  85.    
  86.  */
  87. extern BOOL HTList_appendObject (HTList * me, void * newObject);
  88. /*
  89.  
  90. REMOVE LIST ELEMENTS
  91.  
  92.    You can delete elements in a list usin the following methods
  93.    
  94.  */
  95. extern BOOL     HTList_removeObject             (HTList *me, void *oldObject);
  96. extern void *   HTList_removeLastObject         (HTList *me);
  97. extern void *   HTList_removeFirstObject        (HTList *me);
  98. /*
  99.  
  100. SIZE OF A LIST
  101.  
  102.    Two small function to ask for the size
  103.    
  104.  */
  105. #define         HTList_isEmpty(me)              (me ? me->next == NULL : YES)
  106. extern int      HTList_count                    (HTList *me);
  107. /*
  108.  
  109. REFERENCE LIST ELEMENTS BY INDEX
  110.  
  111.    In some situations is is required to use an index in order to refer to a list element.
  112.    This is for example the case if an element can be registered multiple times.
  113.    
  114.  */
  115. extern int      HTList_indexOf  (HTList *me, void *object);
  116. extern void *   HTList_objectAt (HTList *me, int position);
  117. /*
  118.  
  119. FIND LIST ELEMENTS
  120.  
  121.    This method returns the _last_ element to the list or NULL if list is empty
  122.    
  123.  */
  124. #define         HTList_lastObject(me) \
  125.                 ((me) && (me)->next ? (me)->next->object : NULL)
  126. /*
  127.  
  128.    This method returns the _first_ element to the list or NULL if list is empty
  129.    
  130.  */
  131. extern void * HTList_firstObject  (HTList * me);
  132. /*
  133.  
  134. TRAVERSE LIST
  135.  
  136.    Fast macro to traverse the list. Call it first with copy of list header: it returns the
  137.    first object and increments the passed list pointer. Call it with the same variable
  138.    until it returns NULL.
  139.    
  140.  */
  141. #define         HTList_nextObject(me) \
  142.                 ((me) && (((me) = (me)->next) != NULL) ? (me)->object : NULL)
  143. /*
  144.  
  145. FREE LIST
  146.  
  147.  */
  148. #define HTList_free(x)  HT_FREE(x)
  149.  
  150. #endif /* HTLIST_H */
  151. /*
  152.  
  153.    
  154.    ___________________________________
  155.    
  156.                             @(#) $Id: htlist.h,v 3.1 1998/03/28 03:32:07 ltabb Exp $
  157.                                                                                           
  158.     */
  159.