Debian Codegraph @

lib/database/src/so/fields/SoSFPath.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 | SoSFPath
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/SoPath.h>cxx . . $ `<file>/lib/database/include/Inventor/SoPath.h`/
56 #include <Inventor/actions/SoWriteAction.h>cxx . . $ `<file>/lib/database/include/Inventor/actions/SoWriteAction.h`/
57 #include <Inventor/fields/SoSFPath.h>cxx . . $ `<file>/lib/database/include/Inventor/fields/SoSFPath.h`/
58
59 //////////////////////////////////////////////////////////////////////////////
60 //
61 // SoSFPath class - contains a pointer to an SoPath. This has to
62 // implement some extra path 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_SFIELD_REQUIRED_SOURCEcxx . . $ `lib/database/include/Inventor/fields/SoSubField.h:459:9`!(SoSFPath);
70
71
72 ////////////////////////////////////////////////////////////////////////
73 //
74 // Description:
75 // Constructor
76 //
77 // Use: public
78
79 SoSFPathcxx . . $ SoSFPath#::SoSFPathcxx . . $ SoSFPath#SoSFPath(49f6e7a06ebc5aa8).()
80 //
81 ////////////////////////////////////////////////////////////////////////
82 {
83 // This will prevent treating random memory as an SoPath
84 valuecxx . . $ SoSFPath#value. = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!;
85 headcxx . . $ SoSFPath#head. = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!;
86 }
87
88 ////////////////////////////////////////////////////////////////////////
89 //
90 // Description:
91 // Destructor
92 //
93 // Use: public
94
95 SoSFPathcxx . . $ SoSFPath#::~cxx . . $ SoSFPath#`~SoSFPath`(49f6e7a06ebc5aa8).SoSFPathcxx . . $ SoSFPath#()
96 //
97 ////////////////////////////////////////////////////////////////////////
98 {
99 if (valuecxx . . $ SoSFPath#value. != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!) {
100 if (valuecxx . . $ SoSFPath#value.->getHeadcxx . . $ SoPath#getHead(b794963b450d51b3).() != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!)
101 valuecxx . . $ SoSFPath#value.->getHeadcxx . . $ SoPath#getHead(b794963b450d51b3).()->removeAuditorcxx . . $ SoBase#removeAuditor(83574029f67dcc4a).(this, SoNotReccxx . . $ SoNotRec#::FIELDcxx . . $ SoNotRec#FIELD.);
102 valuecxx . . $ SoSFPath#value.->removeAuditorcxx . . $ SoBase#removeAuditor(83574029f67dcc4a).(this, SoNotReccxx . . $ SoNotRec#::FIELDcxx . . $ SoNotRec#FIELD.);
103 valuecxx . . $ SoSFPath#value.->unrefcxx . . $ SoBase#unref(83f5f38750778ac8).();
104 }
105 }
106
107 ////////////////////////////////////////////////////////////////////////
108 //
109 // Description:
110 // Sets value to given path pointer.
111 //
112 // Use: public
113
114 void
115 SoSFPathcxx . . $ SoSFPath#::setValuecxx . . $ SoSFPath#setValue(eed4dbbaf0eca0f1).(SoPathcxx . . $ SoPath# *newValue)
116 //
117 ////////////////////////////////////////////////////////////////////////
118 {
119 setValcxx . . $ SoSFPath#setVal(eed4dbbaf0eca0f1).(newValue);
120 valueChangedcxx . . $ SoField#valueChanged(d4f767463ce0a6b3).();
121 }
122
123 ////////////////////////////////////////////////////////////////////////
124 //
125 // Description:
126 // Equality test. (Standard definition.)
127 //
128 // Use: public
129
130 int
131 SoSFPathcxx . . $ SoSFPath#::operatorcxx . . $ SoSFPath#`operator==`(c4973528dd7d7761). ==(const SoSFPathcxx . . $ SoSFPath# &f) const
132 //
133 ////////////////////////////////////////////////////////////////////////
134 {
135 return getValuecxx . . $ SoSFPath#getValue(58db5280b30558ed).() == f.getValuecxx . . $ SoSFPath#getValue(58db5280b30558ed).();
136 }
137
138 ////////////////////////////////////////////////////////////////////////
139 //
140 // Description:
141 // Propagates notification through the field. We have to override
142 // this to track changes to the path we are watching. For example,
143 // if the path is truncated or the head node changes, we need to
144 // reset our head node auditor.
145 //
146 // NOTE: This code is essentially the same as the code in
147 // SoPathSensor::notify().
148 //
149 // Use: internal
150
151 void
152 SoSFPathcxx . . $ SoSFPath#::notifycxx . . $ SoSFPath#notify(f43de791d8d2eb5a).(SoNotListcxx . . $ SoNotList# *list)
153 //
154 ////////////////////////////////////////////////////////////////////////
155 {
156 // If there is nothing on the list, which would be the case if the
157 // field has been read from file, do the notify thing.
158 if (list->getFirstReccxx . . $ SoNotList#getFirstRec(a39986cdb7d7aef6).() == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!) {
159 SoSFieldcxx . . $ SoSField#::notifycxx . . $ SoField#notify(f43de791d8d2eb5a).(list);
160 return;
161 }
162
163 SbBoolcxx . . $ SbBool# doNotify;
164
165 // If the path started notification:
166 if (list->getFirstReccxx . . $ SoNotList#getFirstRec(a39986cdb7d7aef6).()->getBasecxx . . $ SoNotRec#getBase(82e87c88e730ed63).() == valuecxx . . $ SoSFPath#value.)
167 doNotify = TRUEcxx . . $ `lib/database/include/Inventor/SbBasic.h:80:12`!;
168
169 // If the notification came through the head node
170 else
171 doNotify = valuecxx . . $ SoSFPath#value.->isRelevantNotificationcxx . . $ SoPath#isRelevantNotification(50809eaab14a85d7).(list);
172
173 // If the head node of the path changed, detach from old head and
174 // attach to new:
175 if (valuecxx . . $ SoSFPath#value.->getHeadcxx . . $ SoPath#getHead(b794963b450d51b3).() != headcxx . . $ SoSFPath#head.) {
176 // Detach from old:
177 if (headcxx . . $ SoSFPath#head. != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!)
178 headcxx . . $ SoSFPath#head.->removeAuditorcxx . . $ SoBase#removeAuditor(83574029f67dcc4a).(this, SoNotReccxx . . $ SoNotRec#::FIELDcxx . . $ SoNotRec#FIELD.);
179 headcxx . . $ SoSFPath#head. = valuecxx . . $ SoSFPath#value.->getHeadcxx . . $ SoPath#getHead(b794963b450d51b3).();
180 // Attach to new:
181 if (headcxx . . $ SoSFPath#head. != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!)
182 headcxx . . $ SoSFPath#head.->addAuditorcxx . . $ SoBase#addAuditor(83574029f67dcc4a).(this, SoNotReccxx . . $ SoNotRec#::FIELDcxx . . $ SoNotRec#FIELD.);
183 }
184
185 // Notify if we're supposed to...
186 if (doNotify)
187 SoSFieldcxx . . $ SoSField#::notifycxx . . $ SoField#notify(f43de791d8d2eb5a).(list);
188 }
189
190 ////////////////////////////////////////////////////////////////////////
191 //
192 // Description:
193 // Reads value from file. Returns FALSE on error.
194 //
195 // Use: private
196
197 SbBoolcxx . . $ SbBool#
198 SoSFPathcxx . . $ SoSFPath#::readValuecxx . . $ SoSFPath#readValue(cfb31f743f00c8ca).(SoInputcxx . . $ SoInput# *in)
199 //
200 ////////////////////////////////////////////////////////////////////////
201 {
202 SbNamecxx . . $ SbName# namecxx . . $ SbName#SbName(49f6e7a06ebc5aa8).;
203 SoBasecxx . . $ SoBase# *base;
204
205 // See if it's a null pointer
206 if (in->readcxx . . $ SoInput#read(9a8a621633966675).(name)) {
207 if (name ==cxx . . $ `operator==`(1deca42c6f82b65f). "NULL") {
208 setValcxx . . $ SoSFPath#setVal(eed4dbbaf0eca0f1).(NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!);
209 return TRUEcxx . . $ `lib/database/include/Inventor/SbBasic.h:80:12`!;
210 }
211 else
212 in->putBackcxx . . $ SoInput#putBack(85c52e162fed56f9).(name.getStringcxx . . $ SbName#getString(a9f41ea0e82d88cf).());
213 }
214
215 // Read path
216 if (! SoBasecxx . . $ SoBase#::readcxx . . $ SoBase#read(56c2a128ec952e80).(in, base, SoPathcxx . . $ SoPath#::getClassTypeIdcxx . . $ SoPath#getClassTypeId(c00c150378d2b968).())) {
217 setValcxx . . $ SoSFPath#setVal(eed4dbbaf0eca0f1).(NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!);
218 return FALSEcxx . . $ `lib/database/include/Inventor/SbBasic.h:79:12`!;
219 }
220
221 setValcxx . . $ SoSFPath#setVal(eed4dbbaf0eca0f1).((SoPathcxx . . $ SoPath# *) base);
222
223 return TRUEcxx . . $ `lib/database/include/Inventor/SbBasic.h:80:12`!;
224 }
225
226 ////////////////////////////////////////////////////////////////////////
227 //
228 // Description:
229 // Overrides SoField::countWriteRefs() to maintain write-references
230 // in path.
231 //
232 // Use: private
233
234 void
235 SoSFPathcxx . . $ SoSFPath#::countWriteRefscxx . . $ SoSFPath#countWriteRefs(58762e0f79576b7c).(SoOutputcxx . . $ SoOutput# *out) const
236 //
237 ////////////////////////////////////////////////////////////////////////
238 {
239 // Do standard counting for field
240 SoFieldcxx . . $ SoField#::countWriteRefscxx . . $ SoField#countWriteRefs(58762e0f79576b7c).(out);
241
242 // Count path
243 if (valuecxx . . $ SoSFPath#value. != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!) {
244 SoWriteActioncxx . . $ SoWriteAction# wacxx . . $ SoWriteAction#SoWriteAction(46d85c4d426f339d).(out);
245 wa.continueToApplycxx . . $ SoWriteAction#continueToApply(eed4dbbaf0eca0f1).(valuecxx . . $ SoSFPath#value.);
246 }
247 }
248
249 ////////////////////////////////////////////////////////////////////////
250 //
251 // Description:
252 // Writes value of field to file.
253 //
254 // Use: private
255
256 void
257 SoSFPathcxx . . $ SoSFPath#::writeValuecxx . . $ SoSFPath#writeValue(58762e0f79576b7c).(SoOutputcxx . . $ SoOutput# *out) const
258 //
259 ////////////////////////////////////////////////////////////////////////
260 {
261 if (valuecxx . . $ SoSFPath#value. != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!) {
262 SoWriteActioncxx . . $ SoWriteAction# wacxx . . $ SoWriteAction#SoWriteAction(46d85c4d426f339d).(out);
263 wa.continueToApplycxx . . $ SoWriteAction#continueToApply(eed4dbbaf0eca0f1).(valuecxx . . $ SoSFPath#value.);
264 }
265 else
266 out->writecxx . . $ SoOutput#write(85c52e162fed56f9).("NULL");
267 }
268
269 ////////////////////////////////////////////////////////////////////////
270 //
271 // Description:
272 // Changes value in field without doing other notification stuff.
273 // Keeps track of references and auditors.
274 //
275 // Use: private
276
277 void
278 SoSFPathcxx . . $ SoSFPath#::setValcxx . . $ SoSFPath#setVal(eed4dbbaf0eca0f1).(SoPathcxx . . $ SoPath# *newValue)
279 //
280 ////////////////////////////////////////////////////////////////////////
281 {
282 // Play it safe if we are replacing one pointer with the same pointer
283 if (newValue != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!)
284 newValue->refcxx . . $ SoBase#ref(83f5f38750778ac8).();
285
286 // Get rid of old path, if any
287 if (valuecxx . . $ SoSFPath#value. != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!) {
288
289 // Remove auditor on head node
290 if (headcxx . . $ SoSFPath#head. != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!)
291 headcxx . . $ SoSFPath#head.->removeAuditorcxx . . $ SoBase#removeAuditor(83574029f67dcc4a).(this, SoNotReccxx . . $ SoNotRec#::FIELDcxx . . $ SoNotRec#FIELD.);
292
293 // Remove auditor on path itself
294 valuecxx . . $ SoSFPath#value.->removeAuditorcxx . . $ SoBase#removeAuditor(83574029f67dcc4a).(this, SoNotReccxx . . $ SoNotRec#::FIELDcxx . . $ SoNotRec#FIELD.);
295
296 valuecxx . . $ SoSFPath#value.->unrefcxx . . $ SoBase#unref(83f5f38750778ac8).();
297 }
298
299 valuecxx . . $ SoSFPath#value. = newValue;
300
301 if (valuecxx . . $ SoSFPath#value. != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!) {
302
303 valuecxx . . $ SoSFPath#value.->refcxx . . $ SoBase#ref(83f5f38750778ac8).();
304
305 // Add auditor on path
306 valuecxx . . $ SoSFPath#value.->addAuditorcxx . . $ SoBase#addAuditor(83574029f67dcc4a).(this, SoNotReccxx . . $ SoNotRec#::FIELDcxx . . $ SoNotRec#FIELD.);
307
308 // Add auditor on head node. (For efficiency, a path does not
309 // audit its head node directly. Things that rely on this
310 // notification - e.g., this field and path sensors - have to
311 // do it themselves.)
312 headcxx . . $ SoSFPath#head. = valuecxx . . $ SoSFPath#value.->getHeadcxx . . $ SoPath#getHead(b794963b450d51b3).();
313 if (headcxx . . $ SoSFPath#head. != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!)
314 headcxx . . $ SoSFPath#head.->addAuditorcxx . . $ SoBase#addAuditor(83574029f67dcc4a).(this, SoNotReccxx . . $ SoNotRec#::FIELDcxx . . $ SoNotRec#FIELD.);
315 }
316
317 if (newValue != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!)
318 newValue->unrefcxx . . $ SoBase#unref(83f5f38750778ac8).();
319 }
320
321 ////////////////////////////////////////////////////////////////////////
322 //
323 // Description:
324 // Update a copied field to use node copies if the head node has
325 // been copied.
326 //
327 // Use: internal
328
329 void
330 SoSFPathcxx . . $ SoSFPath#::fixCopycxx . . $ SoSFPath#fixCopy(d4f767463ce0a6b3).(SbBoolcxx . . $ SbBool# copyConnections)
331 //
332 ////////////////////////////////////////////////////////////////////////
333 {
334 if (valuecxx . . $ SoSFPath#value. != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!) {
335
336 // If the head of the path has been copied, then each of the
337 // other nodes in the path must have been copied as
338 // well. Change the copied path to start at the copy and go
339 // through the copied nodes.
340
341 SoNodecxx . . $ SoNode# *headCopy = (SoNodecxx . . $ SoNode# *)
342 SoFieldContainercxx . . $ SoFieldContainer#::findCopycxx . . $ SoFieldContainer#findCopy(764c84fe9fa40e97).(valuecxx . . $ SoSFPath#value.->getHeadcxx . . $ SoPath#getHead(b794963b450d51b3).(), copyConnections);
343
344 if (headCopy != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!) {
345
346 // Create a new path through the copied nodes
347 SoPathcxx . . $ SoPath# *pathCopy = new SoPathcxx . . $ SoPath#SoPath(da6c7544ccee32bd).(headCopy);
348 pathCopy->refcxx . . $ SoBase#ref(83f5f38750778ac8).();
349 for (int i = 1; i < ((SoFullPathcxx . . $ SoFullPath# *) valuecxx . . $ SoSFPath#value.)->getLengthcxx . . $ SoFullPath#getLength(455f465bc33b4cdf).(); i++)
350 pathCopy->appendcxx . . $ SoPath#append(d4f767463ce0a6b3).(valuecxx . . $ SoSFPath#value.->getIndexcxx . . $ SoPath#getIndex(7ccb52b1bfe01045).(i));
351
352 setValcxx . . $ SoSFPath#setVal(eed4dbbaf0eca0f1).(pathCopy);
353 pathCopy->unrefcxx . . $ SoBase#unref(83f5f38750778ac8).();
354 }
355 }
356 }
357
358 ////////////////////////////////////////////////////////////////////////
359 //
360 // Description:
361 // Override this to also check the head of the stored path.
362 //
363 // Use: internal, virtual
364
365 SbBoolcxx . . $ SbBool#
366 SoSFPathcxx . . $ SoSFPath#::referencesCopycxx . . $ SoSFPath#referencesCopy(455f465bc33b4cdf).() const
367 //
368 ////////////////////////////////////////////////////////////////////////
369 {
370 // Do the normal test, and also see if the head of the stored path
371 // is a copy
372 return (SoSFieldcxx . . $ SoSField#::referencesCopycxx . . $ SoField#referencesCopy(455f465bc33b4cdf).() ||
373 (valuecxx . . $ SoSFPath#value. != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`! &&
374 SoFieldContainercxx . . $ SoFieldContainer#::checkCopycxx . . $ SoFieldContainer#checkCopy(39a6da8fb59a7efc).(valuecxx . . $ SoSFPath#value.->getHeadcxx . . $ SoPath#getHead(b794963b450d51b3).()) != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!));
375 }