Coin: ScXMLEvaluator.h Source File

| Coin3D is Free Software, published under the BSD 3-clause license. | https://coin3d.github.io https://www.kongsberg.com/en/kogt/

ScXMLEvaluator.h
1#ifndef COIN_SCXMLEVALUATOR_H
2#define COIN_SCXMLEVALUATOR_H
3
4/**************************************************************************\
5 * Copyright (c) Kongsberg Oil & Gas Technologies AS
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
10 * met:
11 *
12 * Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
14 *
15 * Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * Neither the name of the copyright holder nor the names of its
20 * contributors may be used to endorse or promote products derived from
21 * this software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34\**************************************************************************/
35
36#include <Inventor/scxml/ScXMLObject.h>
37#include <Inventor/tools/SbLazyPimplPtr.h>
38
39class ScXMLDocument;
40class ScXMLStateMachine;
41class ScXMLDataObj;
42
43
44 class COIN_DLL_API ScXMLEvaluator : public ScXMLObject {
45 typedef ScXMLObject inherited;
46 SCXML_OBJECT_ABSTRACT_HEADER(ScXMLEvaluator)
47public:
48 static void initClass(void);
49 static void cleanClass(void);
50
51 ScXMLEvaluator(void);
52 virtual ~ScXMLEvaluator(void);
53
54 virtual void setStateMachine(ScXMLStateMachine * sm);
55 ScXMLStateMachine * getStateMachine(void) const { return this->statemachine; }
56
57 virtual ScXMLDataObj * evaluate(const char * expression) const = 0;
58
59 virtual SbBool setAtLocation(const char * location, ScXMLDataObj * obj) = 0;
60 virtual ScXMLDataObj * locate(const char * location) const = 0;
61
62 virtual void clearTemporaryVariables(void);
63
64protected:
65
66private:
67 ScXMLStateMachine * statemachine;
68
69 class PImpl;
70 SbLazyPimplPtr<PImpl> pimpl;
71
72}; // ScXMLEvaluator
73
74
75// *************************************************************************
76
77 class COIN_DLL_API ScXMLDataObj : public ScXMLObject {
78 SCXML_OBJECT_ABSTRACT_HEADER(ScXMLDataObj)
79 typedef ScXMLObject inherited;
80public:
81 static void initClass(void);
82 static void cleanClass(void);
83
84 ScXMLDataObj(void);
85 virtual ~ScXMLDataObj(void);
86
87 void setContainer(ScXMLObject * container);
88 ScXMLObject * getContainer(void) const { return this->container; }
89
90private:
91 ScXMLObject * container;
92
93}; // ScXMLDataObj
94
95 class COIN_DLL_API ScXMLConstantDataObj : public ScXMLDataObj {
96 SCXML_OBJECT_ABSTRACT_HEADER(ScXMLConstantDataObj)
97 typedef ScXMLDataObj inherited;
98public:
99 static void initClass(void);
100 static void cleanClass(void);
101
102 virtual ScXMLDataObj * clone(void) const = 0;
103 virtual void convertToString(SbString & str) const = 0;
104
105};
106
107
108 class COIN_DLL_API ScXMLStringDataObj : public ScXMLConstantDataObj {
109 SCXML_OBJECT_HEADER(ScXMLStringDataObj)
110 typedef ScXMLConstantDataObj inherited;
111public:
112 static void initClass(void);
113 static void cleanClass(void);
114
115 static ScXMLDataObj * createFor(const char * value);
116
117 ScXMLStringDataObj(void);
118 ScXMLStringDataObj(const char * value);
119 virtual ~ScXMLStringDataObj(void);
120
121 void setString(const char * value);
122 const char * getString(void) const { return this->value; }
123
124 virtual ScXMLDataObj * clone(void) const;
125 virtual void convertToString(SbString & str) const;
126
127private:
128 char * value;
129
130};
131
132
133 class COIN_DLL_API ScXMLRealDataObj : public ScXMLConstantDataObj {
134 SCXML_OBJECT_HEADER(ScXMLRealDataObj)
135 typedef ScXMLConstantDataObj inherited;
136public:
137 static void initClass(void);
138 static void cleanClass(void);
139
140 static ScXMLDataObj * createFor(double value);
141
142 ScXMLRealDataObj(void);
143 ScXMLRealDataObj(double value);
144 virtual ~ScXMLRealDataObj(void);
145
146 void setReal(double value);
147 double getReal(void) const { return this->value; }
148
149 virtual ScXMLDataObj * clone(void) const;
150 virtual void convertToString(SbString & str) const;
151
152private:
153 double value;
154
155};
156
157
158 class COIN_DLL_API ScXMLBoolDataObj : public ScXMLConstantDataObj {
159 SCXML_OBJECT_HEADER(ScXMLBoolDataObj)
160 typedef ScXMLConstantDataObj inherited;
161public:
162 static void initClass(void);
163 static void cleanClass(void);
164
165 static ScXMLDataObj * createFor(SbBool value);
166
167 ScXMLBoolDataObj(void);
168 ScXMLBoolDataObj(SbBool value);
169 virtual ~ScXMLBoolDataObj(void);
170
171 void setBool(SbBool value);
172 SbBool getBool(void) const { return this->value; }
173
174 virtual ScXMLDataObj * clone(void) const;
175 virtual void convertToString(SbString & str) const;
176
177private:
178 SbBool value;
179
180};
181
182
183 class COIN_DLL_API ScXMLSbDataObj : public ScXMLConstantDataObj {
184 SCXML_OBJECT_HEADER(ScXMLSbDataObj)
185 typedef ScXMLConstantDataObj inherited;
186public:
187 static void initClass(void);
188 static void cleanClass(void);
189
190 static ScXMLDataObj * createFor(const char * value);
191
192 ScXMLSbDataObj(void);
193 ScXMLSbDataObj(const char * value);
194 virtual ~ScXMLSbDataObj(void);
195
196 void setSbValue(const char * value);
197 const char * getSbValue(void) const { return this->value; }
198
199 virtual ScXMLDataObj * clone(void) const;
200 virtual void convertToString(SbString & str) const;
201
202private:
203 char * value;
204
205};
206
207
208 class COIN_DLL_API ScXMLXMLDataObj : public ScXMLDataObj {
209 SCXML_OBJECT_HEADER(ScXMLXMLDataObj)
210 typedef ScXMLDataObj inherited;
211public:
212 static void initClass(void);
213 static void cleanClass(void);
214
215 ScXMLXMLDataObj(void);
216 virtual ~ScXMLXMLDataObj(void);
217
218 virtual ScXMLDataObj * clone(void) const;
219
220};
221
222
223 class COIN_DLL_API ScXMLExprDataObj : public ScXMLDataObj {
224 SCXML_OBJECT_ABSTRACT_HEADER(ScXMLExprDataObj)
225 typedef ScXMLDataObj inherited;
226public:
227 static void initClass(void);
228 static void cleanClass(void);
229
230 ScXMLExprDataObj(void);
231 virtual ~ScXMLExprDataObj(void);
232
233 ScXMLDataObj * evaluate(ScXMLStateMachine * sm);
234
235protected:
236 virtual SbBool evaluateNow(ScXMLStateMachine * sm, ScXMLDataObj *& pointer) const = 0;
237
238private:
239 ScXMLDataObj * result;
240
241};
242
243
244 class COIN_DLL_API ScXMLReferenceDataObj : public ScXMLExprDataObj {
245 SCXML_OBJECT_HEADER(ScXMLReferenceDataObj)
246 typedef ScXMLExprDataObj inherited;
247public:
248 static void initClass(void);
249 static void cleanClass(void);
250
251 static ScXMLDataObj * createFor(const char * reference);
252
253 ScXMLReferenceDataObj(void);
254 ScXMLReferenceDataObj(const char * reference);
255 virtual ~ScXMLReferenceDataObj(void);
256
257 void setReference(const char * reference);
258 const char * getReference(void) const { return this->reference; }
259
260 virtual SbBool evaluateNow(ScXMLStateMachine * sm, ScXMLDataObj *& pointer) const;
261
262private:
263 char * reference;
264
265};
266
267
268// *************************************************************************
269// logical operators
270
271 class COIN_DLL_API ScXMLAndOpExprDataObj : public ScXMLExprDataObj {
272 SCXML_OBJECT_HEADER(ScXMLAndOpExprDataObj)
273 typedef ScXMLExprDataObj inherited;
274public:
275 static void initClass(void);
276 static void cleanClass(void);
277
278 static ScXMLDataObj * createFor(ScXMLDataObj * lhs, ScXMLDataObj * rhs);
279
280 ScXMLAndOpExprDataObj(void);
281 ScXMLAndOpExprDataObj(ScXMLDataObj * lhs, ScXMLDataObj * rhs);
282 virtual ~ScXMLAndOpExprDataObj(void);
283
284 void setLHS(ScXMLDataObj * lhs);
285 const ScXMLDataObj * getLHS(void) const { return this->lhs; }
286 void setRHS(ScXMLDataObj * rhs);
287 const ScXMLDataObj * getRHS(void) const { return this->rhs; }
288
289protected:
290 virtual SbBool evaluateNow(ScXMLStateMachine * sm, ScXMLDataObj *& pointer) const;
291
292private:
293 ScXMLDataObj * lhs, * rhs;
294
295};
296
297
298 class COIN_DLL_API ScXMLOrOpExprDataObj : public ScXMLExprDataObj {
299 SCXML_OBJECT_HEADER(ScXMLOrOpExprDataObj)
300 typedef ScXMLExprDataObj inherited;
301public:
302 static void initClass(void);
303 static void cleanClass(void);
304
305 static ScXMLDataObj * createFor(ScXMLDataObj * lhs, ScXMLDataObj * rhs);
306
307 ScXMLOrOpExprDataObj(void);
308 ScXMLOrOpExprDataObj(ScXMLDataObj * lhs, ScXMLDataObj * rhs);
309 virtual ~ScXMLOrOpExprDataObj(void);
310
311 void setLHS(ScXMLDataObj * lhs);
312 const ScXMLDataObj * getLHS(void) const { return this->lhs; }
313 void setRHS(ScXMLDataObj * rhs);
314 const ScXMLDataObj * getRHS(void) const { return this->rhs; }
315
316protected:
317 virtual SbBool evaluateNow(ScXMLStateMachine * sm, ScXMLDataObj *& pointer) const;
318
319private:
320 ScXMLDataObj * lhs, * rhs;
321
322};
323
324
325 class COIN_DLL_API ScXMLNotOpExprDataObj : public ScXMLExprDataObj {
326 SCXML_OBJECT_HEADER(ScXMLNotOpExprDataObj)
327 typedef ScXMLExprDataObj inherited;
328public:
329 static void initClass(void);
330 static void cleanClass(void);
331
332 static ScXMLDataObj * createFor(ScXMLDataObj * rhs);
333
334 ScXMLNotOpExprDataObj(void);
335 ScXMLNotOpExprDataObj(ScXMLDataObj * rhs);
336 virtual ~ScXMLNotOpExprDataObj(void);
337
338 void setRHS(ScXMLDataObj * rhs);
339 const ScXMLDataObj * getRHS(void) const { return this->rhs; }
340
341protected:
342 virtual SbBool evaluateNow(ScXMLStateMachine * sm, ScXMLDataObj *& pointer) const;
343
344private:
345 ScXMLDataObj * rhs;
346
347};
348
349
350 class COIN_DLL_API ScXMLEqualsOpExprDataObj : public ScXMLExprDataObj {
351 SCXML_OBJECT_HEADER(ScXMLEqualsOpExprDataObj)
352 typedef ScXMLExprDataObj inherited;
353public:
354 static void initClass(void);
355 static void cleanClass(void);
356
357 static ScXMLDataObj * createFor(ScXMLDataObj * lhs, ScXMLDataObj * rhs);
358
359 ScXMLEqualsOpExprDataObj(void);
360 ScXMLEqualsOpExprDataObj(ScXMLDataObj * lhs, ScXMLDataObj * rhs);
361 virtual ~ScXMLEqualsOpExprDataObj(void);
362
363 void setLHS(ScXMLDataObj * lhs);
364 const ScXMLDataObj * getLHS(void) const { return this->lhs; }
365 void setRHS(ScXMLDataObj * rhs);
366 const ScXMLDataObj * getRHS(void) const { return this->rhs; }
367
368protected:
369 virtual SbBool evaluateNow(ScXMLStateMachine * sm, ScXMLDataObj *& pointer) const;
370
371private:
372 ScXMLDataObj * lhs, * rhs;
373
374};
375
376
377// *************************************************************************
378// arithmetic operators
379
380 class COIN_DLL_API ScXMLAddOpExprDataObj : public ScXMLExprDataObj {
381 SCXML_OBJECT_HEADER(ScXMLAddOpExprDataObj)
382 typedef ScXMLExprDataObj inherited;
383public:
384 static void initClass(void);
385 static void cleanClass(void);
386
387 static ScXMLDataObj * createFor(ScXMLDataObj * lhs, ScXMLDataObj * rhs);
388
389 ScXMLAddOpExprDataObj(void);
390 ScXMLAddOpExprDataObj(ScXMLDataObj * lhs, ScXMLDataObj * rhs);
391 virtual ~ScXMLAddOpExprDataObj(void);
392
393 void setLHS(ScXMLDataObj * lhs);
394 const ScXMLDataObj * getLHS(void) const { return this->lhs; }
395 void setRHS(ScXMLDataObj * rhs);
396 const ScXMLDataObj * getRHS(void) const { return this->rhs; }
397
398protected:
399 virtual SbBool evaluateNow(ScXMLStateMachine * sm, ScXMLDataObj *& pointer) const;
400
401private:
402 ScXMLDataObj * lhs, * rhs;
403
404};
405
406
407 class COIN_DLL_API ScXMLSubtractOpExprDataObj : public ScXMLExprDataObj {
408 SCXML_OBJECT_HEADER(ScXMLSubtractOpExprDataObj)
409 typedef ScXMLExprDataObj inherited;
410public:
411 static void initClass(void);
412 static void cleanClass(void);
413
414 static ScXMLDataObj * createFor(ScXMLDataObj * lhs, ScXMLDataObj * rhs);
415
416 ScXMLSubtractOpExprDataObj(void);
417 ScXMLSubtractOpExprDataObj(ScXMLDataObj * lhs, ScXMLDataObj * rhs);
418 virtual ~ScXMLSubtractOpExprDataObj(void);
419
420 void setLHS(ScXMLDataObj * lhs);
421 const ScXMLDataObj * getLHS(void) const { return this->lhs; }
422 void setRHS(ScXMLDataObj * rhs);
423 const ScXMLDataObj * getRHS(void) const { return this->rhs; }
424
425protected:
426 virtual SbBool evaluateNow(ScXMLStateMachine * sm, ScXMLDataObj *& pointer) const;
427
428private:
429 ScXMLDataObj * lhs, * rhs;
430
431};
432
433
434 class COIN_DLL_API ScXMLMultiplyOpExprDataObj : public ScXMLExprDataObj {
435 SCXML_OBJECT_HEADER(ScXMLMultiplyOpExprDataObj)
436 typedef ScXMLExprDataObj inherited;
437public:
438 static void initClass(void);
439 static void cleanClass(void);
440
441 static ScXMLDataObj * createFor(ScXMLDataObj * lhs, ScXMLDataObj * rhs);
442
443 ScXMLMultiplyOpExprDataObj(void);
444 ScXMLMultiplyOpExprDataObj(ScXMLDataObj * lhs, ScXMLDataObj * rhs);
445 virtual ~ScXMLMultiplyOpExprDataObj(void);
446
447 void setLHS(ScXMLDataObj * lhs);
448 const ScXMLDataObj * getLHS(void) const { return this->lhs; }
449 void setRHS(ScXMLDataObj * rhs);
450 const ScXMLDataObj * getRHS(void) const { return this->rhs; }
451
452protected:
453 virtual SbBool evaluateNow(ScXMLStateMachine * sm, ScXMLDataObj *& pointer) const;
454
455private:
456 ScXMLDataObj * lhs, * rhs;
457
458};
459
460
461 class COIN_DLL_API ScXMLDivideOpExprDataObj : public ScXMLExprDataObj {
462 SCXML_OBJECT_HEADER(ScXMLDivideOpExprDataObj)
463 typedef ScXMLExprDataObj inherited;
464public:
465 static void initClass(void);
466 static void cleanClass(void);
467
468 static ScXMLDataObj * createFor(ScXMLDataObj * lhs, ScXMLDataObj * rhs);
469
470 ScXMLDivideOpExprDataObj(void);
471 ScXMLDivideOpExprDataObj(ScXMLDataObj * lhs, ScXMLDataObj * rhs);
472 virtual ~ScXMLDivideOpExprDataObj(void);
473
474 void setLHS(ScXMLDataObj * lhs);
475 const ScXMLDataObj * getLHS(void) const { return this->lhs; }
476 void setRHS(ScXMLDataObj * rhs);
477 const ScXMLDataObj * getRHS(void) const { return this->rhs; }
478
479protected:
480 virtual SbBool evaluateNow(ScXMLStateMachine * sm, ScXMLDataObj *& pointer) const;
481
482private:
483 ScXMLDataObj * lhs, * rhs;
484
485};
486
487
488 class COIN_DLL_API ScXMLNegateOpExprDataObj : public ScXMLExprDataObj {
489 SCXML_OBJECT_HEADER(ScXMLNegateOpExprDataObj)
490 typedef ScXMLExprDataObj inherited;
491public:
492 static void initClass(void);
493 static void cleanClass(void);
494
495 static ScXMLDataObj * createFor(ScXMLDataObj * rhs);
496
497 ScXMLNegateOpExprDataObj(void);
498 ScXMLNegateOpExprDataObj(ScXMLDataObj * rhs);
499 virtual ~ScXMLNegateOpExprDataObj(void);
500
501 void setRHS(ScXMLDataObj * rhs);
502 const ScXMLDataObj * getRHS(void) const { return this->rhs; }
503
504protected:
505 virtual SbBool evaluateNow(ScXMLStateMachine * sm, ScXMLDataObj *& pointer) const;
506
507private:
508 ScXMLDataObj * rhs;
509
510};
511
512
513#endif // !COIN_SCXMLEVALUATOR_H
SbLazyPimplPtr
Definition SbLazyPimplPtr.h:56
SbString
The SbString class is a string class with convenience functions for string operations.
Definition SbString.h:52
ScXMLConstantDataObj
base class for immediate data values
Definition ScXMLEvaluator.h:95
ScXMLDataObj
base class for evaluator data objects in the SCXML data module
Definition ScXMLEvaluator.h:77
ScXMLDocument
Definition ScXMLDocument.h:47
ScXMLEvaluator::setStateMachine
virtual void setStateMachine(ScXMLStateMachine *sm)
Definition ScXMLEvaluator.cpp:134
ScXMLObject
Base class for all SCXML objects.
Definition ScXMLObject.h:41
ScXMLObject::cleanClass
static void cleanClass(void)
Does the opposite of initClass, deallocates any class specific resources and resets the class to an u...
Definition ScXMLObject.cpp:115
ScXMLObject::initClass
static void initClass(void)
Sets up initialization for data common to all instances of this class, like submitting necessary info...
Definition ScXMLObject.cpp:102
ScXMLStateMachine
Manager for processing events and setting states in SCXML structures.
Definition ScXMLStateMachine.h:61