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