]> git.mxchange.org Git - flightgear.git/blob - src/Main/fg_props.hxx
Patch from Jim Wilson:
[flightgear.git] / src / Main / fg_props.hxx
1 // fg_props.hxx - Declarations and inline methods for property handling.
2 // Written by David Megginson, started 2000.
3 //
4 // This file is in the Public Domain, and comes with no warranty.
5
6 #ifndef __FG_PROPS_HXX
7 #define __FG_PROPS_HXX 1
8
9 #include <simgear/debug/logstream.hxx>
10 #include <simgear/misc/props.hxx>
11 #include "globals.hxx"
12
13 \f
14 ////////////////////////////////////////////////////////////////////////
15 // Property management.
16 ////////////////////////////////////////////////////////////////////////
17
18
19 /**
20  * Initialize the default FlightGear properties.
21  *
22  * These are mostly properties that haven't been claimed by a
23  * specific module yet.  This function should be invoked once,
24  * while the program is starting (and after the global property
25  * tree has been created).
26  */
27 extern void fgInitProps ();     // fixme: how are they untied?
28
29
30 /**
31  * Update the default FlightGear properties.
32  *
33  * This function should be invoked once in each loop to update all
34  * of the default properties.
35  */
36 extern void fgUpdateProps ();
37
38
39 /**
40  * Save a flight to disk.
41  *
42  * This function saves all of the archivable properties to a stream
43  * so that the current flight can be restored later.
44  *
45  * @param output The output stream to write the XML save file to.
46  * @param write_all If true, write all properties rather than
47  *        just the ones flagged as archivable.
48  * @return true if the flight was saved successfully.
49  */
50 extern bool fgSaveFlight (ostream &output, bool write_all = false);
51
52
53 /**
54  * Load a flight from disk.
55  *
56  * This function loads an XML save file from a stream to restore
57  * a flight.
58  *
59  * @param input The input stream to read the XML from.
60  * @return true if the flight was restored successfully.
61  */
62 extern bool fgLoadFlight (istream &input);
63
64
65 \f
66 ////////////////////////////////////////////////////////////////////////
67 // Convenience functions for getting property values.
68 ////////////////////////////////////////////////////////////////////////
69
70
71 /**
72  * Get a property node.
73  *
74  * @param path The path of the node, relative to root.
75  * @param create true to create the node if it doesn't exist.
76  * @return The node, or 0 if none exists and none was created.
77  */
78 inline SGPropertyNode * 
79 fgGetNode (const string &path, bool create = false)
80 {
81   return globals->get_props()->getNode(path, create);
82 }
83
84
85 /**
86  * Get a property node with separate index.
87  *
88  * This method separates the index from the path string, to make it
89  * easier to iterate through multiple components without using sprintf
90  * to add indices.  For example, fgGetNode("foo[1]/bar", 3) will
91  * return the same result as fgGetNode("foo[1]/bar[3]").
92  *
93  * @param path The path of the node, relative to root.
94  * @param index The index for the last member of the path (overrides
95  * any given in the string).
96  * @param create true to create the node if it doesn't exist.
97  * @return The node, or 0 if none exists and none was created.
98  */
99 inline SGPropertyNode * 
100 fgGetNode (const string &path, int index, bool create = false)
101 {
102   return globals->get_props()->getNode(path, index, create);
103 }
104
105
106 /**
107  * Test whether a given node exists.
108  *
109  * @param path The path of the node, relative to root.
110  * @return true if the node exists, false otherwise.
111  */
112 inline bool
113 fgHasNode (const string &path)
114 {
115   return (fgGetNode(path, false) != 0);
116 }
117
118
119 /**
120  * Get a bool value for a property.
121  *
122  * This method is convenient but inefficient.  It should be used
123  * infrequently (i.e. for initializing, loading, saving, etc.),
124  * not in the main loop.  If you need to get a value frequently,
125  * it is better to look up the node itself using fgGetNode and then
126  * use the node's getBoolValue() method, to avoid the lookup overhead.
127  *
128  * @param name The property name.
129  * @param defaultValue The default value to return if the property
130  *        does not exist.
131  * @return The property's value as a bool, or the default value provided.
132  */
133 inline bool fgGetBool (const string &name, bool defaultValue = false)
134 {
135   return globals->get_props()->getBoolValue(name, defaultValue);
136 }
137
138
139 /**
140  * Get an int value for a property.
141  *
142  * This method is convenient but inefficient.  It should be used
143  * infrequently (i.e. for initializing, loading, saving, etc.),
144  * not in the main loop.  If you need to get a value frequently,
145  * it is better to look up the node itself using fgGetNode and then
146  * use the node's getIntValue() method, to avoid the lookup overhead.
147  *
148  * @param name The property name.
149  * @param defaultValue The default value to return if the property
150  *        does not exist.
151  * @return The property's value as an int, or the default value provided.
152  */
153 inline int fgGetInt (const string &name, int defaultValue = 0)
154 {
155   return globals->get_props()->getIntValue(name, defaultValue);
156 }
157
158
159 /**
160  * Get a long value for a property.
161  *
162  * This method is convenient but inefficient.  It should be used
163  * infrequently (i.e. for initializing, loading, saving, etc.),
164  * not in the main loop.  If you need to get a value frequently,
165  * it is better to look up the node itself using fgGetNode and then
166  * use the node's getLongValue() method, to avoid the lookup overhead.
167  *
168  * @param name The property name.
169  * @param defaultValue The default value to return if the property
170  *        does not exist.
171  * @return The property's value as a long, or the default value provided.
172  */
173 inline int fgGetLong (const string &name, long defaultValue = 0L)
174 {
175   return globals->get_props()->getLongValue(name, defaultValue);
176 }
177
178
179 /**
180  * Get a float value for a property.
181  *
182  * This method is convenient but inefficient.  It should be used
183  * infrequently (i.e. for initializing, loading, saving, etc.),
184  * not in the main loop.  If you need to get a value frequently,
185  * it is better to look up the node itself using fgGetNode and then
186  * use the node's getFloatValue() method, to avoid the lookup overhead.
187  *
188  * @param name The property name.
189  * @param defaultValue The default value to return if the property
190  *        does not exist.
191  * @return The property's value as a float, or the default value provided.
192  */
193 inline float fgGetFloat (const string &name, float defaultValue = 0.0)
194 {
195   return globals->get_props()->getFloatValue(name, defaultValue);
196 }
197
198
199 /**
200  * Get a double value for a property.
201  *
202  * This method is convenient but inefficient.  It should be used
203  * infrequently (i.e. for initializing, loading, saving, etc.),
204  * not in the main loop.  If you need to get a value frequently,
205  * it is better to look up the node itself using fgGetNode and then
206  * use the node's getDoubleValue() method, to avoid the lookup overhead.
207  *
208  * @param name The property name.
209  * @param defaultValue The default value to return if the property
210  *        does not exist.
211  * @return The property's value as a double, or the default value provided.
212  */
213 inline double fgGetDouble (const string &name, double defaultValue = 0.0)
214 {
215   return globals->get_props()->getDoubleValue(name, defaultValue);
216 }
217
218
219 /**
220  * Get a string value for a property.
221  *
222  * This method is convenient but inefficient.  It should be used
223  * infrequently (i.e. for initializing, loading, saving, etc.),
224  * not in the main loop.  If you need to get a value frequently,
225  * it is better to look up the node itself using fgGetNode and then
226  * use the node's getStringValue() method, to avoid the lookup overhead.
227  *
228  * @param name The property name.
229  * @param defaultValue The default value to return if the property
230  *        does not exist.
231  * @return The property's value as a string, or the default value provided.
232  */
233 inline string fgGetString (const string &name, string defaultValue = "")
234 {
235   return globals->get_props()->getStringValue(name, defaultValue);
236 }
237
238
239 /**
240  * Set a bool value for a property.
241  *
242  * Assign a bool value to a property.  If the property does not
243  * yet exist, it will be created and its type will be set to
244  * BOOL; if it has a type of UNKNOWN, the type will also be set to
245  * BOOL; otherwise, the bool value will be converted to the property's
246  * type.
247  *
248  * @param name The property name.
249  * @param val The new value for the property.
250  * @return true if the assignment succeeded, false otherwise.
251  */
252 inline bool fgSetBool (const string &name, bool val)
253 {
254   return globals->get_props()->setBoolValue(name, val);
255 }
256
257
258 /**
259  * Set an int value for a property.
260  *
261  * Assign an int value to a property.  If the property does not
262  * yet exist, it will be created and its type will be set to
263  * INT; if it has a type of UNKNOWN, the type will also be set to
264  * INT; otherwise, the bool value will be converted to the property's
265  * type.
266  *
267  * @param name The property name.
268  * @param val The new value for the property.
269  * @return true if the assignment succeeded, false otherwise.
270  */
271 inline bool fgSetInt (const string &name, int val)
272 {
273   return globals->get_props()->setIntValue(name, val);
274 }
275
276
277 /**
278  * Set a long value for a property.
279  *
280  * Assign a long value to a property.  If the property does not
281  * yet exist, it will be created and its type will be set to
282  * LONG; if it has a type of UNKNOWN, the type will also be set to
283  * LONG; otherwise, the bool value will be converted to the property's
284  * type.
285  *
286  * @param name The property name.
287  * @param val The new value for the property.
288  * @return true if the assignment succeeded, false otherwise.
289  */
290 inline bool fgSetLong (const string &name, long val)
291 {
292   return globals->get_props()->setLongValue(name, val);
293 }
294
295
296 /**
297  * Set a float value for a property.
298  *
299  * Assign a float value to a property.  If the property does not
300  * yet exist, it will be created and its type will be set to
301  * FLOAT; if it has a type of UNKNOWN, the type will also be set to
302  * FLOAT; otherwise, the bool value will be converted to the property's
303  * type.
304  *
305  * @param name The property name.
306  * @param val The new value for the property.
307  * @return true if the assignment succeeded, false otherwise.
308  */
309 inline bool fgSetFloat (const string &name, float val)
310 {
311   return globals->get_props()->setFloatValue(name, val);
312 }
313
314
315 /**
316  * Set a double value for a property.
317  *
318  * Assign a double value to a property.  If the property does not
319  * yet exist, it will be created and its type will be set to
320  * DOUBLE; if it has a type of UNKNOWN, the type will also be set to
321  * DOUBLE; otherwise, the double value will be converted to the property's
322  * type.
323  *
324  * @param name The property name.
325  * @param val The new value for the property.
326  * @return true if the assignment succeeded, false otherwise.
327  */
328 inline bool fgSetDouble (const string &name, double val)
329 {
330   return globals->get_props()->setDoubleValue(name, val);
331 }
332
333
334 /**
335  * Set a string value for a property.
336  *
337  * Assign a string value to a property.  If the property does not
338  * yet exist, it will be created and its type will be set to
339  * STRING; if it has a type of UNKNOWN, the type will also be set to
340  * STRING; otherwise, the string value will be converted to the property's
341  * type.
342  *
343  * @param name The property name.
344  * @param val The new value for the property.
345  * @return true if the assignment succeeded, false otherwise.
346  */
347 inline bool fgSetString (const string &name, const string &val)
348 {
349   return globals->get_props()->setStringValue(name, val);
350 }
351
352
353 \f
354 ////////////////////////////////////////////////////////////////////////
355 // Convenience functions for setting property attributes.
356 ////////////////////////////////////////////////////////////////////////
357
358
359 /**
360  * Set the state of the archive attribute for a property.
361  *
362  * If the archive attribute is true, the property will be written
363  * when a flight is saved; if it is false, the property will be
364  * skipped.
365  *
366  * A warning message will be printed if the property does not exist.
367  *
368  * @param name The property name.
369  * @param state The state of the archive attribute (defaults to true).
370  */
371 inline void
372 fgSetArchivable (const string &name, bool state = true)
373 {
374   SGPropertyNode * node = globals->get_props()->getNode(name);
375   if (node == 0)
376     SG_LOG(SG_GENERAL, SG_ALERT,
377            "Attempt to set archive flag for non-existant property "
378            << name);
379   else
380     node->setAttribute(SGPropertyNode::ARCHIVE, state);
381 }
382
383
384 /**
385  * Set the state of the read attribute for a property.
386  *
387  * If the read attribute is true, the property value will be readable;
388  * if it is false, the property value will always be the default value
389  * for its type.
390  *
391  * A warning message will be printed if the property does not exist.
392  *
393  * @param name The property name.
394  * @param state The state of the read attribute (defaults to true).
395  */
396 inline void
397 fgSetReadable (const string &name, bool state = true)
398 {
399   SGPropertyNode * node = globals->get_props()->getNode(name);
400   if (node == 0)
401     SG_LOG(SG_GENERAL, SG_ALERT,
402            "Attempt to set read flag for non-existant property "
403            << name);
404   else
405     node->setAttribute(SGPropertyNode::READ, state);
406 }
407
408
409 /**
410  * Set the state of the write attribute for a property.
411  *
412  * If the write attribute is true, the property value may be modified
413  * (depending on how it is tied); if the write attribute is false, the
414  * property value may not be modified.
415  *
416  * A warning message will be printed if the property does not exist.
417  *
418  * @param name The property name.
419  * @param state The state of the write attribute (defaults to true).
420  */
421 inline void
422 fgSetWritable (const string &name, bool state = true)
423 {
424   SGPropertyNode * node = globals->get_props()->getNode(name);
425   if (node == 0)
426     SG_LOG(SG_GENERAL, SG_ALERT,
427            "Attempt to set write flag for non-existant property "
428            << name);
429   else
430     node->setAttribute(SGPropertyNode::WRITE, state);
431 }
432
433
434 \f
435 ////////////////////////////////////////////////////////////////////////
436 // Convenience functions for tying properties, with logging.
437 ////////////////////////////////////////////////////////////////////////
438
439
440 /**
441  * Untie a property from an external data source.
442  *
443  * Classes should use this function to release control of any
444  * properties they are managing.
445  */
446 inline void
447 fgUntie (const string &name)
448 {
449   if (!globals->get_props()->untie(name))
450     SG_LOG(SG_GENERAL, SG_WARN, "Failed to untie property " << name);
451 }
452
453
454                                 // Templates cause ambiguity here
455
456 /**
457  * Tie a property to an external bool variable.
458  *
459  * The property's value will automatically mirror the variable's
460  * value, and vice-versa, until the property is untied.
461  *
462  * @param name The property name to tie (full path).
463  * @param pointer A pointer to the variable.
464  * @param useDefault true if any existing property value should be
465  *        copied to the variable; false if the variable should not
466  *        be modified; defaults to true.
467  */
468 inline void
469 fgTie (const string &name, bool *pointer, bool useDefault = true)
470 {
471   if (!globals->get_props()->tie(name, SGRawValuePointer<bool>(pointer),
472                                  useDefault))
473     SG_LOG(SG_GENERAL, SG_WARN,
474            "Failed to tie property " << name << " to a pointer");
475 }
476
477
478 /**
479  * Tie a property to an external int variable.
480  *
481  * The property's value will automatically mirror the variable's
482  * value, and vice-versa, until the property is untied.
483  *
484  * @param name The property name to tie (full path).
485  * @param pointer A pointer to the variable.
486  * @param useDefault true if any existing property value should be
487  *        copied to the variable; false if the variable should not
488  *        be modified; defaults to true.
489  */
490 inline void
491 fgTie (const string &name, int *pointer, bool useDefault = true)
492 {
493   if (!globals->get_props()->tie(name, SGRawValuePointer<int>(pointer),
494                                  useDefault))
495     SG_LOG(SG_GENERAL, SG_WARN,
496            "Failed to tie property " << name << " to a pointer");
497 }
498
499
500 /**
501  * Tie a property to an external long variable.
502  *
503  * The property's value will automatically mirror the variable's
504  * value, and vice-versa, until the property is untied.
505  *
506  * @param name The property name to tie (full path).
507  * @param pointer A pointer to the variable.
508  * @param useDefault true if any existing property value should be
509  *        copied to the variable; false if the variable should not
510  *        be modified; defaults to true.
511  */
512 inline void
513 fgTie (const string &name, long *pointer, bool useDefault = true)
514 {
515   if (!globals->get_props()->tie(name, SGRawValuePointer<long>(pointer),
516                                  useDefault))
517     SG_LOG(SG_GENERAL, SG_WARN,
518            "Failed to tie property " << name << " to a pointer");
519 }
520
521
522 /**
523  * Tie a property to an external float variable.
524  *
525  * The property's value will automatically mirror the variable's
526  * value, and vice-versa, until the property is untied.
527  *
528  * @param name The property name to tie (full path).
529  * @param pointer A pointer to the variable.
530  * @param useDefault true if any existing property value should be
531  *        copied to the variable; false if the variable should not
532  *        be modified; defaults to true.
533  */
534 inline void
535 fgTie (const string &name, float *pointer, bool useDefault = true)
536 {
537   if (!globals->get_props()->tie(name, SGRawValuePointer<float>(pointer),
538                                  useDefault))
539     SG_LOG(SG_GENERAL, SG_WARN,
540            "Failed to tie property " << name << " to a pointer");
541 }
542
543
544 /**
545  * Tie a property to an external double variable.
546  *
547  * The property's value will automatically mirror the variable's
548  * value, and vice-versa, until the property is untied.
549  *
550  * @param name The property name to tie (full path).
551  * @param pointer A pointer to the variable.
552  * @param useDefault true if any existing property value should be
553  *        copied to the variable; false if the variable should not
554  *        be modified; defaults to true.
555  */
556 inline void
557 fgTie (const string &name, double *pointer, bool useDefault = true)
558 {
559   if (!globals->get_props()->tie(name, SGRawValuePointer<double>(pointer),
560                                  useDefault))
561     SG_LOG(SG_GENERAL, SG_WARN,
562            "Failed to tie property " << name << " to a pointer");
563 }
564
565
566 /**
567  * Tie a property to an external string variable.
568  *
569  * The property's value will automatically mirror the variable's
570  * value, and vice-versa, until the property is untied.
571  *
572  * @param name The property name to tie (full path).
573  * @param pointer A pointer to the variable.
574  * @param useDefault true if any existing property value should be
575  *        copied to the variable; false if the variable should not
576  *        be modified; defaults to true.
577  */
578 inline void
579 fgTie (const string &name, string *pointer, bool useDefault = true)
580 {
581   if (!globals->get_props()->tie(name, SGRawValuePointer<string>(pointer),
582                                  useDefault))
583     SG_LOG(SG_GENERAL, SG_WARN,
584            "Failed to tie property " << name << " to a pointer");
585 }
586
587
588 /**
589  * Tie a property to a pair of simple functions.
590  *
591  * Every time the property value is queried, the getter (if any) will
592  * be invoked; every time the property value is modified, the setter
593  * (if any) will be invoked.  The getter can be 0 to make the property
594  * unreadable, and the setter can be 0 to make the property
595  * unmodifiable.
596  *
597  * @param name The property name to tie (full path).
598  * @param getter The getter function, or 0 if the value is unreadable.
599  * @param setter The setter function, or 0 if the value is unmodifiable.
600  * @param useDefault true if the setter should be invoked with any existing 
601  *        property value should be; false if the old value should be
602  *        discarded; defaults to true.
603  */
604 template <class V>
605 inline void
606 fgTie (const string &name, V (*getter)(), void (*setter)(V) = 0,
607        bool useDefault = true)
608 {
609   if (!globals->get_props()->tie(name, SGRawValueFunctions<V>(getter, setter),
610                                  useDefault))
611     SG_LOG(SG_GENERAL, SG_WARN,
612            "Failed to tie property " << name << " to functions");
613 }
614
615
616 /**
617  * Tie a property to a pair of indexed functions.
618  *
619  * Every time the property value is queried, the getter (if any) will
620  * be invoked with the index provided; every time the property value
621  * is modified, the setter (if any) will be invoked with the index
622  * provided.  The getter can be 0 to make the property unreadable, and
623  * the setter can be 0 to make the property unmodifiable.
624  *
625  * @param name The property name to tie (full path).
626  * @param index The integer argument to pass to the getter and
627  *        setter functions.
628  * @param getter The getter function, or 0 if the value is unreadable.
629  * @param setter The setter function, or 0 if the value is unmodifiable.
630  * @param useDefault true if the setter should be invoked with any existing 
631  *        property value should be; false if the old value should be
632  *        discarded; defaults to true.
633  */
634 template <class V>
635 inline void
636 fgTie (const string &name, int index, V (*getter)(int),
637        void (*setter)(int, V) = 0, bool useDefault = true)
638 {
639   if (!globals->get_props()->tie(name,
640                                  SGRawValueFunctionsIndexed<V>(index,
641                                                                getter,
642                                                                setter),
643                                  useDefault))
644     SG_LOG(SG_GENERAL, SG_WARN,
645            "Failed to tie property " << name << " to indexed functions");
646 }
647
648
649 /**
650  * Tie a property to a pair of object methods.
651  *
652  * Every time the property value is queried, the getter (if any) will
653  * be invoked; every time the property value is modified, the setter
654  * (if any) will be invoked.  The getter can be 0 to make the property
655  * unreadable, and the setter can be 0 to make the property
656  * unmodifiable.
657  *
658  * @param name The property name to tie (full path).
659  * @param obj The object whose methods should be invoked.
660  * @param getter The object's getter method, or 0 if the value is
661  *        unreadable.
662  * @param setter The object's setter method, or 0 if the value is
663  *        unmodifiable.
664  * @param useDefault true if the setter should be invoked with any existing 
665  *        property value should be; false if the old value should be
666  *        discarded; defaults to true.
667  */
668 template <class T, class V>
669 inline void
670 fgTie (const string &name, T * obj, V (T::*getter)() const,
671        void (T::*setter)(V) = 0, bool useDefault = true)
672 {
673   if (!globals->get_props()->tie(name,
674                                  SGRawValueMethods<T,V>(*obj, getter, setter),
675                                  useDefault))
676     SG_LOG(SG_GENERAL, SG_WARN,
677            "Failed to tie property " << name << " to object methods");
678 }
679
680
681 /**
682  * Tie a property to a pair of indexed object methods.
683  *
684  * Every time the property value is queried, the getter (if any) will
685  * be invoked with the index provided; every time the property value
686  * is modified, the setter (if any) will be invoked with the index
687  * provided.  The getter can be 0 to make the property unreadable, and
688  * the setter can be 0 to make the property unmodifiable.
689  *
690  * @param name The property name to tie (full path).
691  * @param obj The object whose methods should be invoked.
692  * @param index The integer argument to pass to the getter and
693  *        setter methods.
694  * @param getter The getter method, or 0 if the value is unreadable.
695  * @param setter The setter method, or 0 if the value is unmodifiable.
696  * @param useDefault true if the setter should be invoked with any existing 
697  *        property value should be; false if the old value should be
698  *        discarded; defaults to true.
699  */
700 template <class T, class V>
701 inline void 
702 fgTie (const string &name, T * obj, int index,
703        V (T::*getter)(int) const, void (T::*setter)(int, V) = 0,
704        bool useDefault = true)
705 {
706   if (!globals->get_props()->tie(name,
707                                  SGRawValueMethodsIndexed<T,V>(*obj,
708                                                                index,
709                                                                getter,
710                                                                setter),
711                                  useDefault))
712     SG_LOG(SG_GENERAL, SG_WARN,
713            "Failed to tie property " << name << " to indexed object methods");
714 }
715
716
717 \f
718 ////////////////////////////////////////////////////////////////////////
719 // Conditions.
720 ////////////////////////////////////////////////////////////////////////
721
722
723 /**
724  * An encoded condition.
725  *
726  * This class encodes a single condition of some sort, possibly
727  * connected with properties.
728  *
729  * This class should migrate to somewhere more general.
730  */
731 class FGCondition
732 {
733 public:
734   FGCondition ();
735   virtual ~FGCondition ();
736   virtual bool test () const = 0;
737 };
738
739
740 /**
741  * Condition for a single property.
742  *
743  * This condition is true only if the property returns a boolean
744  * true value.
745  */
746 class FGPropertyCondition : public FGCondition
747 {
748 public:
749   FGPropertyCondition (const string &propname);
750   virtual ~FGPropertyCondition ();
751   virtual bool test () const { return _node->getBoolValue(); }
752 private:
753   const SGPropertyNode * _node;
754 };
755
756
757 /**
758  * Condition for a 'not' operator.
759  *
760  * This condition is true only if the child condition is false.
761  */
762 class FGNotCondition : public FGCondition
763 {
764 public:
765                                 // transfer pointer ownership
766   FGNotCondition (FGCondition * condition);
767   virtual ~FGNotCondition ();
768   virtual bool test () const;
769 private:
770   FGCondition * _condition;
771 };
772
773
774 /**
775  * Condition for an 'and' group.
776  *
777  * This condition is true only if all of the conditions
778  * in the group are true.
779  */
780 class FGAndCondition : public FGCondition
781 {
782 public:
783   FGAndCondition ();
784   virtual ~FGAndCondition ();
785   virtual bool test () const;
786                                 // transfer pointer ownership
787   virtual void addCondition (FGCondition * condition);
788 private:
789   vector<FGCondition *> _conditions;
790 };
791
792
793 /**
794  * Condition for an 'or' group.
795  *
796  * This condition is true if at least one of the conditions in the
797  * group is true.
798  */
799 class FGOrCondition : public FGCondition
800 {
801 public:
802   FGOrCondition ();
803   virtual ~FGOrCondition ();
804   virtual bool test () const;
805                                 // transfer pointer ownership
806   virtual void addCondition (FGCondition * condition);
807 private:
808   vector<FGCondition *> _conditions;
809 };
810
811
812 /**
813  * Abstract base class for property comparison conditions.
814  */
815 class FGComparisonCondition : public FGCondition
816 {
817 public:
818   enum Type {
819     LESS_THAN,
820     GREATER_THAN,
821     EQUALS
822   };
823   FGComparisonCondition (Type type, bool reverse = false);
824   virtual ~FGComparisonCondition ();
825   virtual bool test () const;
826   virtual void setLeftProperty (const string &propname);
827   virtual void setRightProperty (const string &propname);
828                                 // will make a local copy
829   virtual void setRightValue (const SGPropertyNode * value);
830 private:
831   Type _type;
832   bool _reverse;
833   const SGPropertyNode * _left_property;
834   const SGPropertyNode * _right_property;
835   const SGPropertyNode * _right_value;
836 };
837
838
839 /**
840  * Base class for a conditional components.
841  *
842  * This class manages the conditions and tests; the component should
843  * invoke the test() method whenever it needs to decide whether to
844  * active itself, draw itself, and so on.
845  */
846 class FGConditional
847 {
848 public:
849   FGConditional ();
850   virtual ~FGConditional ();
851                                 // transfer pointer ownership
852   virtual void setCondition (FGCondition * condition);
853   virtual const FGCondition * getCondition () const { return _condition; }
854   virtual bool test () const;
855 private:
856   FGCondition * _condition;
857 };
858
859
860 /**
861  * Global function to make a condition out of properties.
862  *
863  * The top-level is always an implicit 'and' group, whatever the
864  * node's name (it should usually be "condition").
865  *
866  * @param node The top-level condition node (usually named "condition").
867  * @return A pointer to a newly-allocated condition; it is the
868  *         responsibility of the caller to delete the condition when
869  *         it is no longer needed.
870  */
871 FGCondition * fgReadCondition (const SGPropertyNode * node);
872
873
874 #endif // __FG_PROPS_HXX
875