list.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. ** Command & Conquer Generals Zero Hour(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifndef __LIST_H
  19. #define __LIST_H
  20. const int LOWEST_PRIORITY = (int ) 0x80000000;
  21. const int HIGHEST_PRIORITY = (int) 0x7fffffff;
  22. const int NORMAL_PRIORITY = 0;
  23. class ListNode
  24. {
  25. private:
  26. ListNode *next;
  27. ListNode *prev;
  28. int pri; // node's priority
  29. protected:
  30. void *item; // item
  31. public:
  32. ListNode ( void );
  33. void Append ( ListNode *node );
  34. void Prepend ( ListNode *node );
  35. void Link ( ListNode *node);
  36. void Remove ( void );
  37. ListNode* Next ( void );
  38. ListNode* Prev ( void );
  39. ListNode* NextLoop ( void );
  40. ListNode* PrevLoop ( void );
  41. void* Item ( void );
  42. void SetItem ( void *item );
  43. int InList ( void );
  44. int IsHead ( void );
  45. int Priority ( void );
  46. void SetPriority ( int new_pri );
  47. };
  48. class List: public ListNode
  49. {
  50. public:
  51. List ( void );
  52. void AddToTail ( ListNode *node );
  53. void AddToHead ( ListNode *node );
  54. void Add ( ListNode *node );
  55. void Merge ( List *list );
  56. int NumItems ( void );
  57. void* Item ( int list_index );
  58. ListNode* FirstNode ( void );
  59. ListNode* LastNode ( void );
  60. int IsEmpty ( void );
  61. void Empty ( void );
  62. ListNode* Find ( void *item );
  63. };
  64. class ListSearch
  65. {
  66. List *head;
  67. ListNode *node;
  68. public:
  69. ListNode* Next ( void ) { if (node) { node = node->Next ();} return node;};
  70. ListNode* Prev ( void ) { if (node) { node = node->Prev ();} return node;};
  71. ListNode* FirstNode ( void ) { node = head; return Next (); };
  72. ListNode* LastNode ( void ) { node = head; return Prev (); };
  73. ListNode* FirstNode ( List *new_head ) { node = head = new_head; return Next (); };
  74. ListNode* LastNode ( List *new_head) { node = head = new_head; return Prev (); };
  75. };
  76. #endif // __LIST_H