1 /* 2 * Element.h 3 * 4 * Copyright (C) 1999 Stephen F. White 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or 9 * (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program (see the file "COPYING" for details); if 18 * not, write to the Free Software Foundation, Inc., 675 Mass Ave, 19 * Cambridge, MA 02139, USA. 20 */ 21 22 #pragma once 23 24 # include "MyString.h" 25 #include "Array.h" 26 #include "x3dFlags.h" 27 28 class Node; 29 class Proto; 30 31 enum { 32 EL_UNKNOWN, 33 34 EL_EVENT_IN, 35 EL_EVENT_OUT, 36 EL_FIELD, 37 EL_EXPOSED_FIELD, 38 39 EL_INITIALIZE, 40 EL_EVENTS_PROCESSED, 41 EL_SHUTDOWN 42 }; 43 44 enum { 45 FF_HIDDEN = 1<<0, 46 FF_FIXEDSTRINGS = 1<<1, 47 FF_URL = 1<<2, 48 FF_WONDERLAND_ART = 1<<3, 49 FF_DOUBLE = 1<<4, 50 FF_3_DOUBLE = 1<<5, 51 FF_DELETED = 1<<6, 52 FF_STATIC = 1<<7, 53 FF_DEPRECATED = 1<<8, 54 FF_IN_SCRIPT = 1<<9, 55 FF_SCRIPT_URL = 1<<10, 56 FF_COVER_ONLY = 1<<11, 57 FF_X3D_ONLY = 1<<12, 58 FF_VRML_ONLY = 1<<13, 59 FF_ALWAYS = 1<<14, 60 FF_NEVER = 1<<15, 61 FF_KAMBI_ONLY = 1<<16, 62 FF_KAMBI_DEPRECATED = 1<<17, 63 FF_4KIDS = 1<<18, 64 FF_X3DOM_ONLY = 1<<19, 65 FF_ROOT_ONLY = 1<<20, 66 FF_UPDATE = 1<<21, 67 FF_IS_NAME = 1<<22, 68 FF_IS = 1<<23, 69 EIF_IS = 1<<24, 70 EOF_IS = 1<<25, 71 EIF_RECOMMENDED = 1<<26, 72 EOF_RECOMMENDED = 1<<27, 73 EIF_IS_HIDDEN = 1<<28, 74 EOF_IS_HIDDEN = 1<<29, 75 EIF_WONDERLAND_SUPPORTED = 1<<30, 76 EOF_WONDERLAND_SUPPORTED = 1<<31 77 }; 78 79 class IsElement { 80 public: IsElement()81 IsElement() 82 { 83 m_nodeIndex = -1; 84 m_node = NULL; 85 m_field = -1; 86 m_elementType = EL_UNKNOWN; 87 m_originalProto = NULL; 88 m_originalField = -1; 89 m_id = 0; 90 } 91 IsElement(Node *node, int field, int elementType, 92 Proto *origProto, int origField); getNode(void)93 Node* getNode(void) { return m_node; } 94 int getField(void); getElementType(void)95 int getElementType(void) { return m_elementType; } getNodeIndex(void)96 int getNodeIndex(void) { return m_nodeIndex; } setNodeIndex(int nodeIndex)97 void setNodeIndex(int nodeIndex) { m_nodeIndex = nodeIndex; } 98 protected: 99 int m_nodeIndex; 100 Node *m_node; 101 int m_field; 102 Proto *m_originalProto; 103 int m_originalField; 104 int m_elementType; 105 long m_id; 106 }; 107 108 class Element { 109 public: Element()110 Element() {m_x3dName = "";m_validNumIs = 0;} 111 Element(const Element *ptr); ~Element()112 virtual ~Element() {} 113 virtual int getElementType() const = 0; 114 virtual const char *getElementName(bool x3d) const = 0; 115 const MyString &getName(bool x3d) const; 116 int getType() const; getFlags()117 int getFlags() const { return m_flags; } setFlags(int flags)118 void setFlags(int flags) { m_flags = flags; } addFlags(int flags)119 void addFlags(int flags) { m_flags |= flags; } removeFlags(int flags)120 void removeFlags(int flags) 121 { m_flags = m_flags & !(flags & 0xffff); } 122 123 virtual int write(int filedes, int indent, int flag = 0) 124 const = 0; 125 virtual int writeElementPart(int filedes, int indent, int flag) 126 const; 127 128 void addIs(Node *node, int field, int elementType, 129 Proto *origProto, int origField, int flags = 0); getNumIs(void)130 long getNumIs(void) const { return m_validNumIs; } getIsNode(int i)131 Node *getIsNode(int i) 132 { 133 if (m_isArray[i]) 134 return m_isArray[i]->getNode(); 135 return NULL; 136 } getIsField(int i)137 int getIsField(int i) 138 { 139 if (i > m_validNumIs - 1) 140 return -1; 141 int ret = -1; 142 if (m_isArray[i] != NULL) 143 ret = m_isArray[i]->getField(); 144 return ret; 145 } getIsElementType(int i)146 int getIsElementType(int i) 147 { return m_isArray[i]->getElementType(); } removeIs(int i)148 void removeIs(int i) { m_isArray.remove(i); } 149 getIsNodeIndex(int i)150 int getIsNodeIndex(int i) 151 { return m_isArray[i]->getNodeIndex(); } setIsNodeIndex(int i,int nodeIndex)152 void setIsNodeIndex(int i, int nodeIndex) 153 { m_isArray[i]->setNodeIndex(nodeIndex); } 154 setAppinfo(const MyString & appinfo)155 void setAppinfo(const MyString& appinfo) 156 { m_appinfo = appinfo; } getAppinfo()157 MyString getAppinfo() const 158 { return m_appinfo; } setDocumentation(const MyString & documentation)159 void setDocumentation(const MyString& documentation) 160 { m_documentation = documentation; } getDocumentation()161 MyString getDocumentation() const 162 { return m_documentation; } 163 protected: 164 int m_type; 165 MyString m_name; 166 MyString m_x3dName; 167 int m_flags; 168 MyArray<IsElement *> m_isArray; 169 long m_validNumIs; 170 171 MyString m_appinfo; 172 MyString m_documentation; 173 }; 174 175 int indentf(int filedes, int indent); 176