Open Inventor Reference
SoMFEnum.h
Go to the documentation of this file.
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 /*
39  * Copyright (C) 1990,91 Silicon Graphics, Inc.
40  *
41  _______________________________________________________________________
42  ______________ S I L I C O N G R A P H I C S I N C . ____________
43  |
44  | $Revision: 1.1.1.1 $
45  |
46  | Classes:
47  | SoMFEnum
48  |
49  | Macros:
50  |
51  | SO_NODE_SET_MF_ENUM_TYPE(fieldName, enumType)
52  | SO_ENGINE_SET_MF_ENUM_TYPE(fieldName, enumType)
53  | These assign a specific type of enum to an MFEnum field.
54  |
55  | Author(s) : Paul S. Strauss
56  |
57  ______________ S I L I C O N G R A P H I C S I N C . ____________
58  _______________________________________________________________________
59  */
60 
61 #ifndef _SO_MF_ENUM_
62 #define _SO_MF_ENUM_
63 
64 #include <Inventor/SbString.h>
67 
68 
71 
92 
93 class INVENTOR_API SoMFEnum : public SoMField {
94 
96  SO_MFIELD_HEADER(SoMFEnum, int, int);
97 
98  public:
99 
102  void setValue(const SbName &name);
103 
106  void set1Value(int index, const SbName &name);
107 
108  SoEXTENDER public:
110  void setEnums(int num, int *vals, SbName *names);
111 
112  SoINTERNAL public:
113  static void initClass();
114 
115  protected:
117  int numEnums;
118  int *enumValues;
120 
122  virtual bool findEnumValue(const SbName &name, int &val);
123 
125  virtual bool findEnumName(int val, const SbName *&name) const;
126 };
127 
128 
134 #ifdef DEBUG
135 #define SO__MF_ENUM_CHECK_DATA(vals, typeName, fieldName, containerMacroName) { \
136  int _value_false= 0; \
137  do { \
138  if (vals == NULL && firstInstance) \
139  SoDebugError::post("SO_SET_MF_ENUM_TYPE", \
140  "Field %s (%s, line %d): Did you forget to" \
141  " use SO_%s_DEFINE_ENUM_VALUE(%s, ...)?", \
142  fieldName, __FILE__, __LINE__, \
143  containerMacroName, typeName); \
144  } while (_value_false); \
145  }
146 #else
147 #define SO__MF_ENUM_CHECK_DATA(vals, typeName, fieldName, containerMacroName) { int _value_false= 0; while(_value_false) {} }
148 #endif
149 
150 
156 
157 #define SO__MF_ENUM_SET_TYPE(fieldName, enumType, contMacroName, contData) { \
158  int _value_false= 0; \
159  do { \
160  int _so_mf_enum_num; \
161  int *_so_mf_enum_vals; \
162  SbName *_so_mf_enum_names; \
163  contData->getEnumData(SO__QUOTE(enumType), \
164  _so_mf_enum_num, \
165  _so_mf_enum_vals, \
166  _so_mf_enum_names); \
167  SO__MF_ENUM_CHECK_DATA(_so_mf_enum_vals, \
168  SO__QUOTE(enumType), \
169  SO__QUOTE(fieldName), \
170  contMacroName); \
171  fieldName.setEnums(_so_mf_enum_num, \
172  _so_mf_enum_vals, \
173  _so_mf_enum_names); \
174  } while (_value_false); \
175  }
176 
177 #define SO_NODE_SET_MF_ENUM_TYPE(fieldName, enumType) \
178  SO__MF_ENUM_SET_TYPE(fieldName,enumType,"NODE",fieldData)
179 
180 #define SO_ENGINE_SET_MF_ENUM_TYPE(fieldName, enumType) \
181  SO__MF_ENUM_SET_TYPE(fieldName,enumType,"ENGINE",inputData)
182 
187 
188 
189 #endif /* _SO_MF_ENUM_ */
#define SoEXTENDER
Provide inline template functions for abs, swap, min, max, and clamp.
Definition: SbBasic.h:154
#define SoINTERNAL
Definition: SbBasic.h:155
#define INVENTOR_API
Disable some annoying warnings on MSVC 6.
Definition: SbSystem.h:81
#define SO_MFIELD_HEADER(className, valueType, valueRef)
This macro is all that is needed for most multiple-value field classes.
Definition: SoSubField.h:416
Character string stored in a hash table.
Definition: SbString.h:264
Multiple-value field containing any number of enumerated type values.
Definition: SoMFEnum.h:93
void setEnums(int num, int *vals, SbName *names)
Sets up value/name correspondances.
SbName * enumNames
Mnemonic names of values.
Definition: SoMFEnum.h:119
void setValue(const SbName &name)
Sets this field to contain one and only one value, which is the mnemonic name as a string.
int * enumValues
Enumeration values.
Definition: SoMFEnum.h:118
void set1Value(int index, const SbName &name)
Sets the index'th value to be the integer corresponding to the mnemonic name in the given string.
static void initClass()
virtual bool findEnumValue(const SbName &name, int &val)
Looks up enum name, returns value. Returns FALSE if not found.
bool legalValuesSet
TRUE if setEnums called.
Definition: SoMFEnum.h:116
int numEnums
Number of enumeration values.
Definition: SoMFEnum.h:117
virtual bool findEnumName(int val, const SbName *&name) const
Looks up enum value, returns ptr to name. Returns FALSE if not found.
Base class for all multiple-valued fields.
Definition: SoField.h:628