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