definitionfactorymgr.cpp 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : WWSaveLoad *
  23. * *
  24. * $Archive:: /VSS_Sync/wwsaveload/definitionfactorymgr.cpp $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 10/16/00 11:42a $*
  29. * *
  30. * $Revision:: 12 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "definitionfactorymgr.h"
  36. #include "definitionfactory.h"
  37. #include "wwdebug.h"
  38. #include <string.h>
  39. #ifdef _UNIX
  40. #include "osdep.h"
  41. #endif
  42. ////////////////////////////////////////////////////////////////////////////
  43. // Static member initialization
  44. ////////////////////////////////////////////////////////////////////////////
  45. DefinitionFactoryClass *DefinitionFactoryMgrClass::_FactoryListHead = 0;
  46. ////////////////////////////////////////////////////////////////////////////
  47. //
  48. // Find_Factory
  49. //
  50. ////////////////////////////////////////////////////////////////////////////
  51. DefinitionFactoryClass *
  52. DefinitionFactoryMgrClass::Find_Factory (uint32 class_id)
  53. {
  54. DefinitionFactoryClass *factory = 0;
  55. //
  56. // Loop through all the factories and see if we can
  57. // find the one who owns the corresponding class-id.
  58. //
  59. for ( DefinitionFactoryClass *curr_factory = _FactoryListHead;
  60. (factory == 0) && (curr_factory != 0);
  61. curr_factory = curr_factory->m_NextFactory) {
  62. //
  63. // Is this the factory we were looking for?
  64. //
  65. if (curr_factory->Get_Class_ID () == class_id) {
  66. factory = curr_factory;
  67. }
  68. }
  69. return factory;
  70. }
  71. ////////////////////////////////////////////////////////////////////////////
  72. //
  73. // Find_Factory
  74. //
  75. ////////////////////////////////////////////////////////////////////////////
  76. DefinitionFactoryClass *
  77. DefinitionFactoryMgrClass::Find_Factory (const char *name)
  78. {
  79. DefinitionFactoryClass *factory = 0;
  80. //
  81. // Loop through all the factories and see if we can
  82. // find the one who owns the corresponding class-id.
  83. //
  84. for ( DefinitionFactoryClass *curr_factory = _FactoryListHead;
  85. (factory == 0) && (curr_factory != 0);
  86. curr_factory = curr_factory->m_NextFactory) {
  87. //
  88. // Is this the factory we were looking for?
  89. //
  90. if (::stricmp (curr_factory->Get_Name (), name) == 0) {
  91. factory = curr_factory;
  92. }
  93. }
  94. return factory;
  95. }
  96. ////////////////////////////////////////////////////////////////////////////
  97. //
  98. // Get_First
  99. //
  100. ////////////////////////////////////////////////////////////////////////////
  101. DefinitionFactoryClass *
  102. DefinitionFactoryMgrClass::Get_First (uint32 superclass_id)
  103. {
  104. DefinitionFactoryClass *factory = 0;
  105. //
  106. // Loop through all the factories and see if we can
  107. // find the next one that belongs to the given superclass
  108. //
  109. for ( DefinitionFactoryClass *curr_factory = _FactoryListHead;
  110. (factory == 0) && (curr_factory != 0);
  111. curr_factory = curr_factory->m_NextFactory) {
  112. //
  113. // Is this the factory we were looking for?
  114. //
  115. if (::SuperClassID_From_ClassID (curr_factory->Get_Class_ID ()) == superclass_id) {
  116. factory = curr_factory;
  117. }
  118. }
  119. return factory;
  120. }
  121. ////////////////////////////////////////////////////////////////////////////
  122. //
  123. // Get_Next
  124. //
  125. ////////////////////////////////////////////////////////////////////////////
  126. DefinitionFactoryClass *
  127. DefinitionFactoryMgrClass::Get_Next
  128. (
  129. DefinitionFactoryClass *curr_factory,
  130. uint32 superclass_id
  131. )
  132. {
  133. DefinitionFactoryClass *factory = 0;
  134. //
  135. // Loop through all the factories and see if we can
  136. // find the next one that belongs to the given superclass
  137. //
  138. while ((factory == NULL) && ((curr_factory = curr_factory->m_NextFactory) != NULL)) {
  139. //
  140. // Is this the factory we were looking for?
  141. //
  142. if (::SuperClassID_From_ClassID (curr_factory->Get_Class_ID ()) == superclass_id) {
  143. factory = curr_factory;
  144. }
  145. }
  146. return factory;
  147. }
  148. ////////////////////////////////////////////////////////////////////////////
  149. //
  150. // Get_First
  151. //
  152. ////////////////////////////////////////////////////////////////////////////
  153. DefinitionFactoryClass *
  154. DefinitionFactoryMgrClass::Get_First (void)
  155. {
  156. return _FactoryListHead;
  157. }
  158. ////////////////////////////////////////////////////////////////////////////
  159. //
  160. // Get_Next
  161. //
  162. ////////////////////////////////////////////////////////////////////////////
  163. DefinitionFactoryClass *
  164. DefinitionFactoryMgrClass::Get_Next (DefinitionFactoryClass *curr_factory)
  165. {
  166. DefinitionFactoryClass *factory = 0;
  167. //
  168. // Simply return the next factory in the chain
  169. //
  170. if (curr_factory != NULL) {
  171. factory = curr_factory->m_NextFactory;
  172. }
  173. return factory;
  174. }
  175. ////////////////////////////////////////////////////////////////////////////
  176. //
  177. // Register_Factory
  178. //
  179. ////////////////////////////////////////////////////////////////////////////
  180. void
  181. DefinitionFactoryMgrClass::Register_Factory (DefinitionFactoryClass *factory)
  182. {
  183. WWASSERT (factory->m_NextFactory == 0);
  184. WWASSERT (factory->m_PrevFactory == 0);
  185. Link_Factory (factory);
  186. return ;
  187. }
  188. ////////////////////////////////////////////////////////////////////////////
  189. //
  190. // Unregister_Factory
  191. //
  192. ////////////////////////////////////////////////////////////////////////////
  193. void
  194. DefinitionFactoryMgrClass::Unregister_Factory (DefinitionFactoryClass *factory)
  195. {
  196. WWASSERT (factory != 0);
  197. Unlink_Factory (factory);
  198. return ;
  199. }
  200. ////////////////////////////////////////////////////////////////////////////
  201. //
  202. // Link_Factory
  203. //
  204. ////////////////////////////////////////////////////////////////////////////
  205. void
  206. DefinitionFactoryMgrClass::Link_Factory (DefinitionFactoryClass *factory)
  207. {
  208. WWASSERT (factory->m_NextFactory == 0);
  209. WWASSERT (factory->m_PrevFactory == 0);
  210. // Adding this factory in front of the current head of the list
  211. factory->m_NextFactory = _FactoryListHead;
  212. // If the list wasn't empty, link the next factory back to this factory
  213. if (factory->m_NextFactory != 0) {
  214. factory->m_NextFactory->m_PrevFactory = factory;
  215. }
  216. // Point the head of the list at this factory now
  217. _FactoryListHead = factory;
  218. return ;
  219. }
  220. ////////////////////////////////////////////////////////////////////////////
  221. //
  222. // Unlink_Factory
  223. //
  224. ////////////////////////////////////////////////////////////////////////////
  225. void
  226. DefinitionFactoryMgrClass::Unlink_Factory (DefinitionFactoryClass *factory)
  227. {
  228. WWASSERT(factory != 0);
  229. // Handle the factory's prev pointer:
  230. if (factory->m_PrevFactory == 0) {
  231. // this factory is the head
  232. WWASSERT (_FactoryListHead == factory);
  233. _FactoryListHead = factory->m_NextFactory;
  234. } else {
  235. // link it's prev with it's next
  236. factory->m_PrevFactory->m_NextFactory = factory->m_NextFactory;
  237. }
  238. // Handle the factory's next pointer if its not at the end of the list:
  239. if (factory->m_NextFactory != 0) {
  240. factory->m_NextFactory->m_PrevFactory = factory->m_PrevFactory;
  241. }
  242. // factory is now un-linked
  243. factory->m_NextFactory = 0;
  244. factory->m_PrevFactory = 0;
  245. return ;
  246. }