Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

# SoSFEnum.h

    00001 #ifndef COIN_SOSFENUM_H
    00002 #define COIN_SOSFENUM_H
    00003
    00004 /**************************************************************************\
    00005  *
    00006  *  This file is part of the Coin 3D visualization library.
    00007  *  Copyright (C) 1998-2003 by Systems in Motion.  All rights reserved.
    00008  *
    00009  *  This library is free software; you can redistribute it and/or
    00010  *  modify it under the terms of the GNU General Public License
    00011  *  ("GPL") version 2 as published by the Free Software Foundation.
    00012  *  See the file LICENSE.GPL at the root directory of this source
    00013  *  distribution for additional information about the GNU GPL.
    00014  *
    00015  *  For using Coin with software that can not be combined with the GNU
    00016  *  GPL, and for taking advantage of the additional benefits of our
    00017  *  support services, please contact Systems in Motion about acquiring
    00018  *  a Coin Professional Edition License.
    00019  *
    00020  *  See <URL:http://www.coin3d.org> for  more information.
    00021  *
    00022  *  Systems in Motion, Teknobyen, Abels Gate 5, 7030 Trondheim, NORWAY.
    00023  *  <URL:http://www.sim.no>.
    00024  *
    00025 \**************************************************************************/
    00026
    00027 #include <Inventor/fields/SoSField.h>
    00028 #include <Inventor/fields/SoSubField.h>
    00029 #include <Inventor/SbString.h>
    00030
    00031 class COIN_DLL_API SoSFEnum : public SoSField {
    00032   typedef SoSField inherited;
    00033
    00034   SO_SFIELD_HEADER(SoSFEnum, int, int);
    00035
    00036 public:
    00037   static void initClass(void);
    00038
    00039   void setValue(const SbName name);
    00040   void setEnums(const int num, const int * vals, const SbName * names);
    00041
    00042   int getNumEnums(void) const;
    00043   int getEnum(const int idx, SbName & name) const;
    00044
    00045 protected:
    00046   virtual SbBool findEnumValue(const SbName & name, int & val);
    00047   virtual SbBool findEnumName(int value, const SbName * & name) const;
    00048
    00049   int numEnums;
    00050   int * enumValues;
    00051   SbName * enumNames;
    00052   SbBool legalValuesSet;
    00053 };
    00054
    00055 // These macros are called from both node and engine classes which
    00056 // uses SoSFEnum instances, so we put them here instead of in
    00057 // SoSub[Node|Engine].h.
    00058
    00059 #define PRIVATE_SOENUM_SET_TYPE(_fieldname_, _enumtype_, _fieldstorage_) \
    00060   do { \
    00061     /* Don't need to worry about name clashes, as we're inside our own scope. */ \
    00062     int num; \
    00063     const int * values; \
    00064     const SbName * names; \
    00065     _fieldstorage_->getEnumData(SO__QUOTE(_enumtype_), num, values, names); \
    00066     this->_fieldname_.setEnums(num, values, names); \
    00067   } while (FALSE)
    00068
    00069
    00070 #define SO_ENGINE_SET_SF_ENUM_TYPE(_fieldname_, _enumtype_) \
    00071   PRIVATE_SOENUM_SET_TYPE(_fieldname_, _enumtype_, inputdata)
    00072
    00073 #define SO_NODE_SET_SF_ENUM_TYPE(_fieldname_, _enumtype_) \
    00074   PRIVATE_SOENUM_SET_TYPE(_fieldname_, _enumtype_, fieldData)
    00075
    00076 #endif // !COIN_SOSFENUM_H