Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * This file is part of libdom test suite.
  3.  * Licensed under the MIT License,
  4.  *                http://www.opensource.org/licenses/mit-license.php
  5.  * Copyright 2007 James Shaw <jshaw@netsurf-browser.org>
  6.  */
  7.  
  8. #ifndef list_h_
  9. #define list_h_
  10.  
  11. #include <stdbool.h>
  12.  
  13. #include "comparators.h"
  14.  
  15. /* The element type in the list
  16.  *
  17.  * The high byte is used for category type
  18.  * The low byte is used for concrete type
  19.  */
  20. typedef enum TYPE {
  21.         INT = 0x0001,
  22.         STRING = 0x0100,
  23.         DOM_STRING = 0x0101,
  24.         NODE = 0x0200
  25. } TYPE;
  26.  
  27.  
  28. struct list_elt {
  29.         void* data;
  30.         struct list_elt* next;
  31. };
  32.  
  33. typedef struct list {
  34.         unsigned int size;
  35.         TYPE type;
  36.         struct list_elt* head;
  37.         struct list_elt* tail;
  38. } list;
  39.  
  40. struct list* list_new(TYPE type);
  41. void list_destroy(struct list* list);
  42.  
  43. /**
  44.  * Add data to the tail of the list.
  45.  */
  46. void list_add(struct list* list, void* data);
  47.  
  48. /**
  49.  * Remove element containing data from list.
  50.  * The list element is freed, but the caller must free the data itself
  51.  * if necessary.
  52.  *
  53.  * Returns true if data was found in the list.
  54.  */
  55. bool list_remove(struct list* list, void* data);
  56.  
  57. struct list* list_clone(struct list* list);
  58. /**
  59.  * Tests if data is equal to any element in the list.
  60.  */
  61. bool list_contains(struct list* list, void* data,
  62.                 comparator comparator);
  63.  
  64. /**
  65.  * Tests if superlist contains all elements in sublist.  Order is not important.
  66.  */
  67. bool list_contains_all(struct list* superList, struct list* subList,
  68.                 comparator comparator);
  69.  
  70. #endif
  71.