Debian Codegraph @

lib/database/src/so/fields/SoMFNode.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 | SoMFNode
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/nodes/SoNode.h>cxx . . $ `<file>/lib/database/include/Inventor/nodes/SoNode.h`/
56 #include <Inventor/actions/SoWriteAction.h>cxx . . $ `<file>/lib/database/include/Inventor/actions/SoWriteAction.h`/
57 #include <Inventor/fields/SoMFNode.h>cxx . . $ `<file>/lib/database/include/Inventor/fields/SoMFNode.h`/
58
59 //////////////////////////////////////////////////////////////////////////////
60 //
61 // SoMFNode class - contains pointers to SoNodes. This has to
62 // implement some extra node 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`!(SoMFNode);
70
71 ////////////////////////////////////////////////////////////////////////
72 //
73 // Description:
74 // Constructor (standard stuff)
75 //
76 // Use: public
77
78 SoMFNodecxx . . $ SoMFNode#::SoMFNodecxx . . $ SoMFNode#SoMFNode(49f6e7a06ebc5aa8).()
79 //
80 ////////////////////////////////////////////////////////////////////////
81 {
82 valuescxx . . $ SoMFNode#values. = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!;
83 }
84
85 ////////////////////////////////////////////////////////////////////////
86 //
87 // Description:
88 // Destructor
89 //
90 // Use: public
91
92 SoMFNodecxx . . $ SoMFNode#::~cxx . . $ SoMFNode#`~SoMFNode`(49f6e7a06ebc5aa8).SoMFNodecxx . . $ SoMFNode#()
93 //
94 ////////////////////////////////////////////////////////////////////////
95 {
96 deleteAllValuescxx . . $ SoMFNode#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 SoMFNodecxx . . $ SoMFNode#::findcxx . . $ SoMFNode#find(24688ec0e2695cb1).(SoNodecxx . . $ SoNode# *targetValue, SbBoolcxx . . $ SbBool# addIfNotFound)
108 {
109 int i, num = getNumcxx . . $ SoMField#getNum(455f465bc33b4cdf).();
110
111 for (i = 0; i < num; i++)
112 if (valuescxx . . $ SoMFNode#values.[i] == targetValue)
113 return i;
114
115 if (addIfNotFound)
116 set1Valuecxx . . $ SoMFNode#set1Value(e27134e6ee27ace4).(num, targetValue);
117
118 return -1;
119 }
120
121 void
122 SoMFNodecxx . . $ SoMFNode#::setValuescxx . . $ SoMFNode#setValues(ed7c1314c18dd122).(int start, int num, const SoNodecxx . . $ SoNode# **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 . . $ SoMFNode#setVal(e27134e6ee27ace4).(start + i, (SoNodecxx . . $ SoNode# *) newValues[i]);
131
132 valueChangedcxx . . $ SoField#valueChanged(d4f767463ce0a6b3).();
133 }
134
135 void
136 SoMFNodecxx . . $ SoMFNode#::set1Valuecxx . . $ SoMFNode#set1Value(e27134e6ee27ace4).(int index, SoNodecxx . . $ SoNode# *newValue)
137 {
138 if (index >= getNumcxx . . $ SoMField#getNum(455f465bc33b4cdf).())
139 makeRoomcxx . . $ SoMField#makeRoom(d4f767463ce0a6b3).(index + 1);
140 setValcxx . . $ SoMFNode#setVal(e27134e6ee27ace4).(index, newValue);
141 valueChangedcxx . . $ SoField#valueChanged(d4f767463ce0a6b3).();
142 }
143
144 void
145 SoMFNodecxx . . $ SoMFNode#::setValuecxx . . $ SoMFNode#setValue(da6c7544ccee32bd).(SoNodecxx . . $ SoNode# *newValue)
146 {
147 makeRoomcxx . . $ SoMField#makeRoom(d4f767463ce0a6b3).(1);
148 setValcxx . . $ SoMFNode#setVal(e27134e6ee27ace4).(0, newValue);
149 valueChangedcxx . . $ SoField#valueChanged(d4f767463ce0a6b3).();
150 }
151
152 int
153 SoMFNodecxx . . $ SoMFNode#::operatorcxx . . $ SoMFNode#`operator==`(a06d02bab397b91). ==(const SoMFNodecxx . . $ SoMFNode# &f) const
154 {
155 int i, num = getNumcxx . . $ SoMField#getNum(455f465bc33b4cdf).();
156 const SoNodecxx . . $ SoNode# **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 . . $ SoMFNode#getValues(78817cd67996170a).(0);
162 itsVals = f.getValuescxx . . $ SoMFNode#getValues(78817cd67996170a).(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 SoMFNodecxx . . $ SoMFNode#::deleteAllValuescxx . . $ SoMFNode#deleteAllValues(49f6e7a06ebc5aa8).()
173 {
174 allocValuescxx . . $ SoMFNode#allocValues(d4f767463ce0a6b3).(0);
175 }
176
177 void
178 SoMFNodecxx . . $ SoMFNode#::copyValuecxx . . $ SoMFNode#copyValue(3e454b8ccf442868).(int to, int from)
179 {
180 if (to != from)
181 setValcxx . . $ SoMFNode#setVal(e27134e6ee27ace4).(to, valuescxx . . $ SoMFNode#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 SoMFNodecxx . . $ SoMFNode#::allocValuescxx . . $ SoMFNode#allocValues(d4f767463ce0a6b3).(int newNum)
193 {
194 int i;
195
196 if (valuescxx . . $ SoMFNode#values. == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!) {
197 if (newNum > 0) {
198 valuescxx . . $ SoMFNode#values. = new SoNodecxx . . $ SoNode# * [newNum];
199
200 // Make sure all pointers are initialized to NULL
201 for (i = 0; i < newNum; i++)
202 valuescxx . . $ SoMFNode#values.[i] = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!;
203 }
204 }
205 else {
206 SoNodecxx . . $ SoNode# **oldValues = valuescxx . . $ SoMFNode#values.;
207
208 if (newNum > 0) {
209 valuescxx . . $ SoMFNode#values. = new SoNodecxx . . $ SoNode# * [newNum];
210 for (i = 0; i < numcxx . . $ SoMField#num. && i < newNum; i++)
211 valuescxx . . $ SoMFNode#values.[i] = oldValues[i];
212
213 // Initialize unused pointers to NULL
214 for (i = numcxx . . $ SoMField#num.; i < newNum; i++)
215 valuescxx . . $ SoMFNode#values.[i] = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!;
216 }
217 else
218 valuescxx . . $ SoMFNode#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 SoMFNodecxx . . $ SoMFNode#::read1Valuecxx . . $ SoMFNode#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 . . $ SoMFNode#setVal(e27134e6ee27ace4).(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 node
264 if (! SoBasecxx . . $ SoBase#::readcxx . . $ SoBase#read(56c2a128ec952e80).(in, base, SoNodecxx . . $ SoNode#::getClassTypeIdcxx . . $ SoNode#getClassTypeId(c00c150378d2b968).())) {
265 setValcxx . . $ SoMFNode#setVal(e27134e6ee27ace4).(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 node)
270 setValcxx . . $ SoMFNode#setVal(e27134e6ee27ace4).(index, (SoNodecxx . . $ SoNode# *) 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 nodes.
280 //
281 // Use: private
282
283 void
284 SoMFNodecxx . . $ SoMFNode#::countWriteRefscxx . . $ SoMFNode#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 nodes
292 for (int i = 0; i < numcxx . . $ SoMField#num.; i++) {
293 SoNodecxx . . $ SoNode# *node = valuescxx . . $ SoMFNode#values.[i];
294
295 if (node != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!)
296 node->writeInstancecxx . . $ SoNode#writeInstance(46d85c4d426f339d).(out);
297 }
298 }
299
300 ////////////////////////////////////////////////////////////////////////
301 //
302 // Description:
303 // Writes value of field to file.
304 //
305 // Use: private
306
307 void
308 SoMFNodecxx . . $ SoMFNode#::write1Valuecxx . . $ SoMFNode#write1Value(73cc401f7e0a390c).(SoOutputcxx . . $ SoOutput# *out, int index) const
309 //
310 ////////////////////////////////////////////////////////////////////////
311 {
312 if (valuescxx . . $ SoMFNode#values.[index] != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!)
313 valuescxx . . $ SoMFNode#values.[index]->writeInstancecxx . . $ SoNode#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 SoMFNodecxx . . $ SoMFNode#::setValcxx . . $ SoMFNode#setVal(e27134e6ee27ace4).(int index, SoNodecxx . . $ SoNode# *newValue)
328 //
329 ////////////////////////////////////////////////////////////////////////
330 {
331 SoNodecxx . . $ SoNode# *value = valuescxx . . $ SoMFNode#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 node, 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 . . $ SoMFNode#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 node if there is
358 // one.
359 //
360 // Use: internal
361
362 void
363 SoMFNodecxx . . $ SoMFNode#::fixCopycxx . . $ SoMFNode#fixCopy(d4f767463ce0a6b3).(SbBoolcxx . . $ SbBool# copyConnections)
364 //
365 ////////////////////////////////////////////////////////////////////////
366 {
367 for (int i = 0; i < numcxx . . $ SoMField#num.; i++) {
368 if (valuescxx . . $ SoMFNode#values.[i] != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!) {
369 SoNodecxx . . $ SoNode# *nodeCopy = (SoNodecxx . . $ SoNode# *)
370 SoFieldContainercxx . . $ SoFieldContainer#::findCopycxx . . $ SoFieldContainer#findCopy(764c84fe9fa40e97).(valuescxx . . $ SoMFNode#values.[i], copyConnections);
371 if (nodeCopy != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!)
372 setValcxx . . $ SoMFNode#setVal(e27134e6ee27ace4).(i, nodeCopy);
373 }
374 }
375 }
376
377 ////////////////////////////////////////////////////////////////////////
378 //
379 // Description:
380 // Override this to also check the stored nodes.
381 //
382 // Use: internal, virtual
383
384 SbBoolcxx . . $ SbBool#
385 SoMFNodecxx . . $ SoMFNode#::referencesCopycxx . . $ SoMFNode#referencesCopy(455f465bc33b4cdf).() const
386 //
387 ////////////////////////////////////////////////////////////////////////
388 {
389 // Do the normal test, and also see if the stored nodes 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 . . $ SoMFNode#values.[i] != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`! &&
395 SoFieldContainercxx . . $ SoFieldContainer#::checkCopycxx . . $ SoFieldContainer#checkCopy(39a6da8fb59a7efc).(valuescxx . . $ SoMFNode#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 }