H3D API  2.4.1
VrmlDriver.h
Go to the documentation of this file.
1 // Copyright 2004-2019, SenseGraphics AB
3 //
4 // This file is part of H3D API.
5 //
6 // H3D API 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 // H3D API 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 H3D API; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 //
20 // A commercial license is also available. Please contact us at
21 // www.sensegraphics.com for more information.
22 //
23 //
26 //
28 #ifndef __VRMLDRIVER__H__
29 #define __VRMLDRIVER__H__
30 
31 #include <string>
32 #include <stdio.h>
33 #include <H3D/Group.h>
34 #include <H3D/DEFNodes.h>
35 #include <H3D/FlexLexer.h>
36 #include <H3D/ProtoDeclaration.h>
37 #include <H3D/PrototypeVector.h>
38 #include <H3D/H3DScriptNode.h>
39 
40 //namespace H3D {
41 // class Group;
42 //}
43 using namespace H3D;
44 using namespace X3D;
45 
46 // Forward declarations.
47 //union YYSTYPE {
48 // char* val;
49 //};
50 
51 #define YYSTYPE std::string
52 
53 class VrmlDriver;
54 
55 struct VRMLFlexLexer : public yyFlexLexer {
56  VRMLFlexLexer( istream* arg_yyin = 0, ostream* arg_yyout = 0 ) :
57  yyFlexLexer( arg_yyin, arg_yyout ) {};
58 
59  int yylex (YYSTYPE* yylval, yy::location* yylloc, VrmlDriver& driver);
60 };
61 
62 // Announce to Flex the prototype we want for lexing function, ...
63 # define YY_DECL \
64  int VRMLFlexLexer::yylex (YYSTYPE* yylval, yy::location* /*yylloc*/, VrmlDriver& driver)
65 // ... and declare it for the parser's sake.
66 //YY_DECL;
67 
68 // Conducting the whole scanning and parsing of Calc++.
69 class VrmlDriver {
70 public:
71  VrmlDriver ();
72  virtual ~VrmlDriver ();
73 
74  int result;
75 
76  // Handling the scanner.
77  bool trace_scanning;
78 
79  // Handling the parser.
80  int parse( istream *inp, const char *fn, DEFNodes *dn, DEFNodes
81  *exported_nodes, PrototypeVector *prototypes );
82  string file;
83  bool trace_parsing;
84 
86  void error (const yy::location& l, const std::string& m);
87 
89  void error (const std::string& m);
90 
91  void setProtoInstance ( X3DPrototypeInstance *p ) {
92  proto_instance = p;
93  }
94 
97  void setProtoField( const string &name,
98  const string& type,
99  const Field::AccessType &access_type,
100  const string & value = "" );
101 
103  bool addDynamicField( const string &name,
104  const string& type,
105  const Field::AccessType &access_type,
106  const string & value = "" );
107 
110  bool connectProtoField( const string &proto_field, const string &node_field );
111 
112  // VRML specific functions:
113 
114  Group *getRoot() { return root.get(); }
115  void setFieldValue( const char *);
116  void setNodeStatement( int );
117  string getLocationString();
118  string getOldLocationString();
119 
120  void addLine( const char* );
121 
123  inline bool insideProtoDeclaration() {
124  return !proto_declarations.empty();
125  }
126 
130  inline bool insideTopMostProtoDeclaration() {
131  return proto_declarations.size() == 1;
132  }
133 
136  inline bool insideDynamicFieldsObject() {
137  if( node_stack.empty() ) return false;
138  return dynamic_cast< H3DDynamicFieldsObject * >( node_stack.back() ) != NULL;
139  }
140 
141  H3DUniquePtr< VRMLFlexLexer > lexer;
142  AutoRef< Group > root;
143 
144  DEFNodes *DEF_map;
145  DEFNodes *DEF_export;
146 
149  AutoRefVector< H3DScriptNode > script_nodes;
150 
151  H3DUniquePtr< DEFNodes > local_DEF_map;
152 
153  vector< Node* > node_stack;
154  vector< string > field_stack;
155 
156  int vrml_line_no;
157  int old_line_no;
158  int old_char_no;
159  string vrml_line;
160  const char *file_name;
161 
163  vector< ProtoDeclaration *> proto_declarations;
164 
166  PrototypeVector *proto_vector;
167 
170  H3DUniquePtr< PrototypeVector > local_proto_vector;
171 
172  static PrototypeVector *global_proto_vector;
173 
176  string proto_body;
177 
180  X3DPrototypeInstance *proto_instance;
181 };
182 
183 #endif
184 
Contains the DEFNodes class.
Header file for Group, X3D scene-graph node.
Base class for all scripting node interfaces.
Header file for ProtoDeclaration.
Used by VRMLParser and X3D to implement a PROTO declaration.
AccessType
The different access types that a field can have.
Definition: Field.h:53
A Group node contains children nodes without introducing a new transformation.
Definition: Group.h:53
This abstract interface class is the base class for all classes that specify arbitrary fields.
Definition: H3DDynamicFieldsObject.h:128
This abstract node type is the base type for all prototype instances in the X3D system.
Definition: X3DPrototypeInstance.h:65
Provides a mapping between defined DEF names in X3D and the nodes they refer to.
Definition: DEFNodes.h:92
Abstract a location.
Definition: location.hh:57
H3D API namespace.
Definition: Anchor.h:38