1
0

LinkedList.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /* ---------------------------------------------------------------------------
  2. Nullsoft Database Engine
  3. --------------------
  4. codename: Near Death Experience
  5. --------------------------------------------------------------------------- */
  6. /* ---------------------------------------------------------------------------
  7. Double-Linked List Class Prototypes
  8. --------------------------------------------------------------------------- */
  9. #ifndef __LINKEDLIST_H
  10. #define __LINKEDLIST_H
  11. class LinkedListEntry
  12. {
  13. public:
  14. LinkedListEntry *Next;
  15. LinkedListEntry *Previous;
  16. public:
  17. LinkedListEntry *GetNext() const;
  18. LinkedListEntry *GetPrevious() const;
  19. LinkedListEntry();
  20. virtual ~LinkedListEntry();
  21. };
  22. template <class T> class VListEntry : public LinkedListEntry
  23. {
  24. public:
  25. void SetVal(T val)
  26. {
  27. Val = val;
  28. }
  29. T GetVal(void)
  30. {
  31. return Val;
  32. }
  33. private:
  34. T Val;
  35. };
  36. template <class T> class PListEntry : public LinkedListEntry
  37. {
  38. public:
  39. void SetVal(T *val)
  40. {
  41. Val = val;
  42. }
  43. T *GetVal(void)
  44. {
  45. return Val;
  46. }
  47. private:
  48. T *Val;
  49. };
  50. typedef bool (*WalkListProc)(LinkedListEntry *Entry, int, void*, void*);
  51. class LinkedList
  52. {
  53. protected:
  54. int NElements;
  55. LinkedListEntry *Head;
  56. LinkedListEntry *Foot;
  57. public:
  58. LinkedList();
  59. ~LinkedList();
  60. void AddEntry(LinkedListEntry *Entry, bool Cat);
  61. void RemoveEntry(LinkedListEntry *Entry);
  62. void WalkList(WalkListProc WalkProc, int ID, void *Data1, void *Data2);
  63. int GetNElements(void) { return NElements; }
  64. LinkedListEntry *GetHead(void) { return Head; }
  65. LinkedListEntry *GetFoot(void) { return Foot; }
  66. };
  67. #endif