Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
4.5 KiB

  1. //------------------------------------------------------------------------------------------
  2. // list.hpp
  3. //
  4. // Data structures to manage link lists.
  5. //
  6. // A list can contain any type of data structure as an item on the list: thread control
  7. // blocks, pending interrupts, etc. That is why each item is a "void *", or in other words,
  8. // a "pointers to anything".
  9. //------------------------------------------------------------------------------------------
  10. #ifndef LIST_HPP
  11. #define LIST_HPP
  12. #include <stddef.h>
  13. #include "unidef.h"
  14. //------------------------------------------------------------------------------------------
  15. // This declares the type "VoidFunctionPtr" to be a "pointer to a function taking an
  16. // integer argument and returning nothing". With such a function pointer
  17. // (say it is "func"), we can call it like this:
  18. //
  19. // (*func) (17);
  20. //
  21. // Used by MapCar in list.h
  22. //------------------------------------------------------------------------------------------
  23. typedef void (*VoidFunctionPtr)(void * arg);
  24. //------------------------------------------------------------------------------------------
  25. // The following class defines a list element -- which is used to keep track of one item
  26. // on a list.
  27. //
  28. // Internal data structures kept public so that List operations can access them directly.
  29. //------------------------------------------------------------------------------------------
  30. class ListElement
  31. {
  32. public:
  33. ListElement(void *itemPtr, int sortKey); // initialize a list element
  34. ListElement *next; // next element on list,
  35. // NULL if this is the last
  36. ListElement *previous; // previous element on the list
  37. // NULL if this is the first element
  38. int key; // priority, for a sorted list
  39. void *item; // pointer to item on the list
  40. protected:
  41. ListElement();
  42. };
  43. //------------------------------------------------------------------------------------------
  44. // The following class defines a "list" -- a singly linked list of
  45. // list elements, each of which points to a single item on the list.
  46. //
  47. // By using the "Sorted" functions, the list can be kept in sorted
  48. // in increasing order by "key" in ListElement.
  49. //------------------------------------------------------------------------------------------
  50. class List
  51. {
  52. public:
  53. List(); // initialize the list
  54. ~List(); // de-allocate the list
  55. void Prepend(void *item); // Put item at the beginning of the list
  56. void Append(void *item); // Put item at the end of the list
  57. void* Remove(); // Take item off the front of the list
  58. virtual void Flush(); // Remove everything in the list
  59. void Mapcar(VoidFunctionPtr func); // Apply "func" to every element on the list
  60. bool IsEmpty(); // is the list empty?
  61. void insertAfter(ListElement * listEl, void *item);
  62. void insertBefore(ListElement * listEl, void *item);
  63. void removeAt(ListElement * listEl);
  64. // Routines to put/get items on/off list in order (sorted by key)
  65. void SortedInsert(void *item, int sortKey);// Put item into list
  66. void* SortedRemove(int *keyPtr); // Remove first item from list
  67. int length; // Length of list
  68. ListElement *first; // Head of the list, NULL if list is empty
  69. ListElement *last; // Last element of list
  70. // Interator function.
  71. virtual void MoveFirst();
  72. virtual bool MoveNext();
  73. void* GetData();
  74. ListElement *iterator;
  75. };
  76. #endif // LIST_HPP