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

  1. /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. #ifndef XPLIST_H
  20. #define XPLIST_H
  21.  
  22. #include "xp_core.h"
  23.  
  24. /* generic list structure
  25.  */
  26. struct _XP_List {
  27.   void            * object;
  28.   struct _XP_List * next;
  29.   struct _XP_List * prev;
  30. };
  31.  
  32. XP_BEGIN_PROTOS
  33.  
  34. extern XP_List * XP_ListNew (void);
  35. extern void XP_ListDestroy (XP_List *list);
  36.  
  37. extern void     XP_ListAddObject (XP_List *list, void *newObject);
  38. extern void     XP_ListAddObjectToEnd (XP_List *list, void *newObject);
  39. extern void     XP_ListInsertObject (XP_List *list, void *insert_before, void *newObject);
  40. extern void XP_ListInsertObjectAfter (XP_List *list, void *insert_after, void *newObject);
  41.  
  42.  
  43. /* returns the list node of the specified object if it was
  44.  * in the list
  45.  */
  46. extern XP_List * XP_ListFindObject (XP_List *list, void * obj);
  47.  
  48.  
  49. extern Bool     XP_ListRemoveObject (XP_List *list, void *oldObject);
  50. extern void *   XP_ListRemoveTopObject (XP_List *list);
  51. extern void *   XP_ListPeekTopObject (XP_List *list);
  52. extern void *   XP_ListRemoveEndObject (XP_List *list);
  53. #define         XP_ListIsEmpty(list) (list ? list->next == NULL : TRUE)
  54. extern int      XP_ListCount (XP_List *list);
  55. #define         XP_ListTopObject(list) (list && list->next ? list->next->object : NULL)
  56.  
  57. extern void *   XP_ListGetEndObject (XP_List *list);
  58. extern void * XP_ListGetObjectNum (XP_List *list, int num);
  59. extern int    XP_ListGetNumFromObject (XP_List *list, void * object);
  60.  
  61. /* move the top object to the bottom of the list
  62.  * this function is useful for reordering the list
  63.  * so that a round robin ordering can occur
  64.  */
  65. extern void XP_ListMoveTopToBottom (XP_List *list);
  66.  
  67.  
  68. XP_END_PROTOS
  69.  
  70. /* traverse the list in order
  71.  *
  72.  * make a copy of the list pointer and point it at the list object head.
  73.  * the first call the XP_ListNextObject will return the first object
  74.  * and increment the copy of the list pointer.  Subsequent calls
  75.  * will continue to increment the copy of the list pointer and return
  76.  * objects
  77.  */
  78. #define XP_ListNextObject(list) \
  79.   (list && ((list = list->next)!=0) ? list->object : NULL)
  80.  
  81. #endif /* XPLIST_H */
  82.