Open Inventor Reference
SoSFEnum.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  | SoSFEnum
48  |
49  | Macros:
50  |
51  | SO_NODE_SET_SF_ENUM_TYPE(fieldName, enumType)
52  | SO_ENGINE_SET_SF_ENUM_TYPE(fieldName, enumType)
53  | These assign a specific type of enum to an SFEnum 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_SF_ENUM_
62 #define _SO_SF_ENUM_
63 
64 #include <Inventor/SbString.h>
67 
68 
71 
92 
93 class INVENTOR_API SoSFEnum : public SoSField {
95  SO_SFIELD_HEADER(SoSFEnum, int, int);
96 
97  public:
98 
101  void setValue(const SbName &name);
102 
103  SoEXTENDER public:
104 
106  void setEnums(int num, int *vals, SbName *names);
107 
108  SoINTERNAL public:
109  static void initClass();
110 
111  protected:
113  int numEnums;
114  int *enumValues;
116 
118  virtual bool findEnumValue(const SbName &name, int &val);
119 
121  virtual bool findEnumName(int val, const SbName *&name) const;
122 };
123 
124 
130 #ifdef DEBUG
131 #define SO__SF_ENUM_CHECK_DATA(vals, typeName, fieldName, containerMacroName) { \
132  if (vals == NULL && firstInstance) \
133  SoDebugError::post("SO_SET_SF_ENUM_TYPE", \
134  "Field %s (%s, line %d): Did you forget to" \
135  " use SO_%s_DEFINE_ENUM_VALUE(%s, ...)?", \
136  fieldName, __FILE__, __LINE__, \
137  containerMacroName, typeName); \
138  }
139 #else
140 #define SO__SF_ENUM_CHECK_DATA(vals, typeName, fieldName, containerMacroName) { int _value_false= 0; while(_value_false) {} }
141 #endif
142 
143 
149 
150 #define SO__SF_ENUM_SET_TYPE(fieldName, enumType, contMacroName, contData) { \
151  int _so_sf_enum_num; \
152  int *_so_sf_enum_vals; \
153  SbName *_so_sf_enum_names; \
154  contData->getEnumData(SO__QUOTE(enumType), \
155  _so_sf_enum_num, \
156  _so_sf_enum_vals, \
157  _so_sf_enum_names); \
158  SO__SF_ENUM_CHECK_DATA(_so_sf_enum_vals, \
159  SO__QUOTE(enumType), \
160  SO__QUOTE(fieldName), \
161  contMacroName); \
162  fieldName.setEnums(_so_sf_enum_num, \
163  _so_sf_enum_vals, \
164  _so_sf_enum_names); \
165  }
166 
167 #define SO_NODE_SET_SF_ENUM_TYPE(fieldName, enumType) \
168  SO__SF_ENUM_SET_TYPE(fieldName,enumType,"NODE",fieldData)
169 
170 #define SO_ENGINE_SET_SF_ENUM_TYPE(fieldName, enumType) \
171  SO__SF_ENUM_SET_TYPE(fieldName,enumType,"ENGINE",inputData)
172 
177 
178 
181 template<typename T>
182 class SoSFTypedEnum : public SoSFEnum {
183 public:
185  inline void setValue(T val) { SoSFEnum::setValue(val); }
187  inline T getValue() const { return static_cast<T>(SoSFEnum::getValue()); }
188 };
189 
190 #endif /* _SO_SF_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_SFIELD_HEADER(className, valueType, valueRef)
This macro is all that is needed for most single-value field classes.
Definition: SoSubField.h:287
Character string stored in a hash table.
Definition: SbString.h:264
Field containing an enumerated value.
Definition: SoSFEnum.h:93
void setEnums(int num, int *vals, SbName *names)
Sets up value/name correspondances.
int numEnums
Number of enumeration values.
Definition: SoSFEnum.h:113
void setValue(const SbName &name)
Sets this field to contain the given mnemonic name, passed in as a name or string.
bool legalValuesSet
TRUE if setEnums called.
Definition: SoSFEnum.h:112
virtual bool findEnumValue(const SbName &name, int &val)
Looks up enum name, returns value. Returns FALSE if not found.
virtual bool findEnumName(int val, const SbName *&name) const
Looks up enum value, returns ptr to name. Returns FALSE if not found.
int * enumValues
Enumeration values.
Definition: SoSFEnum.h:114
static void initClass()
SbName * enumNames
Mnemonic names of values.
Definition: SoSFEnum.h:115
End of macros.
Definition: SoSFEnum.h:182
T getValue() const
Get the enum value.
Definition: SoSFEnum.h:187
void setValue(T val)
Set the enum value.
Definition: SoSFEnum.h:185
Abstract base class for all single-value fields.
Definition: SoField.h:537