Open Inventor Release 2024.2.0
 
Loading...
Searching...
No Matches
SoMFEnum.h
1/*=======================================================================
2 * Copyright 1991-1996, Silicon Graphics, Inc.
3 * ALL RIGHTS RESERVED
4 *
5 * UNPUBLISHED -- Rights reserved under the copyright laws of the United
6 * States. Use of a copyright notice is precautionary only and does not
7 * imply publication or disclosure.
8 *
9 * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND:
10 * Use, duplication or disclosure by the Government is subject to restrictions
11 * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights
12 * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or
13 * in similar or successor clauses in the FAR, or the DOD or NASA FAR
14 * Supplement. Contractor/manufacturer is Silicon Graphics, Inc.,
15 * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311.
16 *
17 * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY
18 * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION,
19 * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY
20 * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON
21 * GRAPHICS, INC.
22**=======================================================================*/
23/*=======================================================================
24** Author : Paul S. Strauss (MMM yyyy)
25**=======================================================================*/
26/*=======================================================================
27 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), ***
28 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. ***
29 *** ***
30 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS ***
31 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR ***
32 *** WRITTEN AUTHORIZATION OF FEI S.A.S. ***
33 *** ***
34 *** RESTRICTED RIGHTS LEGEND ***
35 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS ***
36 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN ***
37 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT ***
38 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN ***
39 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. ***
40 *** ***
41 *** COPYRIGHT (C) 1996-2014 BY FEI S.A.S, ***
42 *** BORDEAUX, FRANCE ***
43 *** ALL RIGHTS RESERVED ***
44**=======================================================================*/
45/*=======================================================================
46** Modified by : VSG (MMM YYYY)
47**=======================================================================*/
48
49
50#ifndef _SO_MF_ENUM_
51#define _SO_MF_ENUM_
52
53#include <Inventor/SbString.h>
54#include <Inventor/errors/SoDebugError.h>
55#include <Inventor/fields/SoSubField.h>
56
58//
59// SoMFEnum subclass of SoMField. This field holds enumerated types.
60// Each instance of the field must define enumeration mnemonics and
61// character strings. This stores the enumeration values as integers
62// (as allowed by C++).
63//
65
95class SoMFEnum : public SoMField {
96
97 // Use standard field stuff
98 SO_MFIELD_HEADER(SoMFEnum, int, int);
99 SO_MFIELD_SETVALUESPOINTER_HEADER(int);
100
101 public:
102 //
103 // Some convenience functions:
104 //
105
112 void setValue(const SbName &name);
113
118 void getEnums(int &num, int *&vals, SbName *&names);
119
126 void set1Value(int index, const SbName &name);
127
128 private:
129 // Sets up value/name correspondances
130 void setEnums(int num, int *vals, SbName *names);
131
132 private:
133 static void initClass();
134 static void exitClass();
135
136 private:
137 // TRUE if setEnums called
138 bool legalValuesSet;
139
140 // Number of enumeration values
141 int numEnums;
142
143 // Enumeration values
144 int *enumValues;
145
146 // Mnemonic names of values
147 SbName *enumNames;
148
149 // Looks up enum name, returns value. Returns FALSE if not found.
150 virtual SbBool findEnumValue(const SbName &name, int &val);
151
152 // Looks up enum value, returns ptr to name. Returns FALSE if not found.
153 virtual SbBool findEnumName(int val, const SbName *&name) const;
154
155};
156
157
159//
160// Debugging macros (used by other macros in this file)
161// The container must have a field 'firstInstance'.
162//
163#if defined(_DEBUG)
164# define SO__MF_ENUM_CHECK_DATA(vals, typeName, fieldName, containerMacroName) { \
165 if (vals == NULL && firstInstance) { \
166 SoDebugError::post("SO_SET_MF_ENUM_TYPE", \
167 "Field %s (%s, line %d): Did you forget to" \
168 " use SO_%s_DEFINE_ENUM_VALUE(%s, ...)?", \
169 fieldName, __FILE__, __LINE__, \
170 containerMacroName, typeName); \
171 } \
172}
173#else
174# define SO__MF_ENUM_CHECK_DATA(vals, typeName, fieldName, containerMacroName) ;
175#endif
176
177
179//
180// This defines the specific type of enum expected by a particular
181// SoMFEnum field.
182//
183
184#define SO__MF_ENUM_SET_TYPE(fieldName, enumType, contMacroName, contData) { \
185 int _so_mf_enum_num; \
186 int *_so_mf_enum_vals; \
187 SbName *_so_mf_enum_names; \
188 contData->getEnumData((char *)SO__QUOTE(enumType), \
189 _so_mf_enum_num, \
190 _so_mf_enum_vals, \
191 _so_mf_enum_names); \
192 SO__MF_ENUM_CHECK_DATA(_so_mf_enum_vals, \
193 SO__QUOTE(enumType), \
194 SO__QUOTE(fieldName), \
195 contMacroName); \
196 fieldName.setEnums(_so_mf_enum_num, \
197 _so_mf_enum_vals, \
198 _so_mf_enum_names); \
199}
200
201#define SO_NODE_SET_MF_ENUM_TYPE(fieldName, enumType) \
202 SO__MF_ENUM_SET_TYPE(fieldName,enumType,"NODE",fieldData)
203
204#define SO_ENGINE_SET_MF_ENUM_TYPE(fieldName, enumType) \
205 SO__MF_ENUM_SET_TYPE(fieldName,enumType,"ENGINE",inputData)
206
207//
208// End of macros
209//
211
212#endif /* _SO_MF_ENUM_ */
213
Character string stored in a hash table.
Definition SbName.h:162
Multiple-value field containing any number of enumerated type values.
Definition SoMFEnum.h:95
void setValue(const SbName &name)
Sets this field to contain one and only one value, which is the mnemonic name as a string.
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.
void getEnums(int &num, int *&vals, SbName *&names)
Gets value/name correspondances.
Base class for all multiple-valued fields.
Definition SoMField.h:134
int SbBool
Boolean type.
Definition SbBase.h:87