Debian Codegraph @

lib/database/src/so/fields/SoMFEngine.c++

raw symbols SCIP
1 /*
2 *
3 * Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library 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 GNU
13 * Lesser General Public License for more details.
14 *
15 * Further, this software is distributed without any warranty that it is
16 * free of the rightful claim of any third person regarding infringement
17 * or the like. Any license provided herein, whether implied or
18 * otherwise, applies only to this software file. Patent licenses, if
19 * any, provided herein do not apply to combinations of this program with
20 * other software, or any other product whatsoever.
21 *
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 *
26 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
27 * Mountain View, CA 94043, or:
28 *
29 * http://www.sgi.com
30 *
31 * For further information regarding this notice, see:
32 *
33 * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
34 *
35 */
36
37 /*
38 * Copyright (C) 1990,91 Silicon Graphics, Inc.
39 *
40 _______________________________________________________________________
41 ______________ S I L I C O N G R A P H I C S I N C . ____________
42 |
43 | $Revision: 1.1.1.1 $
44 |
45 | Classes:
46 | SoMFEngine
47 |
48 | Author(s) : Paul S. Strauss
49 |
50 ______________ S I L I C O N G R A P H I C S I N C . ____________
51 _______________________________________________________________________
52 */
53
54 #include <Inventor/SoDB.h>cxx . . $ `<file>/lib/database/include/Inventor/SoDB.h`/
55 #include <Inventor/engines/SoEngine.h>cxx . . $ `<file>/lib/database/include/Inventor/engines/SoEngine.h`/
56 #include <Inventor/actions/SoWriteAction.h>cxx . . $ `<file>/lib/database/include/Inventor/actions/SoWriteAction.h`/
57 #include <Inventor/fields/SoMFEngine.h>cxx . . $ `<file>/lib/database/include/Inventor/fields/SoMFEngine.h`/
58
59 //////////////////////////////////////////////////////////////////////////////
60 //
61 // SoMFEngine class - contains pointers to SoEngines. This has to
62 // implement some extra engine bookkeeping.
63 //
64 //////////////////////////////////////////////////////////////////////////////
65
66 // Use standard definitions of required methods, but we have to
67 // redefine the rest to keep track of references and auditors.
68
69 SO_MFIELD_REQUIRED_SOURCEcxx . . $ `lib/database/include/Inventor/fields/SoSubField.h:556:9`!(SoMFEngine);
70
71 ////////////////////////////////////////////////////////////////////////
72 //
73 // Description:
74 // Constructor (standard stuff)
75 //
76 // Use: public
77
78 SoMFEnginecxx . . $ SoMFEngine#::SoMFEnginecxx . . $ SoMFEngine#SoMFEngine(49f6e7a06ebc5aa8).()
79 //
80 ////////////////////////////////////////////////////////////////////////
81 {
82 valuescxx . . $ SoMFEngine#values. = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!;
83 }
84
85 ////////////////////////////////////////////////////////////////////////
86 //
87 // Description:
88 // Destructor
89 //
90 // Use: public
91
92 SoMFEnginecxx . . $ SoMFEngine#::~cxx . . $ SoMFEngine#`~SoMFEngine`(49f6e7a06ebc5aa8).SoMFEnginecxx . . $ SoMFEngine#()
93 //
94 ////////////////////////////////////////////////////////////////////////
95 {
96 deleteAllValuescxx . . $ SoMFEngine#deleteAllValues(49f6e7a06ebc5aa8).();
97 }
98
99 ////////////////////////////////////////////////////////////////////////
100 //
101 // These all override the definitions in SO_MFIELD_VALUE_SOURCE() to
102 // keep track of references and auditors.
103 //
104 ////////////////////////////////////////////////////////////////////////
105
106 int
107 SoMFEnginecxx . . $ SoMFEngine#::findcxx . . $ SoMFEngine#find(a48a9724fea9fe97).(SoEnginecxx . . $ SoEngine# *targetValue, SbBoolcxx . . $ SbBool# addIfNotFound)
108 {
109 int i, num = getNumcxx . . $ SoMField#getNum(455f465bc33b4cdf).();
110
111 for (i = 0; i < num; i++)
112 if (valuescxx . . $ SoMFEngine#values.[i] == targetValue)
113 return i;
114
115 if (addIfNotFound)
116 set1Valuecxx . . $ SoMFEngine#set1Value(11a4a9254cb3be6d).(num, targetValue);
117
118 return -1;
119 }
120
121 void
122 SoMFEnginecxx . . $ SoMFEngine#::setValuescxx . . $ SoMFEngine#setValues(f83be572b03aea3e).(int start, int num, const SoEnginecxx . . $ SoEngine# **newValues)
123 {
124 int newNum = start + num, i;
125
126 if (newNum > getNumcxx . . $ SoMField#getNum(455f465bc33b4cdf).())
127 makeRoomcxx . . $ SoMField#makeRoom(d4f767463ce0a6b3).(newNum);
128
129 for (i = 0; i < num; i++)
130 setValcxx . . $ SoMFEngine#setVal(11a4a9254cb3be6d).(start + i, (SoEnginecxx . . $ SoEngine# *) newValues[i]);
131
132 valueChangedcxx . . $ SoField#valueChanged(d4f767463ce0a6b3).();
133 }
134
135 void
136 SoMFEnginecxx . . $ SoMFEngine#::set1Valuecxx . . $ SoMFEngine#set1Value(11a4a9254cb3be6d).(int index, SoEnginecxx . . $ SoEngine# *newValue)
137 {
138 if (index >= getNumcxx . . $ SoMField#getNum(455f465bc33b4cdf).())
139 makeRoomcxx . . $ SoMField#makeRoom(d4f767463ce0a6b3).(index + 1);
140 setValcxx . . $ SoMFEngine#setVal(11a4a9254cb3be6d).(index, newValue);
141 valueChangedcxx . . $ SoField#valueChanged(d4f767463ce0a6b3).();
142 }
143
144 void
145 SoMFEnginecxx . . $ SoMFEngine#::setValuecxx . . $ SoMFEngine#setValue(423f8bd844534d98).(SoEnginecxx . . $ SoEngine# *newValue)
146 {
147 makeRoomcxx . . $ SoMField#makeRoom(d4f767463ce0a6b3).(1);
148 setValcxx . . $ SoMFEngine#setVal(11a4a9254cb3be6d).(0, newValue);
149 valueChangedcxx . . $ SoField#valueChanged(d4f767463ce0a6b3).();
150 }
151
152 int
153 SoMFEnginecxx . . $ SoMFEngine#::operatorcxx . . $ SoMFEngine#`operator==`(d296fec5ecde9eea). ==(const SoMFEnginecxx . . $ SoMFEngine# &f) const
154 {
155 int i, num = getNumcxx . . $ SoMField#getNum(455f465bc33b4cdf).();
156 const SoEnginecxx . . $ SoEngine# **myVals, **itsVals;
157
158 if (num != f.getNumcxx . . $ SoMField#getNum(455f465bc33b4cdf).())
159 return FALSEcxx . . $ `lib/database/include/Inventor/SbBasic.h:79:12`!;
160
161 myVals = getValuescxx . . $ SoMFEngine#getValues(456bd4e5bd91ec51).(0);
162 itsVals = f.getValuescxx . . $ SoMFEngine#getValues(456bd4e5bd91ec51).(0);
163
164 for (i = 0; i < num; i++)
165 if (! (myVals[i] == itsVals[i]))
166 return FALSEcxx . . $ `lib/database/include/Inventor/SbBasic.h:79:12`!;
167
168 return TRUEcxx . . $ `lib/database/include/Inventor/SbBasic.h:80:12`!;
169 }
170
171 void
172 SoMFEnginecxx . . $ SoMFEngine#::deleteAllValuescxx . . $ SoMFEngine#deleteAllValues(49f6e7a06ebc5aa8).()
173 {
174 allocValuescxx . . $ SoMFEngine#allocValues(d4f767463ce0a6b3).(0);
175 }
176
177 void
178 SoMFEnginecxx . . $ SoMFEngine#::copyValuecxx . . $ SoMFEngine#copyValue(3e454b8ccf442868).(int to, int from)
179 {
180 if (to != from)
181 setValcxx . . $ SoMFEngine#setVal(11a4a9254cb3be6d).(to, valuescxx . . $ SoMFEngine#values.[from]);
182 }
183
184 ////////////////////////////////////////////////////////////////////////
185 //
186 // This overrides the definition in SO_MFIELD_ALLOC_SOURCE() to
187 // keep track of references and auditors.
188 //
189 ////////////////////////////////////////////////////////////////////////
190
191 void
192 SoMFEnginecxx . . $ SoMFEngine#::allocValuescxx . . $ SoMFEngine#allocValues(d4f767463ce0a6b3).(int newNum)
193 {
194 int i;
195
196 if (valuescxx . . $ SoMFEngine#values. == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!) {
197 if (newNum > 0) {
198 valuescxx . . $ SoMFEngine#values. = new SoEnginecxx . . $ SoEngine# * [newNum];
199
200 // Make sure all pointers are initialized to NULL
201 for (i = 0; i < newNum; i++)
202 valuescxx . . $ SoMFEngine#values.[i] = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!;
203 }
204 }
205 else {
206 SoEnginecxx . . $ SoEngine# **oldValues = valuescxx . . $ SoMFEngine#values.;
207
208 if (newNum > 0) {
209 valuescxx . . $ SoMFEngine#values. = new SoEnginecxx . . $ SoEngine# * [newNum];
210 for (i = 0; i < numcxx . . $ SoMField#num. && i < newNum; i++)
211 valuescxx . . $ SoMFEngine#values.[i] = oldValues[i];
212
213 // Initialize unused pointers to NULL
214 for (i = numcxx . . $ SoMField#num.; i < newNum; i++)
215 valuescxx . . $ SoMFEngine#values.[i] = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!;
216 }
217 else
218 valuescxx . . $ SoMFEngine#values. = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!;
219
220 // Free up any old stuff
221 if (oldValues != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!) {
222
223 // Remove auditors and references on unused values
224 for (i = newNum; i < numcxx . . $ SoMField#num.; i++) {
225 if (oldValues[i] != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!) {
226 oldValues[i]->removeAuditorcxx . . $ SoBase#removeAuditor(83574029f67dcc4a).(this, SoNotReccxx . . $ SoNotRec#::FIELDcxx . . $ SoNotRec#FIELD.);
227 oldValues[i]->unrefcxx . . $ SoBase#unref(83f5f38750778ac8).();
228 }
229 }
230
231 delete [] oldValues;
232 }
233 }
234
235 numcxx . . $ SoMField#num. = maxNumcxx . . $ SoMField#maxNum. = newNum;
236 }
237
238 ////////////////////////////////////////////////////////////////////////
239 //
240 // Description:
241 // Reads one (indexed) value from file. Returns FALSE on error.
242 //
243 // Use: private
244
245 SbBoolcxx . . $ SbBool#
246 SoMFEnginecxx . . $ SoMFEngine#::read1Valuecxx . . $ SoMFEngine#read1Value(b57125c54eeea43).(SoInputcxx . . $ SoInput# *in, int index)
247 //
248 ////////////////////////////////////////////////////////////////////////
249 {
250 SbNamecxx . . $ SbName# namecxx . . $ SbName#SbName(49f6e7a06ebc5aa8).;
251 SoBasecxx . . $ SoBase# *base;
252
253 // See if it's a null pointer
254 if (in->readcxx . . $ SoInput#read(9a8a621633966675).(name)) {
255 if (name ==cxx . . $ `operator==`(1deca42c6f82b65f). "NULL") {
256 setValcxx . . $ SoMFEngine#setVal(11a4a9254cb3be6d).(index, NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!);
257 return TRUEcxx . . $ `lib/database/include/Inventor/SbBasic.h:80:12`!;
258 }
259 else
260 in->putBackcxx . . $ SoInput#putBack(85c52e162fed56f9).(name.getStringcxx . . $ SbName#getString(a9f41ea0e82d88cf).());
261 }
262
263 // Read engine
264 if (! SoBasecxx . . $ SoBase#::readcxx . . $ SoBase#read(56c2a128ec952e80).(in, base, SoEnginecxx . . $ SoEngine#::getClassTypeIdcxx . . $ SoEngine#getClassTypeId(c00c150378d2b968).())) {
265 setValcxx . . $ SoMFEngine#setVal(11a4a9254cb3be6d).(index, NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!);
266 return FALSEcxx . . $ `lib/database/include/Inventor/SbBasic.h:79:12`!;
267 }
268
269 // Set value (adds a reference to engine)
270 setValcxx . . $ SoMFEngine#setVal(11a4a9254cb3be6d).(index, (SoEnginecxx . . $ SoEngine# *) base);
271
272 return TRUEcxx . . $ `lib/database/include/Inventor/SbBasic.h:80:12`!;
273 }
274
275 ////////////////////////////////////////////////////////////////////////
276 //
277 // Description:
278 // Overrides SoField::countWriteRefs() to maintain write-references
279 // in engines.
280 //
281 // Use: private
282
283 void
284 SoMFEnginecxx . . $ SoMFEngine#::countWriteRefscxx . . $ SoMFEngine#countWriteRefs(58762e0f79576b7c).(SoOutputcxx . . $ SoOutput# *out) const
285 //
286 ////////////////////////////////////////////////////////////////////////
287 {
288 // Do standard counting for field
289 SoFieldcxx . . $ SoField#::countWriteRefscxx . . $ SoField#countWriteRefs(58762e0f79576b7c).(out);
290
291 // Count engines
292 for (int i = 0; i < numcxx . . $ SoMField#num.; i++) {
293 SoEnginecxx . . $ SoEngine# *engine = valuescxx . . $ SoMFEngine#values.[i];
294
295 if (engine != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!)
296 engine->addWriteReferencecxx . . $ SoFieldContainer#addWriteReference(ef4b98cc8eef533a).(out);
297 }
298 }
299
300 ////////////////////////////////////////////////////////////////////////
301 //
302 // Description:
303 // Writes value of field to file.
304 //
305 // Use: private
306
307 void
308 SoMFEnginecxx . . $ SoMFEngine#::write1Valuecxx . . $ SoMFEngine#write1Value(73cc401f7e0a390c).(SoOutputcxx . . $ SoOutput# *out, int index) const
309 //
310 ////////////////////////////////////////////////////////////////////////
311 {
312 if (valuescxx . . $ SoMFEngine#values.[index] != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!)
313 valuescxx . . $ SoMFEngine#values.[index]->writeInstancecxx . . $ SoEngine#writeInstance(46d85c4d426f339d).(out);
314 else
315 out->writecxx . . $ SoOutput#write(85c52e162fed56f9).("NULL");
316 }
317
318 ////////////////////////////////////////////////////////////////////////
319 //
320 // Description:
321 // Changes value in field without doing other notification stuff.
322 // Keeps track of references and auditors.
323 //
324 // Use: private
325
326 void
327 SoMFEnginecxx . . $ SoMFEngine#::setValcxx . . $ SoMFEngine#setVal(11a4a9254cb3be6d).(int index, SoEnginecxx . . $ SoEngine# *newValue)
328 //
329 ////////////////////////////////////////////////////////////////////////
330 {
331 SoEnginecxx . . $ SoEngine# *value = valuescxx . . $ SoMFEngine#values.[index];
332
333 // Play it safe if we are replacing one pointer with the same pointer
334 if (newValue != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!)
335 newValue->refcxx . . $ SoBase#ref(83f5f38750778ac8).();
336
337 // Get rid of old engine, if any
338 if (value != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!) {
339 value->removeAuditorcxx . . $ SoBase#removeAuditor(83574029f67dcc4a).(this, SoNotReccxx . . $ SoNotRec#::FIELDcxx . . $ SoNotRec#FIELD.);
340 value->unrefcxx . . $ SoBase#unref(83f5f38750778ac8).();
341 }
342
343 value = valuescxx . . $ SoMFEngine#values.[index] = newValue;
344
345 if (value != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!) {
346 value->refcxx . . $ SoBase#ref(83f5f38750778ac8).();
347 value->addAuditorcxx . . $ SoBase#addAuditor(83574029f67dcc4a).(this, SoNotReccxx . . $ SoNotRec#::FIELDcxx . . $ SoNotRec#FIELD.);
348 }
349
350 if (newValue != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!)
351 newValue->unrefcxx . . $ SoBase#unref(83f5f38750778ac8).();
352 }
353
354 ////////////////////////////////////////////////////////////////////////
355 //
356 // Description:
357 // Update a copied field to use the copy of each engine if there is
358 // one.
359 //
360 // Use: internal
361
362 void
363 SoMFEnginecxx . . $ SoMFEngine#::fixCopycxx . . $ SoMFEngine#fixCopy(d4f767463ce0a6b3).(SbBoolcxx . . $ SbBool# copyConnections)
364 //
365 ////////////////////////////////////////////////////////////////////////
366 {
367 for (int i = 0; i < numcxx . . $ SoMField#num.; i++) {
368 if (valuescxx . . $ SoMFEngine#values.[i] != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!) {
369 SoEnginecxx . . $ SoEngine# *engineCopy = (SoEnginecxx . . $ SoEngine# *)
370 SoFieldContainercxx . . $ SoFieldContainer#::findCopycxx . . $ SoFieldContainer#findCopy(764c84fe9fa40e97).(valuescxx . . $ SoMFEngine#values.[i], copyConnections);
371 if (engineCopy != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!)
372 setValcxx . . $ SoMFEngine#setVal(11a4a9254cb3be6d).(i, engineCopy);
373 }
374 }
375 }
376
377 ////////////////////////////////////////////////////////////////////////
378 //
379 // Description:
380 // Override this to also check the stored engines.
381 //
382 // Use: internal, virtual
383
384 SbBoolcxx . . $ SbBool#
385 SoMFEnginecxx . . $ SoMFEngine#::referencesCopycxx . . $ SoMFEngine#referencesCopy(455f465bc33b4cdf).() const
386 //
387 ////////////////////////////////////////////////////////////////////////
388 {
389 // Do the normal test, and also see if the stored engines are copies
390 if (SoMFieldcxx . . $ SoMField#::referencesCopycxx . . $ SoField#referencesCopy(455f465bc33b4cdf).())
391 return TRUEcxx . . $ `lib/database/include/Inventor/SbBasic.h:80:12`!;
392
393 for (int i = 0; i < numcxx . . $ SoMField#num.; i++)
394 if (valuescxx . . $ SoMFEngine#values.[i] != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`! &&
395 SoFieldContainercxx . . $ SoFieldContainer#::checkCopycxx . . $ SoFieldContainer#checkCopy(39a6da8fb59a7efc).(valuescxx . . $ SoMFEngine#values.[i]) != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!)
396 return TRUEcxx . . $ `lib/database/include/Inventor/SbBasic.h:80:12`!;
397
398 return FALSEcxx . . $ `lib/database/include/Inventor/SbBasic.h:79:12`!;
399 }