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