Debian Codegraph @

lib/database/src/so/fields/SoSFEnum.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 | SoSFEnum
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
55 #include <Inventor/errors/SoDebugError.h>cxx . . $ `<file>/lib/database/include/Inventor/errors/SoDebugError.h`/
56 #include <Inventor/errors/SoReadError.h>cxx . . $ `<file>/lib/database/include/Inventor/errors/SoReadError.h`/
57 #include <Inventor/fields/SoSFEnum.h>cxx . . $ `<file>/lib/database/include/Inventor/fields/SoSFEnum.h`/
58
59 //////////////////////////////////////////////////////////////////////////////
60 //
61 // SoSFEnum class
62 //
63 //////////////////////////////////////////////////////////////////////////////
64
65 // Use standard definitions except for constructor/destructor
66 SO_SFIELD_REQUIRED_SOURCEcxx . . $ `lib/database/include/Inventor/fields/SoSubField.h:459:9`!(SoSFEnum);
67 SO_SFIELD_VALUE_SOURCEcxx . . $ `lib/database/include/Inventor/fields/SoSubField.h:493:9`!(SoSFEnum, int, int);
68
69 ////////////////////////////////////////////////////////////////////////
70 //
71 // Description:
72 // Constructor.
73 //
74 // Use: extender
75
76 SoSFEnumcxx . . $ SoSFEnum#::SoSFEnumcxx . . $ SoSFEnum#SoSFEnum(49f6e7a06ebc5aa8).()
77 //
78 ////////////////////////////////////////////////////////////////////////
79 {
80 enumValuescxx . . $ SoSFEnum#enumValues. = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!;
81 enumNamescxx . . $ SoSFEnum#enumNames. = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!;
82 numEnumscxx . . $ SoSFEnum#numEnums. = 0;
83 legalValuesSetcxx . . $ SoSFEnum#legalValuesSet. = FALSEcxx . . $ `lib/database/include/Inventor/SbBasic.h:79:12`!;
84 }
85
86 ////////////////////////////////////////////////////////////////////////
87 //
88 // Description:
89 // Destructor.
90 //
91 // Use: extender
92
93 SoSFEnumcxx . . $ SoSFEnum#::~cxx . . $ SoSFEnum#`~SoSFEnum`(49f6e7a06ebc5aa8).SoSFEnumcxx . . $ SoSFEnum#()
94 //
95 ////////////////////////////////////////////////////////////////////////
96 {
97 if (!legalValuesSetcxx . . $ SoSFEnum#legalValuesSet. && numEnumscxx . . $ SoSFEnum#numEnums. > 0) {
98 delete[] enumValuescxx . . $ SoSFEnum#enumValues.;
99 delete[] enumNamescxx . . $ SoSFEnum#enumNames.;
100 }
101 }
102
103 ////////////////////////////////////////////////////////////////////////
104 //
105 // Description:
106 // Sets value from given SbName, which must contain the name of a
107 // valid enumerator.
108 //
109 // Use: public
110
111 void
112 SoSFEnumcxx . . $ SoSFEnum#::setValuecxx . . $ SoSFEnum#setValue(78e67776a82c5be1).(const SbNamecxx . . $ SbName# &name)
113 //
114 ////////////////////////////////////////////////////////////////////////
115 {
116 int enumVal;
117
118 if (findEnumValuecxx . . $ SoSFEnum#findEnumValue(572bbdc1cc1c500f).(name, enumVal))
119 setValuecxx . . $ SoSFEnum#setValue(d4f767463ce0a6b3).(enumVal);
120
121 #ifdef DEBUG
122 else
123 SoDebugError::post("SoSFEnum::setValue",
124 "No enum for name \"%s\"", name.getString());
125 #endif /* DEBUG */
126 }
127
128 ////////////////////////////////////////////////////////////////////////
129 //
130 // Description:
131 // Called by nodes to set legal enum names and values
132 //
133 // Use: extender public
134
135 void
136 SoSFEnumcxx . . $ SoSFEnum#::setEnumscxx . . $ SoSFEnum#setEnums(c567202b6319e7ca).(int num, int *vals, SbNamecxx . . $ SbName# *names)
137
138 //
139 ////////////////////////////////////////////////////////////////////////
140 {
141 #ifdef DEBUG
142 if (legalValuesSet == TRUE) {
143 SoDebugError::post("SoSFEnum::setEnums",
144 "setEnums called twice");
145 }
146 #endif
147
148 legalValuesSetcxx . . $ SoSFEnum#legalValuesSet. = TRUEcxx . . $ `lib/database/include/Inventor/SbBasic.h:80:12`!;
149 numEnumscxx . . $ SoSFEnum#numEnums. = num;
150 enumValuescxx . . $ SoSFEnum#enumValues. = vals;
151 enumNamescxx . . $ SoSFEnum#enumNames. = names;
152 }
153
154 ////////////////////////////////////////////////////////////////////////
155 //
156 // Description:
157 // Looks up enum name, returns value. Returns FALSE if not found.
158 //
159 // Use: protected
160
161 SbBoolcxx . . $ SbBool#
162 SoSFEnumcxx . . $ SoSFEnum#::findEnumValuecxx . . $ SoSFEnum#findEnumValue(572bbdc1cc1c500f).(const SbNamecxx . . $ SbName# &name, int &val)
163 //
164 ////////////////////////////////////////////////////////////////////////
165 {
166 int i;
167
168 // Look through names table for one that matches
169 for (i = 0; i < numEnumscxx . . $ SoSFEnum#numEnums.; i++) {
170 if (name ==cxx . . $ `operator==`(edde533be586f7a2). enumNamescxx . . $ SoSFEnum#enumNames.[i]) {
171 val = enumValuescxx . . $ SoSFEnum#enumValues.[i];
172 return TRUEcxx . . $ `lib/database/include/Inventor/SbBasic.h:80:12`!;
173 }
174 }
175
176 if (!legalValuesSetcxx . . $ SoSFEnum#legalValuesSet.) {
177 // Must be part of an unknown node, add name, value:
178 int *oldValues = enumValuescxx . . $ SoSFEnum#enumValues.;
179 SbNamecxx . . $ SbName# *oldNames = enumNamescxx . . $ SoSFEnum#enumNames.;
180 enumValuescxx . . $ SoSFEnum#enumValues. = new int[numEnumscxx . . $ SoSFEnum#numEnums.+1];
181 enumNamescxx . . $ SoSFEnum#enumNames. = new SbNamecxx . . $ SbName#SbName(49f6e7a06ebc5aa8).[numEnumscxx . . $ SoSFEnum#numEnums.+1];
182 if (numEnumscxx . . $ SoSFEnum#numEnums. != 0) {
183 for (i = 0; i < numEnumscxx . . $ SoSFEnum#numEnums.; i++) {
184 enumValuescxx . . $ SoSFEnum#enumValues.[i] = oldValues[i];
185 enumNamescxx . . $ SoSFEnum#enumNames.[i] =cxx . . $ SbName#`operator=`(8da52b6fc1e0f7c6). oldNames[i];
186 }
187 delete[] oldValues;
188 delete[] oldNames;
189 }
190 val = numEnumscxx . . $ SoSFEnum#numEnums.;
191 enumValuescxx . . $ SoSFEnum#enumValues.[numEnumscxx . . $ SoSFEnum#numEnums.] = numEnumscxx . . $ SoSFEnum#numEnums.;
192 enumNamescxx . . $ SoSFEnum#enumNames.[numEnumscxx . . $ SoSFEnum#numEnums.] =cxx . . $ SbName#`operator=`(8da52b6fc1e0f7c6). name;
193 ++numEnumscxx . . $ SoSFEnum#numEnums.;
194 return TRUEcxx . . $ `lib/database/include/Inventor/SbBasic.h:80:12`!;
195 }
196
197 return FALSEcxx . . $ `lib/database/include/Inventor/SbBasic.h:79:12`!;
198 }
199
200 ////////////////////////////////////////////////////////////////////////
201 //
202 // Description:
203 // Looks up enum value, returns pointer to name. Returns FALSE if
204 // not found.
205 //
206 // Use: protected
207
208 SbBoolcxx . . $ SbBool#
209 SoSFEnumcxx . . $ SoSFEnum#::findEnumNamecxx . . $ SoSFEnum#findEnumName(cd4d8865116cd2f1).(int val, const SbNamecxx . . $ SbName# *&name) const
210 //
211 ////////////////////////////////////////////////////////////////////////
212 {
213 int i;
214
215 // Find string corresponding to given value
216 for (i = 0; i < numEnumscxx . . $ SoSFEnum#numEnums.; i++) {
217 if (val == enumValuescxx . . $ SoSFEnum#enumValues.[i]) {
218 name = &enumNamescxx . . $ SoSFEnum#enumNames.[i];
219 return TRUEcxx . . $ `lib/database/include/Inventor/SbBasic.h:80:12`!;
220 }
221 }
222
223 return FALSEcxx . . $ `lib/database/include/Inventor/SbBasic.h:79:12`!;
224 }
225
226 ////////////////////////////////////////////////////////////////////////
227 //
228 // Description:
229 // Reads value from file. Returns FALSE on error.
230 //
231 // Use: private
232
233 SbBoolcxx . . $ SbBool#
234 SoSFEnumcxx . . $ SoSFEnum#::readValuecxx . . $ SoSFEnum#readValue(cfb31f743f00c8ca).(SoInputcxx . . $ SoInput# *in)
235 //
236 ////////////////////////////////////////////////////////////////////////
237 {
238 SbNamecxx . . $ SbName# ncxx . . $ SbName#SbName(49f6e7a06ebc5aa8).;
239
240 // Read mnemonic value as a character string identifier
241 if (! in->readcxx . . $ SoInput#read(9a8a621633966675).(n, TRUEcxx . . $ `lib/database/include/Inventor/SbBasic.h:80:12`!))
242 return FALSEcxx . . $ `lib/database/include/Inventor/SbBasic.h:79:12`!;
243
244 if (findEnumValuecxx . . $ SoSFEnum#findEnumValue(572bbdc1cc1c500f).(n, valuecxx . . $ SoSFEnum#value.))
245 return TRUEcxx . . $ `lib/database/include/Inventor/SbBasic.h:80:12`!;
246
247 // Not found? Too bad
248 SoReadErrorcxx . . $ SoReadError#::postcxx . . $ SoReadError#post(a08c53ae8c2fb13c).(in, "Unknown SoSFEnum enumeration value \"%s\"",
249 n.getStringcxx . . $ SbName#getString(a9f41ea0e82d88cf).());
250 return FALSEcxx . . $ `lib/database/include/Inventor/SbBasic.h:79:12`!;
251 }
252
253 ////////////////////////////////////////////////////////////////////////
254 //
255 // Description:
256 // Writes value of field to file.
257 //
258 // Use: private
259
260 void
261 SoSFEnumcxx . . $ SoSFEnum#::writeValuecxx . . $ SoSFEnum#writeValue(58762e0f79576b7c).(SoOutputcxx . . $ SoOutput# *out) const
262 //
263 ////////////////////////////////////////////////////////////////////////
264 {
265 const SbNamecxx . . $ SbName# *n;
266
267 #ifdef DEBUG
268 if (enumValues == NULL) {
269 SoDebugError::post("SoSFEnum::writeValue",
270 "Enum values were never initialized");
271 return;
272 }
273 #endif /* DEBUG */
274
275 // Find and write string corresponding to given value
276 if (findEnumNamecxx . . $ SoSFEnum#findEnumName(cd4d8865116cd2f1).(valuecxx . . $ SoSFEnum#value., n))
277 out->writecxx . . $ SoOutput#write(85c52e162fed56f9).(n->getStringcxx . . $ SbName#getString(a9f41ea0e82d88cf).());
278
279 // Whoops! Something bad was in the field value
280 else {
281 SoDebugErrorcxx . . $ SoDebugError#::postcxx . . $ SoDebugError#post(fb6d009da02ec724).("SoSFEnum::writeValue",
282 "Illegal value (%d) in field", valuecxx . . $ SoSFEnum#value.);
283 }
284 }