Ocean
ClassicParser.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  *
4  * This source code is licensed under the MIT license found in the
5  * LICENSE file in the root directory of this source tree.
6  */
7 
8 #ifndef META_OCEAN_SCENEDESCRIPTION_SDX_X3D_CLASSIC_PARSER_H
9 #define META_OCEAN_SCENEDESCRIPTION_SDX_X3D_CLASSIC_PARSER_H
10 
13 
18 
19 namespace Ocean
20 {
21 
22 namespace SceneDescription
23 {
24 
25 namespace SDX
26 {
27 
28 namespace X3D
29 {
30 
31 // Forward declaration.
32 class X3DScene;
33 
34 /**
35  * This class implements a parser for the classic x3d file format.
36  * @ingroup scenedescriptionsdxx3d
37  */
38 class OCEAN_SCENEDESCRIPTION_SDX_X3D_EXPORT ClassicParser
39 {
40  protected:
41 
42  /**
43  * Definition of a scanner token.
44  */
46 
47  public:
48 
49  /**
50  * Creates a new classic parser.
51  * @param filename Name of the file to parse
52  * @param progress Optional parser progress state recurrently receiving the parsing progress if defined
53  * @param cancel Optional cancel state to stop the progress during process
54  */
55  explicit ClassicParser(const std::string& filename, float* progress = nullptr, bool* cancel = nullptr);
56 
57  /**
58  * Parses the given file and returns a node reference to the entire scene.
59  * @param library The library providing all nodes
60  * @param engine Rendering engine object to create corresponding rendering object from
61  * @param timestamp Parsing timestamp all scene objects will be initialized with this timestamp
62  * @return Parsed scene
63  */
64  SDXSceneRef parse(const Library& library, const Rendering::EngineRef& engine, const Timestamp timestamp = Timestamp());
65 
66  protected:
67 
68  /**
69  * Parses a new node.
70  */
72 
73  /**
74  * Adds a dynamic field.
75  * @param token The token holding the dynamic field type
76  * @param node The node receiving the dynamic field
77  */
78  void addDynamicField(const Token& token, const NodeRef& node);
79 
80  /**
81  * Parses a field.
82  * @param field The field receiving the parsed data
83  */
84  void parseField(Field& field);
85 
86  /**
87  * Parses a SFBool field.
88  * @param field The field receiving the parsed data
89  */
90  void parseField(SingleBool& field);
91 
92  /**
93  * Parses a SFColor field.
94  * @param field The field receiving the parsed data
95  */
96  void parseField(SingleColor& field);
97 
98  /**
99  * Parses a SFFloat field.
100  * @param field The field receiving the parsed data
101  */
102  void parseField(SingleFloat& field);
103 
104  /**
105  * Parses a SFInt32 field.
106  * @param field The field receiving the parsed data
107  */
108  void parseField(SingleInt& field);
109 
110  /**
111  * Parses a SFMatrix3 field.
112  * @param field The field receiving the parsed data
113  */
114  void parseField(SingleMatrix3& field);
115 
116  /**
117  * Parses a SFMatrix4 field.
118  * @param field The field receiving the parsed data
119  */
120  void parseField(SingleMatrix4& field);
121 
122  /**
123  * Parses a SFNode field.
124  * @param field The field receiving the parsed data
125  */
126  void parseField(SingleNode& field);
127 
128  /**
129  * Parses a SFRotation field.
130  * @param field The field receiving the parsed data
131  */
133 
134  /**
135  * Parses a SFString field.
136  * @param field The field receiving the parsed data
137  */
138  void parseField(SingleString& field);
139 
140  /**
141  * Parses a SFTime field.
142  * @param field The field receiving the parsed data
143  */
144  void parseField(SingleTime& field);
145 
146  /**
147  * Parses a SFVec2f field.
148  * @param field The field receiving the parsed data
149  */
150  void parseField(SingleVector2& field);
151 
152  /**
153  * Parses a SFVec3f field.
154  * @param field The field receiving the parsed data
155  */
156  void parseField(SingleVector3& field);
157 
158  /**
159  * Parses a SFVec4f field.
160  * @param field The field receiving the parsed data
161  */
162  void parseField(SingleVector4& field);
163 
164  /**
165  * Parses a MFBool field.
166  * @param field The field receiving the parsed data
167  */
168  void parseField(MultiBool& field);
169 
170  /**
171  * Parses a MFColor field.
172  * @param field The field receiving the parsed data
173  */
174  void parseField(MultiColor& field);
175 
176  /**
177  * Parses a MFFloat field.
178  * @param field The field receiving the parsed data
179  */
180  void parseField(MultiFloat& field);
181 
182  /**
183  * Parses a MFInt32 field.
184  * @param field The field receiving the parsed data
185  */
186  void parseField(MultiInt& field);
187 
188  /**
189  * Parses a MFMatrix3f field.
190  * @param field The field receiving the parsed data
191  */
192  void parseField(MultiMatrix3& field);
193 
194  /**
195  * Parses a MFMatrix4f field.
196  * @param field The field receiving the parsed data
197  */
198  void parseField(MultiMatrix4& field);
199 
200  /**
201  * Parses a MFNode field.
202  * @param field The field receiving the parsed data
203  */
204  void parseField(MultiNode& field);
205 
206  /**
207  * Parses a MFRotation field.
208  * @param field The field receiving the parsed data
209  */
210  void parseField(MultiRotation& field);
211 
212  /**
213  * Parses a MFString field.
214  * @param field The field receiving the parsed data
215  */
216  void parseField(MultiString& field);
217 
218  /**
219  * Parses a MFTime field.
220  * @param field The field receiving the parsed data
221  */
222  void parseField(MultiTime& field);
223 
224  /**
225  * Parses a MFVec2f field.
226  * @param field The field receiving the parsed data
227  */
228  void parseField(MultiVector2& field);
229 
230  /**
231  * Parses a MFVec3f field.
232  * @param field The field receiving the parsed data
233  */
234  void parseField(MultiVector3& field);
235 
236  /**
237  * Parses a MFVec4f field.
238  * @param field The field receiving the parsed data
239  */
240  void parseField(MultiVector4& field);
241 
242  /**
243  * Parses a route statement.
244  */
245  void parseRoute();
246 
247  /**
248  * Parses a meta statement.
249  */
250  void parseMeta();
251 
252  /**
253  * Parses a profile statement.
254  */
255  void parseProfile();
256 
257  /**
258  * Parses a boolean value.
259  * @return The parsed boolean value
260  */
261  bool parseBool();
262 
263  /**
264  * Parses a float value.
265  * @return Parsed float value
266  */
268 
269  /**
270  * Parses a string value.
271  * @return Parsed string value
272  */
273  std::string parseString();
274 
275  /**
276  * Parses a rotation value.
277  * @return Parsed rotation value
278  */
280 
281  /**
282  * Skips a unknown x3d node.
283  * @param nodeStartedAlready True, if the node has been started with an opening break already, false otherwise
284  * @return True, if the node could be skipped successfully
285  */
286  bool skipNode(const bool nodeStartedAlready);
287 
288  protected:
289 
290  /// Scanner scanning x3d token.
292 
293  /// X3D scene holding the parsed scene.
294  X3DScene* scenePtr_ = nullptr;
295 
296  /// Scene timestamp.
297  Timestamp sceneTimestamp_ = Timestamp(false);
298 };
299 
300 }
301 
302 }
303 
304 }
305 
306 }
307 
308 #endif // META_OCEAN_SCENEDESCRIPTION_SDX_X3D_CLASSIC_PARSER_H
This class implements a token for the scanner.
Definition: Scanner.h:43
This class implements a axis-angle rotation using floating point values.
Definition: Rotation.h:79
This class implements all 1D fields (fields holding an array of single values).
Definition: Field1D.h:110
This class is the base class for all scene description fields.
Definition: Field.h:36
This class is the base class for all scene description libraries.
Definition: scenedescription/Library.h:37
This class implements a parser for the classic x3d file format.
Definition: ClassicParser.h:39
void parseField(MultiColor &field)
Parses a MFColor field.
void parseField(MultiFloat &field)
Parses a MFFloat field.
void parseField(MultiMatrix3 &field)
Parses a MFMatrix3f field.
void parseRoute()
Parses a route statement.
SDXSceneRef parse(const Library &library, const Rendering::EngineRef &engine, const Timestamp timestamp=Timestamp())
Parses the given file and returns a node reference to the entire scene.
void parseField(MultiRotation &field)
Parses a MFRotation field.
ClassicScanner scanner_
Scanner scanning x3d token.
Definition: ClassicParser.h:291
void parseField(MultiInt &field)
Parses a MFInt32 field.
void parseField(SingleNode &field)
Parses a SFNode field.
void parseField(SingleMatrix3 &field)
Parses a SFMatrix3 field.
Rotation parseRotation()
Parses a rotation value.
void parseField(MultiNode &field)
Parses a MFNode field.
void parseProfile()
Parses a profile statement.
void parseField(MultiString &field)
Parses a MFString field.
void parseField(SingleString &field)
Parses a SFString field.
void parseField(SingleTime &field)
Parses a SFTime field.
ClassicScanner::Token Token
Definition of a scanner token.
Definition: ClassicParser.h:45
void parseField(MultiVector2 &field)
Parses a MFVec2f field.
void parseField(SingleVector3 &field)
Parses a SFVec3f field.
void parseField(MultiTime &field)
Parses a MFTime field.
void parseMeta()
Parses a meta statement.
void parseField(SingleInt &field)
Parses a SFInt32 field.
ClassicParser(const std::string &filename, float *progress=nullptr, bool *cancel=nullptr)
Creates a new classic parser.
void parseField(SingleMatrix4 &field)
Parses a SFMatrix4 field.
void parseField(MultiMatrix4 &field)
Parses a MFMatrix4f field.
void parseField(SingleBool &field)
Parses a SFBool field.
std::string parseString()
Parses a string value.
void parseField(SingleVector2 &field)
Parses a SFVec2f field.
Scalar parseFloat()
Parses a float value.
void parseField(MultiVector4 &field)
Parses a MFVec4f field.
void parseField(MultiVector3 &field)
Parses a MFVec3f field.
void addDynamicField(const Token &token, const NodeRef &node)
Adds a dynamic field.
void parseField(Field &field)
Parses a field.
void parseField(MultiBool &field)
Parses a MFBool field.
void parseField(SingleColor &field)
Parses a SFColor field.
bool skipNode(const bool nodeStartedAlready)
Skips a unknown x3d node.
void parseField(SingleRotation &field)
Parses a SFRotation field.
void parseField(SingleVector4 &field)
Parses a SFVec4f field.
void parseField(SingleFloat &field)
Parses a SFFloat field.
This class implements a scanner for the classic x3d file format.
Definition: ClassicScanner.h:32
This class implements a scene object holding an entire x3d scene.
Definition: X3DScene.h:39
This class implements a timestamp.
Definition: Timestamp.h:36
float Scalar
Definition of a scalar type.
Definition: Math.h:128
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15