Panda3D

vrmlNodeType.h
1 /**************************************************
2 * VRML 2.0 Parser
3 * Copyright (C) 1996 Silicon Graphics, Inc.
4 *
5 * Author(s) : Gavin Bell
6 * Daniel Woods (first port)
7 **************************************************
8 */
9
10 #ifndef VRMLNODETYPE_H
11 #define VRMLNODETYPE_H
12
13 //
14 // The VrmlNodeType class is responsible for storing information about node
15 // or prototype types.
16 //
17
18
19 #include "pandatoolbase.h"
20
21 #include "plist.h"
22 #include "pvector.h"
23
24 class VrmlNode;
25
26 struct SFNodeRef {
27 VrmlNode *_p;
28 enum { T_null, T_unnamed, T_def, T_use } _type;
29 char *_name;
30 };
31
32 union VrmlFieldValue {
33 bool _sfbool;
34 double _sffloat;
35 long _sfint32;
36 char *_sfstring;
37 double _sfvec[4];
38 SFNodeRef _sfnode;
39 pvector<VrmlFieldValue> *_mf;
40 };
41
42 typedef pvector<VrmlFieldValue> MFArray;
43
44
45 std::ostream &output_value(std::ostream &out, const VrmlFieldValue &value, int type,
46 int indent = 0);
47
48
49 class VrmlNodeType {
50 public:
51 // Constructor. Takes name of new type (e.g. "Transform" or "Box")
52 // Copies the string given as name.
53 VrmlNodeType(const char *nm);
54
55 // Destructor exists mainly to deallocate storage for name
56 ~VrmlNodeType();
57
58 // Namespace management functions. PROTO definitions add node types
59 // to the namespace. PROTO implementations are a separate node
60 // namespace, and require that any nested PROTOs NOT be available
61 // outside the PROTO implementation.
62 // addToNameSpace will print an error to stderr if the given type
63 // is already defined.
64 static void addToNameSpace(VrmlNodeType *);
65 static void pushNameSpace();
66 static void popNameSpace();
67
68 // Find a node type, given its name. Returns NULL if type is not defined.
69 static const VrmlNodeType *find(const char *nm);
70
71 // Routines for adding/getting eventIns/Outs/fields
72 void addEventIn(const char *name, int type,
73 const VrmlFieldValue *dflt = nullptr);
74 void addEventOut(const char *name, int type,
75 const VrmlFieldValue *dflt = nullptr);
76 void addField(const char *name, int type,
77 const VrmlFieldValue *dflt = nullptr);
78 void addExposedField(const char *name, int type,
79 const VrmlFieldValue *dflt = nullptr);
80
81 typedef struct {
82 char *name;
83 int type;
84 VrmlFieldValue dflt;
85 } NameTypeRec;
86
87 const NameTypeRec *hasEventIn(const char *name) const;
88 const NameTypeRec *hasEventOut(const char *name) const;
89 const NameTypeRec *hasField(const char *name) const;
90 const NameTypeRec *hasExposedField(const char *name) const;
91
92 const char *getName() const { return name; }
93
94 private:
95 void add(plist<NameTypeRec*> &,const char *,int, const VrmlFieldValue *dflt);
96 const NameTypeRec *has(const plist<NameTypeRec*> &,const char *) const;
97
98 char *name;
99
100 // Node types are stored in this data structure:
101 static plist<VrmlNodeType*> typeList;
102
103 plist<NameTypeRec*> eventIns;
104 plist<NameTypeRec*> eventOuts;
105 plist<NameTypeRec*> fields;
106 };
107
108 #endif
VrmlNodeType
Definition: vrmlNodeType.h:49
VrmlNode
Definition: vrmlNode.h:23
plist
This is our own Panda specialization on the default STL list.
Definition: plist.h:35
pvector< VrmlFieldValue >
indent
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
Definition: indent.cxx:20
pandatoolbase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
plist.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pvector.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
SFNodeRef
Definition: vrmlNodeType.h:26
VrmlNodeType::NameTypeRec
Definition: vrmlNodeType.h:81
VrmlFieldValue
Definition: vrmlNodeType.h:32