Open Inventor Reference
MeVis/ThirdParty/Sources/Inventor/inventor/lib/database/include/Inventor/fields/SoMFEnum.h
Go to the documentation of this file.
00001 /*
00002  *
00003  *  Copyright (C) 2000 Silicon Graphics, Inc.  All Rights Reserved. 
00004  *
00005  *  This library is free software; you can redistribute it and/or
00006  *  modify it under the terms of the GNU Lesser General Public
00007  *  License as published by the Free Software Foundation; either
00008  *  version 2.1 of the License, or (at your option) any later version.
00009  *
00010  *  This library is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  *  Lesser General Public License for more details.
00014  *
00015  *  Further, this software is distributed without any warranty that it is
00016  *  free of the rightful claim of any third person regarding infringement
00017  *  or the like.  Any license provided herein, whether implied or
00018  *  otherwise, applies only to this software file.  Patent licenses, if
00019  *  any, provided herein do not apply to combinations of this program with
00020  *  other software, or any other product whatsoever.
00021  * 
00022  *  You should have received a copy of the GNU Lesser General Public
00023  *  License along with this library; if not, write to the Free Software
00024  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025  *
00026  *  Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
00027  *  Mountain View, CA  94043, or:
00028  * 
00029  *  http://www.sgi.com 
00030  * 
00031  *  For further information regarding this notice, see: 
00032  * 
00033  *  http://oss.sgi.com/projects/GenInfo/NoticeExplan/
00034  *
00035  */
00036 
00037 
00038 /*
00039  * Copyright (C) 1990,91   Silicon Graphics, Inc.
00040  *
00041  _______________________________________________________________________
00042  ______________  S I L I C O N   G R A P H I C S   I N C .  ____________
00043  |
00044  |   $Revision: 1.1.1.1 $
00045  |
00046  |   Classes:
00047  |      SoMFEnum
00048  |
00049  |   Macros:
00050  |
00051  |      SO_NODE_SET_MF_ENUM_TYPE(fieldName, enumType)
00052  |      SO_ENGINE_SET_MF_ENUM_TYPE(fieldName, enumType)
00053  |              These assign a specific type of enum to an MFEnum field.
00054  |
00055  |   Author(s)          : Paul S. Strauss
00056  |
00057  ______________  S I L I C O N   G R A P H I C S   I N C .  ____________
00058  _______________________________________________________________________
00059  */
00060 
00061 #ifndef  _SO_MF_ENUM_
00062 #define  _SO_MF_ENUM_
00063 
00064 #include <Inventor/SbString.h>
00065 #include <Inventor/errors/SoDebugError.h>
00066 #include <Inventor/fields/SoSubField.h>
00067 
00068 
00071 
00091 
00092 
00093 class INVENTOR_API SoMFEnum : public SoMField {
00094 
00096     SO_MFIELD_HEADER(SoMFEnum, int, int);
00097 
00098   public:
00099 
00102     void                setValue(const SbName &name);
00103 
00106     void                set1Value(int index, const SbName &name);
00107 
00108   SoEXTENDER public:
00110     void                setEnums(int num, int *vals, SbName *names);
00111 
00112   SoINTERNAL public:
00113     static void         initClass();
00114 
00115   protected:
00116     SbBool              legalValuesSet; 
00117     int                 numEnums;       
00118     int                 *enumValues;    
00119     SbName              *enumNames;     
00120 
00122     virtual SbBool      findEnumValue(const SbName &name, int &val);
00123 
00125     virtual SbBool      findEnumName(int val, const SbName *&name) const;
00126 };
00127 
00128 
00134 #ifdef DEBUG
00135 #define SO__MF_ENUM_CHECK_DATA(vals, typeName, fieldName, containerMacroName) {  \
00136     int _value_false= 0;                                                      \
00137     do {                                                                      \
00138         if (vals == NULL && firstInstance)                                    \
00139             SoDebugError::post("SO_SET_MF_ENUM_TYPE",                         \
00140                                "Field %s (%s, line %d): Did you forget to"    \
00141                                " use SO_%s_DEFINE_ENUM_VALUE(%s, ...)?",      \
00142                                fieldName, __FILE__, __LINE__,                 \
00143                                containerMacroName, typeName);                 \
00144     } while (_value_false);                                                   \
00145     }
00146 #else
00147 #define SO__MF_ENUM_CHECK_DATA(vals, typeName, fieldName, containerMacroName)   { int _value_false= 0; while(_value_false) {} }
00148 #endif
00149         
00150 
00156 
00157 #define SO__MF_ENUM_SET_TYPE(fieldName, enumType, contMacroName, contData) {  \
00158     int _value_false= 0;                                                      \
00159     do {                                                                      \
00160         int _so_mf_enum_num;                                                  \
00161         int *_so_mf_enum_vals;                                                \
00162         SbName *_so_mf_enum_names;                                            \
00163         contData->getEnumData(SO__QUOTE(enumType),                            \
00164                                 _so_mf_enum_num,                              \
00165                                 _so_mf_enum_vals,                             \
00166                                 _so_mf_enum_names);                           \
00167         SO__MF_ENUM_CHECK_DATA(_so_mf_enum_vals,                              \
00168                                SO__QUOTE(enumType),                           \
00169                                SO__QUOTE(fieldName),                          \
00170                                contMacroName);                                \
00171         fieldName.setEnums(_so_mf_enum_num,                                   \
00172                            _so_mf_enum_vals,                                  \
00173                            _so_mf_enum_names);                                \
00174     } while (_value_false);                                                   \
00175     }
00176 
00177 #define SO_NODE_SET_MF_ENUM_TYPE(fieldName, enumType)                         \
00178     SO__MF_ENUM_SET_TYPE(fieldName,enumType,"NODE",fieldData)
00179 
00180 #define SO_ENGINE_SET_MF_ENUM_TYPE(fieldName, enumType)                       \
00181     SO__MF_ENUM_SET_TYPE(fieldName,enumType,"ENGINE",inputData)
00182 
00187 
00188 
00189 #endif /* _SO_MF_ENUM_ */