SLNODE.H 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. /***************************************************************************
  19. * *
  20. * Project Name : G *
  21. * *
  22. * File Name : SLNODE.H *
  23. * *
  24. * Programmer : Philip W. Gorrow *
  25. * *
  26. * Start Date : 03/11/97 *
  27. * *
  28. * Last Update : March 11, 1997 [PWG] *
  29. * *
  30. *-------------------------------------------------------------------------*
  31. * Functions: *
  32. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  33. #if _MSC_VER >= 1000
  34. #pragma once
  35. #endif // _MSC_VER >= 1000
  36. #ifndef __SLNODE_H__
  37. #define __SLNODE_H__
  38. #ifndef ALWAYS_H
  39. #include "always.h"
  40. #endif
  41. #include "mempool.h"
  42. #ifndef NULL
  43. #define NULL 0
  44. #endif
  45. // Forward references for friend classes
  46. template <class T> class SList;
  47. //
  48. // The node class is responsible for maintaining the links between
  49. // data in a linked list. It works with the Single List Class to
  50. // manage a singularly linked list of objects.
  51. //
  52. class GenericSLNode : public AutoPoolClass<GenericSLNode, 256>
  53. {
  54. protected:
  55. void* Internal_Get_Next(void) { return NodeNext; };
  56. void Internal_Set_Next(void* n) { NodeNext=n; };
  57. void *Internal_Get_Data(void) { return NodeData; };
  58. void Internal_Get_Data(void* d) { NodeData=d; };
  59. //
  60. // Note that their is only one constructor for this class and it
  61. // requires you to provide an object. Furthermore it can be
  62. // created from anything but a friend or parent class.
  63. //
  64. GenericSLNode(void *obj)
  65. {NodeData = obj; NodeNext = 0; };
  66. //
  67. // You cannot declare a node class without giving it a data object.
  68. // Defining this type of constructor as private to the class insures
  69. // that it cannot be used.
  70. //
  71. private:
  72. GenericSLNode(void) {};
  73. void *NodeNext; // Next Node in the list chain
  74. void *NodeData; // Current Node in the list chain
  75. };
  76. template <class T>
  77. class SLNode : public GenericSLNode
  78. {
  79. public:
  80. //
  81. // Since the list class manages the Node Class it must be able to
  82. // access its private data.
  83. //
  84. friend class SList<T>;
  85. SLNode<T>* Next(void) { return reinterpret_cast<SLNode<T>*>(Internal_Get_Next()); }
  86. T *Data(void) { return reinterpret_cast<T*>(Internal_Get_Data()); }
  87. void Set_Next(SLNode<T>* n) { Internal_Set_Next(reinterpret_cast<void*>(n)); }
  88. protected:
  89. //
  90. // Note that their is only one constructor for this class and it
  91. // requires you to provide an object. Furthermore it can be
  92. // created from anything but a friend or parent class.
  93. //
  94. SLNode(T *obj) : GenericSLNode(obj) {}
  95. //
  96. // You cannot declare a node class without giving it a data object.
  97. // Defining this type of constructor as private to the class insures
  98. // that it cannot be used.
  99. //
  100. private:
  101. SLNode(void) {};
  102. };
  103. #endif