Panda3D
|
00001 /************************************************** 00002 * VRML 2.0 Parser 00003 * Copyright (C) 1996 Silicon Graphics, Inc. 00004 * 00005 * Author(s) : Gavin Bell 00006 * Daniel Woods (first port) 00007 ************************************************** 00008 */ 00009 00010 #ifndef VRMLNODETYPE_H 00011 #define VRMLNODETYPE_H 00012 00013 // 00014 // The VrmlNodeType class is responsible for storing information about node 00015 // or prototype types. 00016 // 00017 00018 00019 #include "pandatoolbase.h" 00020 00021 #include "plist.h" 00022 #include "pvector.h" 00023 00024 class VrmlNode; 00025 00026 struct SFNodeRef { 00027 VrmlNode *_p; 00028 enum { T_null, T_unnamed, T_def, T_use } _type; 00029 char *_name; 00030 }; 00031 00032 union VrmlFieldValue { 00033 bool _sfbool; 00034 double _sffloat; 00035 long _sfint32; 00036 char *_sfstring; 00037 double _sfvec[4]; 00038 SFNodeRef _sfnode; 00039 pvector<VrmlFieldValue> *_mf; 00040 }; 00041 00042 typedef pvector<VrmlFieldValue> MFArray; 00043 00044 00045 ostream &output_value(ostream &out, const VrmlFieldValue &value, int type, 00046 int indent = 0); 00047 00048 00049 class VrmlNodeType { 00050 public: 00051 // Constructor. Takes name of new type (e.g. "Transform" or "Box") 00052 // Copies the string given as name. 00053 VrmlNodeType(const char *nm); 00054 00055 // Destructor exists mainly to deallocate storage for name 00056 ~VrmlNodeType(); 00057 00058 // Namespace management functions. PROTO definitions add node types 00059 // to the namespace. PROTO implementations are a separate node 00060 // namespace, and require that any nested PROTOs NOT be available 00061 // outside the PROTO implementation. 00062 // addToNameSpace will print an error to stderr if the given type 00063 // is already defined. 00064 static void addToNameSpace(VrmlNodeType *); 00065 static void pushNameSpace(); 00066 static void popNameSpace(); 00067 00068 // Find a node type, given its name. Returns NULL if type is not defined. 00069 static const VrmlNodeType *find(const char *nm); 00070 00071 // Routines for adding/getting eventIns/Outs/fields 00072 void addEventIn(const char *name, int type, 00073 const VrmlFieldValue *dflt = NULL); 00074 void addEventOut(const char *name, int type, 00075 const VrmlFieldValue *dflt = NULL); 00076 void addField(const char *name, int type, 00077 const VrmlFieldValue *dflt = NULL); 00078 void addExposedField(const char *name, int type, 00079 const VrmlFieldValue *dflt = NULL); 00080 00081 typedef struct { 00082 char *name; 00083 int type; 00084 VrmlFieldValue dflt; 00085 } NameTypeRec; 00086 00087 const NameTypeRec *hasEventIn(const char *name) const; 00088 const NameTypeRec *hasEventOut(const char *name) const; 00089 const NameTypeRec *hasField(const char *name) const; 00090 const NameTypeRec *hasExposedField(const char *name) const; 00091 00092 const char *getName() const { return name; } 00093 00094 private: 00095 void add(plist<NameTypeRec*> &,const char *,int, const VrmlFieldValue *dflt); 00096 const NameTypeRec *has(const plist<NameTypeRec*> &,const char *) const; 00097 00098 char *name; 00099 00100 // Node types are stored in this data structure: 00101 static plist<VrmlNodeType*> typeList; 00102 00103 plist<NameTypeRec*> eventIns; 00104 plist<NameTypeRec*> eventOuts; 00105 plist<NameTypeRec*> fields; 00106 }; 00107 00108 #endif