Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
definitionfactorymgr.cpp
Go to the documentation of this file.
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 *** 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 ***
21 ***********************************************************************************************
22 * *
23 * Project Name : WWSaveLoad *
24 * *
25 * $Archive:: /VSS_Sync/wwsaveload/definitionfactorymgr.cpp $*
26 * *
27 * Author:: Patrick Smith *
28 * *
29 * $Modtime:: 10/16/00 11:42a $*
30 * *
31 * $Revision:: 12 $*
32 * *
33 *---------------------------------------------------------------------------------------------*
34 * Functions: *
35 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
36
38#include "definitionfactory.h"
39#include "wwdebug.h"
40#include <string.h>
41#ifdef _UNIX
42#include "osdep.h"
43#endif
44
46// Static member initialization
48DefinitionFactoryClass *DefinitionFactoryMgrClass::_FactoryListHead = 0;
49
50
52//
53// Find_Factory
54//
58{
59 DefinitionFactoryClass *factory = 0;
60
61 //
62 // Loop through all the factories and see if we can
63 // find the one who owns the corresponding class-id.
64 //
65 for ( DefinitionFactoryClass *curr_factory = _FactoryListHead;
66 (factory == 0) && (curr_factory != 0);
67 curr_factory = curr_factory->m_NextFactory) {
68
69 //
70 // Is this the factory we were looking for?
71 //
72 if (curr_factory->Get_Class_ID () == class_id) {
73 factory = curr_factory;
74 }
75 }
76
77 return factory;
78}
79
80
82//
83// Find_Factory
84//
88{
89 DefinitionFactoryClass *factory = 0;
90
91 //
92 // Loop through all the factories and see if we can
93 // find the one who owns the corresponding class-id.
94 //
95 for ( DefinitionFactoryClass *curr_factory = _FactoryListHead;
96 (factory == 0) && (curr_factory != 0);
97 curr_factory = curr_factory->m_NextFactory) {
98
99 //
100 // Is this the factory we were looking for?
101 //
102 if (::stricmp (curr_factory->Get_Name (), name) == 0) {
103 factory = curr_factory;
104 }
105 }
106
107 return factory;
108}
109
110
112//
113// Get_First
114//
118{
119 DefinitionFactoryClass *factory = 0;
120
121 //
122 // Loop through all the factories and see if we can
123 // find the next one that belongs to the given superclass
124 //
125 for ( DefinitionFactoryClass *curr_factory = _FactoryListHead;
126 (factory == 0) && (curr_factory != 0);
127 curr_factory = curr_factory->m_NextFactory) {
128
129 //
130 // Is this the factory we were looking for?
131 //
132 if (::SuperClassID_From_ClassID (curr_factory->Get_Class_ID ()) == superclass_id) {
133 factory = curr_factory;
134 }
135 }
136
137 return factory;
138}
139
140
142//
143// Get_Next
144//
148(
149 DefinitionFactoryClass *curr_factory,
150 uint32 superclass_id
151)
152{
153 DefinitionFactoryClass *factory = 0;
154
155 //
156 // Loop through all the factories and see if we can
157 // find the next one that belongs to the given superclass
158 //
159 while ((factory == NULL) && ((curr_factory = curr_factory->m_NextFactory) != NULL)) {
160
161 //
162 // Is this the factory we were looking for?
163 //
164 if (::SuperClassID_From_ClassID (curr_factory->Get_Class_ID ()) == superclass_id) {
165 factory = curr_factory;
166 }
167 }
168
169 return factory;
170}
171
172
174//
175// Get_First
176//
180{
181 return _FactoryListHead;
182}
183
184
186//
187// Get_Next
188//
192{
193 DefinitionFactoryClass *factory = 0;
194
195 //
196 // Simply return the next factory in the chain
197 //
198 if (curr_factory != NULL) {
199 factory = curr_factory->m_NextFactory;
200 }
201
202 return factory;
203}
204
205
207//
208// Register_Factory
209//
211void
213{
214 WWASSERT (factory->m_NextFactory == 0);
215 WWASSERT (factory->m_PrevFactory == 0);
216 Link_Factory (factory);
217 return ;
218}
219
220
222//
223// Unregister_Factory
224//
226void
228{
229 WWASSERT (factory != 0);
230 Unlink_Factory (factory);
231 return ;
232}
233
234
236//
237// Link_Factory
238//
240void
241DefinitionFactoryMgrClass::Link_Factory (DefinitionFactoryClass *factory)
242{
243 WWASSERT (factory->m_NextFactory == 0);
244 WWASSERT (factory->m_PrevFactory == 0);
245
246 // Adding this factory in front of the current head of the list
247 factory->m_NextFactory = _FactoryListHead;
248
249 // If the list wasn't empty, link the next factory back to this factory
250 if (factory->m_NextFactory != 0) {
251 factory->m_NextFactory->m_PrevFactory = factory;
252 }
253
254 // Point the head of the list at this factory now
255 _FactoryListHead = factory;
256 return ;
257}
258
259
261//
262// Unlink_Factory
263//
265void
266DefinitionFactoryMgrClass::Unlink_Factory (DefinitionFactoryClass *factory)
267{
268 WWASSERT(factory != 0);
269
270 // Handle the factory's prev pointer:
271 if (factory->m_PrevFactory == 0) {
272
273 // this factory is the head
274 WWASSERT (_FactoryListHead == factory);
275 _FactoryListHead = factory->m_NextFactory;
276
277 } else {
278
279 // link it's prev with it's next
280 factory->m_PrevFactory->m_NextFactory = factory->m_NextFactory;
281
282 }
283
284 // Handle the factory's next pointer if its not at the end of the list:
285 if (factory->m_NextFactory != 0) {
286
287 factory->m_NextFactory->m_PrevFactory = factory->m_PrevFactory;
288
289 }
290
291 // factory is now un-linked
292 factory->m_NextFactory = 0;
293 factory->m_PrevFactory = 0;
294 return ;
295}
#define NULL
Definition BaseType.h:92
#define WWASSERT
unsigned long uint32
Definition bittype.h:46
DefinitionFactoryClass * m_NextFactory
DefinitionFactoryClass * m_PrevFactory
virtual uint32 Get_Class_ID(void) const =0
static void Register_Factory(DefinitionFactoryClass *factory)
static DefinitionFactoryClass * Get_Next(DefinitionFactoryClass *current, uint32 superclass_id)
static void Unregister_Factory(DefinitionFactoryClass *factory)
static DefinitionFactoryClass * Get_First(void)
static DefinitionFactoryClass * Find_Factory(uint32 class_id)
uint32 SuperClassID_From_ClassID(uint32 class_id)
else return(RetVal)