Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
namedsel.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/* $Header: /Commando/Code/Tools/max2w3d/namedsel.cpp 4 10/28/97 6:08p Greg_h $ */
20/***********************************************************************************************
21 *** Confidential - Westwood Studios ***
22 ***********************************************************************************************
23 * *
24 * Project Name : Commando Tools - WWSkin *
25 * *
26 * $Archive:: /Commando/Code/Tools/max2w3d/namedsel.cpp $*
27 * *
28 * $Author:: Greg_h $*
29 * *
30 * $Modtime:: 10/26/97 1:29p $*
31 * *
32 * $Revision:: 4 $*
33 * *
34 *---------------------------------------------------------------------------------------------*
35 * Functions: *
36 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
37
38
39#include "namedsel.h"
40
41
43{
44 for (int i=0; i<Sets.Count(); i++) {
45 delete Sets[i];
46 Sets[i] = NULL;
47 delete Names[i];
48 Names[i] = NULL;
49 }
50}
51
52void NamedSelSetList::Append_Set(BitArray & nset,TSTR & setname)
53{
54 BitArray *n = new BitArray(nset);
55 Sets.Append(1,&n);
56
57 TSTR * name = new TSTR(setname);
58 Names.Append(1,&name);
59
60 assert(Names.Count() == Sets.Count());
61}
62
64{
65 delete Sets[i];
66 Sets.Delete(i,1);
67
68 delete Names[i];
69 Names.Delete(i,1);
70
71 assert(Names.Count() == Sets.Count());
72}
73
74void NamedSelSetList::Delete_Set(TSTR & setname)
75{
76 int i = Find_Set(setname);
77 if (i >= 0) Delete_Set(i);
78}
79
81{
82 while (Sets.Count() > 0) {
83 Delete_Set(0);
84 }
85}
86
88{
89 for (int i=0; i<Sets.Count(); i++) {
90 Sets[i]->SetSize(size,TRUE);
91 }
92}
93
95{
96 for (int i=0; i<Sets.Count(); i++) {
97 Delete_Set(i);
98 }
99 Sets.SetCount(0);
100 Names.SetCount(0);
101
102 for (i=0; i<from.Count(); i++) {
103 Append_Set(from[i],*(from.Names[i]));
104 }
105
106 return *this;
107}
108
109
111{
112 for (int i=0; i<Names.Count(); i++) {
113 if (setname == *Names[i]) {
114 return i;
115 }
116 }
117 return -1;
118}
119
120
121IOResult NamedSelSetList::Save(ISave *isave)
122{
123 assert(Sets.Count() == Names.Count());
124
125 for (int i=0; i<Sets.Count(); i++) {
126
127 isave->BeginChunk(NAMED_SEL_SET_CHUNK);
128
129 isave->BeginChunk(NAMED_SEL_NAME_CHUNK);
130 isave->WriteWString(*Names[i]);
131 isave->EndChunk();
132
133 isave->BeginChunk(NAMED_SEL_BITS_CHUNK);
134 Sets[i]->Save(isave);
135 isave->EndChunk();
136
137 isave->EndChunk();
138
139 }
140 return IO_OK;
141}
142
143
144IOResult NamedSelSetList::Load(ILoad *iload)
145{
146 IOResult res;
147
148 while (IO_OK==(res=iload->OpenChunk())) {
149
150 switch (iload->CurChunkID()) {
151
153 res = Load_Set(iload);
154 break;
155
156 default:
157 assert(0);
158 break;
159 }
160
161 iload->CloseChunk();
162 if (res!=IO_OK) return res;
163 }
164 return IO_OK;
165}
166
167IOResult NamedSelSetList::Load_Set(ILoad * iload)
168{
169 IOResult res;
170 BitArray set;
171 TCHAR * name;
172
173 BOOL gotset = FALSE;
174 BOOL gotname = FALSE;
175
176 res = iload->OpenChunk();
177
178 while (IO_OK==(res=iload->OpenChunk())) {
179
180 switch (iload->CurChunkID()) {
181
183 {
184 res = set.Load(iload);
185 gotset = TRUE;
186 break;
187 }
188
190 {
191 res = iload->ReadWStringChunk(&name);
192 gotname = TRUE;
193 break;
194 }
195 }
196 iload->CloseChunk();
197 if (res != IO_OK) return res;
198 }
199
200 assert(gotset && gotname);
201 Append_Set(set,TSTR(name));
202
203 return IO_OK;
204}
#define NULL
Definition BaseType.h:92
#define TRUE
Definition BaseType.h:109
#define FALSE
Definition BaseType.h:113
#define BOOL
Definition Wnd_File.h:57
void Reset(void)
Definition namedsel.cpp:80
Tab< TSTR * > Names
Definition namedsel.h:55
IOResult Load_Set(ILoad *iload)
Definition namedsel.cpp:167
IOResult Save(ISave *isave)
Definition namedsel.cpp:121
int Find_Set(TSTR &setname)
Definition namedsel.cpp:110
Tab< BitArray * > Sets
Definition namedsel.h:54
void Delete_Set(int i)
Definition namedsel.cpp:63
NamedSelSetList & operator=(NamedSelSetList &from)
Definition namedsel.cpp:94
IOResult Load(ILoad *iload)
Definition namedsel.cpp:144
void Append_Set(BitArray &nset, TSTR &setname)
Definition namedsel.cpp:52
void Set_Size(int size)
Definition namedsel.cpp:87