2001-07-12 23:36:04 +00:00
|
|
|
|
// fg_props.hxx - Declarations and inline methods for property handling.
|
|
|
|
|
// Written by David Megginson, started 2000.
|
|
|
|
|
//
|
|
|
|
|
// This file is in the Public Domain, and comes with no warranty.
|
|
|
|
|
|
2001-01-05 17:37:59 +00:00
|
|
|
|
#ifndef __FG_PROPS_HXX
|
|
|
|
|
#define __FG_PROPS_HXX 1
|
|
|
|
|
|
2008-07-31 12:04:32 +00:00
|
|
|
|
#include <iosfwd>
|
2002-03-16 00:18:38 +00:00
|
|
|
|
|
2008-07-31 12:04:32 +00:00
|
|
|
|
#include <simgear/structure/subsystem_mgr.hxx>
|
2012-03-04 14:30:08 +00:00
|
|
|
|
#include <simgear/props/tiedpropertylist.hxx>
|
2009-09-18 17:17:06 +00:00
|
|
|
|
|
|
|
|
|
#include <Main/globals.hxx>
|
|
|
|
|
|
2001-01-05 17:37:59 +00:00
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
2001-06-05 22:13:26 +00:00
|
|
|
|
// Property management.
|
2001-01-05 17:37:59 +00:00
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2004-02-20 17:35:33 +00:00
|
|
|
|
class FGProperties : public SGSubsystem
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
FGProperties ();
|
|
|
|
|
virtual ~FGProperties ();
|
|
|
|
|
|
2018-04-03 08:41:27 +00:00
|
|
|
|
// Subsystem API.
|
|
|
|
|
void bind() override;
|
|
|
|
|
void init() override;
|
|
|
|
|
void unbind() override;
|
|
|
|
|
void update(double dt) override;
|
2012-03-04 14:30:08 +00:00
|
|
|
|
|
2018-05-05 09:38:11 +00:00
|
|
|
|
// Subsystem identification.
|
|
|
|
|
static const char* staticSubsystemClassId() { return "properties"; }
|
|
|
|
|
|
2012-03-04 14:30:08 +00:00
|
|
|
|
private:
|
|
|
|
|
simgear::TiedPropertyList _tiedProperties;
|
2012-11-18 15:35:54 +00:00
|
|
|
|
|
|
|
|
|
static const char* getLatitudeString ();
|
|
|
|
|
static const char* getLongitudeString ();
|
|
|
|
|
|
|
|
|
|
static SGConstPropertyNode_ptr _longDeg, _latDeg, _lonLatformat;
|
|
|
|
|
|
|
|
|
|
SGPropertyNode_ptr _offset;
|
|
|
|
|
SGPropertyNode_ptr _uyear, _umonth, _uday, _uhour, _umin, _usec, _uwday, _udsec;
|
|
|
|
|
SGPropertyNode_ptr _ryear, _rmonth, _rday, _rhour, _rmin, _rsec, _rwday, _rdsec;
|
2004-02-20 17:35:33 +00:00
|
|
|
|
};
|
2001-07-12 23:36:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Save a flight to disk.
|
|
|
|
|
*
|
|
|
|
|
* This function saves all of the archivable properties to a stream
|
|
|
|
|
* so that the current flight can be restored later.
|
|
|
|
|
*
|
|
|
|
|
* @param output The output stream to write the XML save file to.
|
2002-03-03 22:48:40 +00:00
|
|
|
|
* @param write_all If true, write all properties rather than
|
|
|
|
|
* just the ones flagged as archivable.
|
2001-07-12 23:36:04 +00:00
|
|
|
|
* @return true if the flight was saved successfully.
|
|
|
|
|
*/
|
2008-07-31 12:04:32 +00:00
|
|
|
|
extern bool fgSaveFlight (std::ostream &output, bool write_all = false);
|
2001-07-12 23:36:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Load a flight from disk.
|
|
|
|
|
*
|
|
|
|
|
* This function loads an XML save file from a stream to restore
|
|
|
|
|
* a flight.
|
|
|
|
|
*
|
|
|
|
|
* @param input The input stream to read the XML from.
|
|
|
|
|
* @return true if the flight was restored successfully.
|
|
|
|
|
*/
|
2008-07-31 12:04:32 +00:00
|
|
|
|
extern bool fgLoadFlight (std::istream &input);
|
2001-01-05 17:37:59 +00:00
|
|
|
|
|
|
|
|
|
|
2002-11-06 18:57:31 +00:00
|
|
|
|
/**
|
2003-01-21 02:08:00 +00:00
|
|
|
|
* Load properties from a file.
|
2002-11-06 18:57:31 +00:00
|
|
|
|
*
|
2003-01-21 02:08:00 +00:00
|
|
|
|
* @param file The relative or absolute filename.
|
|
|
|
|
* @param props The property node to load the properties into.
|
|
|
|
|
* @param in_fg_root If true, look for the file relative to
|
|
|
|
|
* $FG_ROOT; otherwise, look for the file relative to the
|
|
|
|
|
* current working directory.
|
|
|
|
|
* @return true if the properties loaded successfully, false
|
|
|
|
|
* otherwise.
|
2002-11-06 18:57:31 +00:00
|
|
|
|
*/
|
2016-06-23 13:26:34 +00:00
|
|
|
|
extern bool fgLoadProps (const std::string& path, SGPropertyNode * props,
|
2005-12-17 15:34:37 +00:00
|
|
|
|
bool in_fg_root = true, int default_mode = 0);
|
2002-11-06 18:57:31 +00:00
|
|
|
|
|
2011-12-11 12:55:56 +00:00
|
|
|
|
void setLoggingClasses (const char * c);
|
|
|
|
|
void setLoggingPriority (const char * p);
|
2002-11-06 18:57:31 +00:00
|
|
|
|
|
2001-01-13 22:06:39 +00:00
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Convenience functions for getting property values.
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
I'm attaching diffs to add a new FGInput module to FlightGear
(src/Input). So far, FGInput replaces most of src/Main/keyboard.cxx
(I've left a tiny stub); in the very near future, it will also take
over control of the joystick, mouse (Norm permitting), and panel
instrument interactions, so that there is a single mechanism for
configuring all input devices.
The new format should be (close to) self-explanatory by looking at the
new base-package file keyboard.xml, which is now included by
preferences.xml (I'll do the same thing for the joystick when I have a
chance). I have not managed to move all keybindings into this file
yet, but I've made a good start. I'm including Tony in the recipient
list so that he can see how bindings can use an external XML file.
This patch also adds support for multiple bindings for a single key,
special keys (i.e. keypad and function keys), and key modifiers
(shift/alt/ctrl); special keys use the PUI convention of adding 256 to
the Glut key code.
Unfortunately, everything comes with a price; in this case, I have not
yet found a general mechanism for the old (hard-coded) modal bindings,
which behaved differently depending on the autopilot state (i.e. left
rudder or move AP heading left); with my patches, this functionality
disappears, but you can still adjust the autopilot using the panel or
the GUI input dialogs.
2001-05-23 23:01:15 +00:00
|
|
|
|
/**
|
|
|
|
|
* Get a property node.
|
|
|
|
|
*
|
|
|
|
|
* @param path The path of the node, relative to root.
|
|
|
|
|
* @param create true to create the node if it doesn't exist.
|
2001-06-12 16:25:36 +00:00
|
|
|
|
* @return The node, or 0 if none exists and none was created.
|
I'm attaching diffs to add a new FGInput module to FlightGear
(src/Input). So far, FGInput replaces most of src/Main/keyboard.cxx
(I've left a tiny stub); in the very near future, it will also take
over control of the joystick, mouse (Norm permitting), and panel
instrument interactions, so that there is a single mechanism for
configuring all input devices.
The new format should be (close to) self-explanatory by looking at the
new base-package file keyboard.xml, which is now included by
preferences.xml (I'll do the same thing for the joystick when I have a
chance). I have not managed to move all keybindings into this file
yet, but I've made a good start. I'm including Tony in the recipient
list so that he can see how bindings can use an external XML file.
This patch also adds support for multiple bindings for a single key,
special keys (i.e. keypad and function keys), and key modifiers
(shift/alt/ctrl); special keys use the PUI convention of adding 256 to
the Glut key code.
Unfortunately, everything comes with a price; in this case, I have not
yet found a general mechanism for the old (hard-coded) modal bindings,
which behaved differently depending on the autopilot state (i.e. left
rudder or move AP heading left); with my patches, this functionality
disappears, but you can still adjust the autopilot using the panel or
the GUI input dialogs.
2001-05-23 23:01:15 +00:00
|
|
|
|
*/
|
2002-03-19 17:12:13 +00:00
|
|
|
|
extern SGPropertyNode * fgGetNode (const char * path, bool create = false);
|
I'm attaching diffs to add a new FGInput module to FlightGear
(src/Input). So far, FGInput replaces most of src/Main/keyboard.cxx
(I've left a tiny stub); in the very near future, it will also take
over control of the joystick, mouse (Norm permitting), and panel
instrument interactions, so that there is a single mechanism for
configuring all input devices.
The new format should be (close to) self-explanatory by looking at the
new base-package file keyboard.xml, which is now included by
preferences.xml (I'll do the same thing for the joystick when I have a
chance). I have not managed to move all keybindings into this file
yet, but I've made a good start. I'm including Tony in the recipient
list so that he can see how bindings can use an external XML file.
This patch also adds support for multiple bindings for a single key,
special keys (i.e. keypad and function keys), and key modifiers
(shift/alt/ctrl); special keys use the PUI convention of adding 256 to
the Glut key code.
Unfortunately, everything comes with a price; in this case, I have not
yet found a general mechanism for the old (hard-coded) modal bindings,
which behaved differently depending on the autopilot state (i.e. left
rudder or move AP heading left); with my patches, this functionality
disappears, but you can still adjust the autopilot using the panel or
the GUI input dialogs.
2001-05-23 23:01:15 +00:00
|
|
|
|
|
2011-08-27 15:19:36 +00:00
|
|
|
|
/**
|
|
|
|
|
* Get a property node.
|
|
|
|
|
*
|
|
|
|
|
* @param path The path of the node, relative to root.
|
|
|
|
|
* @param create true to create the node if it doesn't exist.
|
|
|
|
|
* @return The node, or 0 if none exists and none was created.
|
|
|
|
|
*/
|
|
|
|
|
inline SGPropertyNode * fgGetNode (const std::string & path, bool create = false)
|
|
|
|
|
{
|
|
|
|
|
return fgGetNode(path.c_str(), create );
|
|
|
|
|
}
|
|
|
|
|
|
I'm attaching diffs to add a new FGInput module to FlightGear
(src/Input). So far, FGInput replaces most of src/Main/keyboard.cxx
(I've left a tiny stub); in the very near future, it will also take
over control of the joystick, mouse (Norm permitting), and panel
instrument interactions, so that there is a single mechanism for
configuring all input devices.
The new format should be (close to) self-explanatory by looking at the
new base-package file keyboard.xml, which is now included by
preferences.xml (I'll do the same thing for the joystick when I have a
chance). I have not managed to move all keybindings into this file
yet, but I've made a good start. I'm including Tony in the recipient
list so that he can see how bindings can use an external XML file.
This patch also adds support for multiple bindings for a single key,
special keys (i.e. keypad and function keys), and key modifiers
(shift/alt/ctrl); special keys use the PUI convention of adding 256 to
the Glut key code.
Unfortunately, everything comes with a price; in this case, I have not
yet found a general mechanism for the old (hard-coded) modal bindings,
which behaved differently depending on the autopilot state (i.e. left
rudder or move AP heading left); with my patches, this functionality
disappears, but you can still adjust the autopilot using the panel or
the GUI input dialogs.
2001-05-23 23:01:15 +00:00
|
|
|
|
|
2002-01-19 05:34:03 +00:00
|
|
|
|
/**
|
|
|
|
|
* Get a property node with separate index.
|
|
|
|
|
*
|
|
|
|
|
* This method separates the index from the path string, to make it
|
|
|
|
|
* easier to iterate through multiple components without using sprintf
|
|
|
|
|
* to add indices. For example, fgGetNode("foo[1]/bar", 3) will
|
|
|
|
|
* return the same result as fgGetNode("foo[1]/bar[3]").
|
|
|
|
|
*
|
|
|
|
|
* @param path The path of the node, relative to root.
|
|
|
|
|
* @param index The index for the last member of the path (overrides
|
|
|
|
|
* any given in the string).
|
|
|
|
|
* @param create true to create the node if it doesn't exist.
|
|
|
|
|
* @return The node, or 0 if none exists and none was created.
|
|
|
|
|
*/
|
2002-03-19 17:12:13 +00:00
|
|
|
|
extern SGPropertyNode * fgGetNode (const char * path,
|
2018-04-03 10:21:33 +00:00
|
|
|
|
int index, bool create = false);
|
2002-01-19 05:34:03 +00:00
|
|
|
|
|
2011-08-27 15:19:36 +00:00
|
|
|
|
/**
|
|
|
|
|
* Get a property node with separate index.
|
|
|
|
|
*
|
|
|
|
|
* This method separates the index from the path string, to make it
|
|
|
|
|
* easier to iterate through multiple components without using sprintf
|
|
|
|
|
* to add indices. For example, fgGetNode("foo[1]/bar", 3) will
|
|
|
|
|
* return the same result as fgGetNode("foo[1]/bar[3]").
|
|
|
|
|
*
|
|
|
|
|
* @param path The path of the node, relative to root.
|
|
|
|
|
* @param index The index for the last member of the path (overrides
|
|
|
|
|
* any given in the string).
|
|
|
|
|
* @param create true to create the node if it doesn't exist.
|
|
|
|
|
* @return The node, or 0 if none exists and none was created.
|
|
|
|
|
*/
|
|
|
|
|
inline SGPropertyNode * fgGetNode (const std::string & path,
|
2018-04-03 10:21:33 +00:00
|
|
|
|
int index, bool create = false)
|
2011-08-27 15:19:36 +00:00
|
|
|
|
{
|
|
|
|
|
return fgGetNode(path.c_str(), index, create );
|
|
|
|
|
}
|
|
|
|
|
|
2002-01-19 05:34:03 +00:00
|
|
|
|
|
2001-01-13 22:06:39 +00:00
|
|
|
|
/**
|
2001-06-12 16:25:36 +00:00
|
|
|
|
* Test whether a given node exists.
|
2001-01-13 22:06:39 +00:00
|
|
|
|
*
|
2001-06-12 16:25:36 +00:00
|
|
|
|
* @param path The path of the node, relative to root.
|
|
|
|
|
* @return true if the node exists, false otherwise.
|
2001-01-13 22:06:39 +00:00
|
|
|
|
*/
|
2002-03-19 17:12:13 +00:00
|
|
|
|
extern bool fgHasNode (const char * path);
|
2001-01-13 22:06:39 +00:00
|
|
|
|
|
2011-08-27 15:19:36 +00:00
|
|
|
|
/**
|
|
|
|
|
* Test whether a given node exists.
|
|
|
|
|
*
|
|
|
|
|
* @param path The path of the node, relative to root.
|
|
|
|
|
* @return true if the node exists, false otherwise.
|
|
|
|
|
*/
|
|
|
|
|
inline bool fgHasNode (const std::string & path)
|
|
|
|
|
{
|
|
|
|
|
return fgHasNode( path.c_str() );
|
|
|
|
|
}
|
|
|
|
|
|
2001-01-13 22:06:39 +00:00
|
|
|
|
|
2002-06-18 03:27:21 +00:00
|
|
|
|
/**
|
|
|
|
|
* Add a listener to a node.
|
|
|
|
|
*
|
|
|
|
|
* @param listener The listener to add to the node.
|
|
|
|
|
* @param path The path of the node, relative to root.
|
|
|
|
|
* @param index The index for the last member of the path (overrides
|
|
|
|
|
* any given in the string).
|
|
|
|
|
*/
|
|
|
|
|
extern void fgAddChangeListener (SGPropertyChangeListener * listener,
|
2018-04-03 10:21:33 +00:00
|
|
|
|
const char * path);
|
2002-06-18 03:27:21 +00:00
|
|
|
|
|
2011-08-27 15:19:36 +00:00
|
|
|
|
/**
|
|
|
|
|
* Add a listener to a node.
|
|
|
|
|
*
|
|
|
|
|
* @param listener The listener to add to the node.
|
|
|
|
|
* @param path The path of the node, relative to root.
|
|
|
|
|
* @param index The index for the last member of the path (overrides
|
|
|
|
|
* any given in the string).
|
|
|
|
|
*/
|
|
|
|
|
inline void fgAddChangeListener (SGPropertyChangeListener * listener,
|
2018-04-03 10:21:33 +00:00
|
|
|
|
const std::string & path)
|
2011-08-27 15:19:36 +00:00
|
|
|
|
{
|
|
|
|
|
fgAddChangeListener( listener, path.c_str() );
|
|
|
|
|
}
|
|
|
|
|
|
2002-06-18 03:27:21 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add a listener to a node.
|
|
|
|
|
*
|
|
|
|
|
* @param listener The listener to add to the node.
|
|
|
|
|
* @param path The path of the node, relative to root.
|
|
|
|
|
* @param index The index for the last member of the path (overrides
|
|
|
|
|
* any given in the string).
|
|
|
|
|
*/
|
|
|
|
|
extern void fgAddChangeListener (SGPropertyChangeListener * listener,
|
2018-04-03 10:21:33 +00:00
|
|
|
|
const char * path, int index);
|
2002-06-18 03:27:21 +00:00
|
|
|
|
|
2011-08-27 15:19:36 +00:00
|
|
|
|
/**
|
|
|
|
|
* Add a listener to a node.
|
|
|
|
|
*
|
|
|
|
|
* @param listener The listener to add to the node.
|
|
|
|
|
* @param path The path of the node, relative to root.
|
|
|
|
|
* @param index The index for the last member of the path (overrides
|
|
|
|
|
* any given in the string).
|
|
|
|
|
*/
|
|
|
|
|
inline void fgAddChangeListener (SGPropertyChangeListener * listener,
|
2018-04-03 10:21:33 +00:00
|
|
|
|
const std::string & path, int index)
|
2011-08-27 15:19:36 +00:00
|
|
|
|
{
|
|
|
|
|
fgAddChangeListener( listener, path.c_str(), index );
|
|
|
|
|
}
|
|
|
|
|
|
2002-06-18 03:27:21 +00:00
|
|
|
|
|
2001-07-12 23:36:04 +00:00
|
|
|
|
/**
|
|
|
|
|
* Get a bool value for a property.
|
|
|
|
|
*
|
|
|
|
|
* This method is convenient but inefficient. It should be used
|
|
|
|
|
* infrequently (i.e. for initializing, loading, saving, etc.),
|
|
|
|
|
* not in the main loop. If you need to get a value frequently,
|
|
|
|
|
* it is better to look up the node itself using fgGetNode and then
|
|
|
|
|
* use the node's getBoolValue() method, to avoid the lookup overhead.
|
|
|
|
|
*
|
|
|
|
|
* @param name The property name.
|
|
|
|
|
* @param defaultValue The default value to return if the property
|
|
|
|
|
* does not exist.
|
|
|
|
|
* @return The property's value as a bool, or the default value provided.
|
|
|
|
|
*/
|
2002-03-19 17:12:13 +00:00
|
|
|
|
extern bool fgGetBool (const char * name, bool defaultValue = false);
|
2001-01-13 22:06:39 +00:00
|
|
|
|
|
2011-08-27 15:19:36 +00:00
|
|
|
|
/**
|
|
|
|
|
* Get a bool value for a property.
|
|
|
|
|
*
|
|
|
|
|
* This method is convenient but inefficient. It should be used
|
|
|
|
|
* infrequently (i.e. for initializing, loading, saving, etc.),
|
|
|
|
|
* not in the main loop. If you need to get a value frequently,
|
|
|
|
|
* it is better to look up the node itself using fgGetNode and then
|
|
|
|
|
* use the node's getBoolValue() method, to avoid the lookup overhead.
|
|
|
|
|
*
|
|
|
|
|
* @param name The property name.
|
|
|
|
|
* @param defaultValue The default value to return if the property
|
|
|
|
|
* does not exist.
|
|
|
|
|
* @return The property's value as a bool, or the default value provided.
|
|
|
|
|
*/
|
|
|
|
|
inline bool fgGetBool (const std::string & name, bool defaultValue = false)
|
|
|
|
|
{
|
|
|
|
|
return fgGetBool( name.c_str(), defaultValue );
|
|
|
|
|
}
|
|
|
|
|
|
2001-07-12 23:36:04 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get an int value for a property.
|
|
|
|
|
*
|
|
|
|
|
* This method is convenient but inefficient. It should be used
|
|
|
|
|
* infrequently (i.e. for initializing, loading, saving, etc.),
|
|
|
|
|
* not in the main loop. If you need to get a value frequently,
|
|
|
|
|
* it is better to look up the node itself using fgGetNode and then
|
|
|
|
|
* use the node's getIntValue() method, to avoid the lookup overhead.
|
|
|
|
|
*
|
|
|
|
|
* @param name The property name.
|
|
|
|
|
* @param defaultValue The default value to return if the property
|
|
|
|
|
* does not exist.
|
|
|
|
|
* @return The property's value as an int, or the default value provided.
|
|
|
|
|
*/
|
2002-03-19 17:12:13 +00:00
|
|
|
|
extern int fgGetInt (const char * name, int defaultValue = 0);
|
2001-01-13 22:06:39 +00:00
|
|
|
|
|
2011-08-27 15:19:36 +00:00
|
|
|
|
/**
|
|
|
|
|
* Get an int value for a property.
|
|
|
|
|
*
|
|
|
|
|
* This method is convenient but inefficient. It should be used
|
|
|
|
|
* infrequently (i.e. for initializing, loading, saving, etc.),
|
|
|
|
|
* not in the main loop. If you need to get a value frequently,
|
|
|
|
|
* it is better to look up the node itself using fgGetNode and then
|
|
|
|
|
* use the node's getIntValue() method, to avoid the lookup overhead.
|
|
|
|
|
*
|
|
|
|
|
* @param name The property name.
|
|
|
|
|
* @param defaultValue The default value to return if the property
|
|
|
|
|
* does not exist.
|
|
|
|
|
* @return The property's value as an int, or the default value provided.
|
|
|
|
|
*/
|
|
|
|
|
inline int fgGetInt (const std::string & name, int defaultValue = 0)
|
|
|
|
|
{
|
|
|
|
|
return fgGetInt( name.c_str(), defaultValue );
|
|
|
|
|
}
|
|
|
|
|
|
2001-07-12 23:36:04 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get a long value for a property.
|
|
|
|
|
*
|
|
|
|
|
* This method is convenient but inefficient. It should be used
|
|
|
|
|
* infrequently (i.e. for initializing, loading, saving, etc.),
|
|
|
|
|
* not in the main loop. If you need to get a value frequently,
|
|
|
|
|
* it is better to look up the node itself using fgGetNode and then
|
|
|
|
|
* use the node's getLongValue() method, to avoid the lookup overhead.
|
|
|
|
|
*
|
|
|
|
|
* @param name The property name.
|
|
|
|
|
* @param defaultValue The default value to return if the property
|
|
|
|
|
* does not exist.
|
|
|
|
|
* @return The property's value as a long, or the default value provided.
|
|
|
|
|
*/
|
2012-09-25 21:08:52 +00:00
|
|
|
|
extern long fgGetLong (const char * name, long defaultValue = 0L);
|
2001-03-29 03:49:02 +00:00
|
|
|
|
|
2011-08-27 15:19:36 +00:00
|
|
|
|
/**
|
|
|
|
|
* Get a long value for a property.
|
|
|
|
|
*
|
|
|
|
|
* This method is convenient but inefficient. It should be used
|
|
|
|
|
* infrequently (i.e. for initializing, loading, saving, etc.),
|
|
|
|
|
* not in the main loop. If you need to get a value frequently,
|
|
|
|
|
* it is better to look up the node itself using fgGetNode and then
|
|
|
|
|
* use the node's getLongValue() method, to avoid the lookup overhead.
|
|
|
|
|
*
|
|
|
|
|
* @param name The property name.
|
|
|
|
|
* @param defaultValue The default value to return if the property
|
|
|
|
|
* does not exist.
|
|
|
|
|
* @return The property's value as a long, or the default value provided.
|
|
|
|
|
*/
|
2012-09-25 21:08:52 +00:00
|
|
|
|
inline long fgGetLong (const std::string & name, long defaultValue = 0L)
|
2011-08-27 15:19:36 +00:00
|
|
|
|
{
|
|
|
|
|
return fgGetLong( name.c_str(), defaultValue );
|
|
|
|
|
}
|
|
|
|
|
|
2001-07-12 23:36:04 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get a float value for a property.
|
|
|
|
|
*
|
|
|
|
|
* This method is convenient but inefficient. It should be used
|
|
|
|
|
* infrequently (i.e. for initializing, loading, saving, etc.),
|
|
|
|
|
* not in the main loop. If you need to get a value frequently,
|
|
|
|
|
* it is better to look up the node itself using fgGetNode and then
|
|
|
|
|
* use the node's getFloatValue() method, to avoid the lookup overhead.
|
|
|
|
|
*
|
|
|
|
|
* @param name The property name.
|
|
|
|
|
* @param defaultValue The default value to return if the property
|
|
|
|
|
* does not exist.
|
|
|
|
|
* @return The property's value as a float, or the default value provided.
|
|
|
|
|
*/
|
2002-03-19 17:12:13 +00:00
|
|
|
|
extern float fgGetFloat (const char * name, float defaultValue = 0.0);
|
2001-01-13 22:06:39 +00:00
|
|
|
|
|
2011-08-27 15:19:36 +00:00
|
|
|
|
/**
|
|
|
|
|
* Get a float value for a property.
|
|
|
|
|
*
|
|
|
|
|
* This method is convenient but inefficient. It should be used
|
|
|
|
|
* infrequently (i.e. for initializing, loading, saving, etc.),
|
|
|
|
|
* not in the main loop. If you need to get a value frequently,
|
|
|
|
|
* it is better to look up the node itself using fgGetNode and then
|
|
|
|
|
* use the node's getFloatValue() method, to avoid the lookup overhead.
|
|
|
|
|
*
|
|
|
|
|
* @param name The property name.
|
|
|
|
|
* @param defaultValue The default value to return if the property
|
|
|
|
|
* does not exist.
|
|
|
|
|
* @return The property's value as a float, or the default value provided.
|
|
|
|
|
*/
|
|
|
|
|
inline float fgGetFloat (const std::string & name, float defaultValue = 0.0)
|
|
|
|
|
{
|
|
|
|
|
return fgGetFloat( name.c_str(), defaultValue );
|
|
|
|
|
}
|
|
|
|
|
|
2001-07-12 23:36:04 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get a double value for a property.
|
|
|
|
|
*
|
|
|
|
|
* This method is convenient but inefficient. It should be used
|
|
|
|
|
* infrequently (i.e. for initializing, loading, saving, etc.),
|
|
|
|
|
* not in the main loop. If you need to get a value frequently,
|
|
|
|
|
* it is better to look up the node itself using fgGetNode and then
|
|
|
|
|
* use the node's getDoubleValue() method, to avoid the lookup overhead.
|
|
|
|
|
*
|
|
|
|
|
* @param name The property name.
|
|
|
|
|
* @param defaultValue The default value to return if the property
|
|
|
|
|
* does not exist.
|
|
|
|
|
* @return The property's value as a double, or the default value provided.
|
|
|
|
|
*/
|
2002-03-19 17:12:13 +00:00
|
|
|
|
extern double fgGetDouble (const char * name, double defaultValue = 0.0);
|
2001-01-13 22:06:39 +00:00
|
|
|
|
|
2011-08-27 15:19:36 +00:00
|
|
|
|
/**
|
|
|
|
|
* Get a double value for a property.
|
|
|
|
|
*
|
|
|
|
|
* This method is convenient but inefficient. It should be used
|
|
|
|
|
* infrequently (i.e. for initializing, loading, saving, etc.),
|
|
|
|
|
* not in the main loop. If you need to get a value frequently,
|
|
|
|
|
* it is better to look up the node itself using fgGetNode and then
|
|
|
|
|
* use the node's getDoubleValue() method, to avoid the lookup overhead.
|
|
|
|
|
*
|
|
|
|
|
* @param name The property name.
|
|
|
|
|
* @param defaultValue The default value to return if the property
|
|
|
|
|
* does not exist.
|
|
|
|
|
* @return The property's value as a double, or the default value provided.
|
|
|
|
|
*/
|
|
|
|
|
inline double fgGetDouble (const std::string & name, double defaultValue = 0.0)
|
|
|
|
|
{
|
|
|
|
|
return fgGetDouble( name.c_str(), defaultValue );
|
|
|
|
|
}
|
|
|
|
|
|
2001-07-12 23:36:04 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get a string value for a property.
|
|
|
|
|
*
|
|
|
|
|
* This method is convenient but inefficient. It should be used
|
|
|
|
|
* infrequently (i.e. for initializing, loading, saving, etc.),
|
|
|
|
|
* not in the main loop. If you need to get a value frequently,
|
|
|
|
|
* it is better to look up the node itself using fgGetNode and then
|
|
|
|
|
* use the node's getStringValue() method, to avoid the lookup overhead.
|
|
|
|
|
*
|
|
|
|
|
* @param name The property name.
|
|
|
|
|
* @param defaultValue The default value to return if the property
|
|
|
|
|
* does not exist.
|
|
|
|
|
* @return The property's value as a string, or the default value provided.
|
|
|
|
|
*/
|
2002-03-19 17:12:13 +00:00
|
|
|
|
extern const char * fgGetString (const char * name,
|
2018-04-03 10:21:33 +00:00
|
|
|
|
const char * defaultValue = "");
|
2001-01-13 22:06:39 +00:00
|
|
|
|
|
2011-08-27 15:19:36 +00:00
|
|
|
|
/**
|
|
|
|
|
* Get a string value for a property.
|
|
|
|
|
*
|
|
|
|
|
* This method is convenient but inefficient. It should be used
|
|
|
|
|
* infrequently (i.e. for initializing, loading, saving, etc.),
|
|
|
|
|
* not in the main loop. If you need to get a value frequently,
|
|
|
|
|
* it is better to look up the node itself using fgGetNode and then
|
|
|
|
|
* use the node's getStringValue() method, to avoid the lookup overhead.
|
|
|
|
|
*
|
|
|
|
|
* @param name The property name.
|
|
|
|
|
* @param defaultValue The default value to return if the property
|
|
|
|
|
* does not exist.
|
|
|
|
|
* @return The property's value as a string, or the default value provided.
|
|
|
|
|
*/
|
|
|
|
|
inline const char * fgGetString (const std::string & name,
|
2011-10-17 16:41:59 +00:00
|
|
|
|
const std::string & defaultValue = std::string(""))
|
2011-08-27 15:19:36 +00:00
|
|
|
|
{
|
|
|
|
|
return fgGetString( name.c_str(), defaultValue.c_str() );
|
|
|
|
|
}
|
|
|
|
|
|
2001-07-12 23:36:04 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set a bool value for a property.
|
|
|
|
|
*
|
|
|
|
|
* Assign a bool value to a property. If the property does not
|
|
|
|
|
* yet exist, it will be created and its type will be set to
|
|
|
|
|
* BOOL; if it has a type of UNKNOWN, the type will also be set to
|
|
|
|
|
* BOOL; otherwise, the bool value will be converted to the property's
|
|
|
|
|
* type.
|
|
|
|
|
*
|
|
|
|
|
* @param name The property name.
|
|
|
|
|
* @param val The new value for the property.
|
|
|
|
|
* @return true if the assignment succeeded, false otherwise.
|
|
|
|
|
*/
|
2002-03-19 17:12:13 +00:00
|
|
|
|
extern bool fgSetBool (const char * name, bool val);
|
2001-01-13 22:06:39 +00:00
|
|
|
|
|
2011-08-27 15:19:36 +00:00
|
|
|
|
/**
|
|
|
|
|
* Set a bool value for a property.
|
|
|
|
|
*
|
|
|
|
|
* Assign a bool value to a property. If the property does not
|
|
|
|
|
* yet exist, it will be created and its type will be set to
|
|
|
|
|
* BOOL; if it has a type of UNKNOWN, the type will also be set to
|
|
|
|
|
* BOOL; otherwise, the bool value will be converted to the property's
|
|
|
|
|
* type.
|
|
|
|
|
*
|
|
|
|
|
* @param name The property name.
|
|
|
|
|
* @param val The new value for the property.
|
|
|
|
|
* @return true if the assignment succeeded, false otherwise.
|
|
|
|
|
*/
|
|
|
|
|
inline bool fgSetBool (const std::string & name, bool val)
|
|
|
|
|
{
|
|
|
|
|
return fgSetBool( name.c_str(), val );
|
|
|
|
|
}
|
|
|
|
|
|
2001-07-12 23:36:04 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set an int value for a property.
|
|
|
|
|
*
|
|
|
|
|
* Assign an int value to a property. If the property does not
|
|
|
|
|
* yet exist, it will be created and its type will be set to
|
|
|
|
|
* INT; if it has a type of UNKNOWN, the type will also be set to
|
|
|
|
|
* INT; otherwise, the bool value will be converted to the property's
|
|
|
|
|
* type.
|
|
|
|
|
*
|
|
|
|
|
* @param name The property name.
|
|
|
|
|
* @param val The new value for the property.
|
|
|
|
|
* @return true if the assignment succeeded, false otherwise.
|
|
|
|
|
*/
|
2002-03-19 17:12:13 +00:00
|
|
|
|
extern bool fgSetInt (const char * name, int val);
|
2001-01-13 22:06:39 +00:00
|
|
|
|
|
2011-08-27 15:19:36 +00:00
|
|
|
|
/**
|
|
|
|
|
* Set an int value for a property.
|
|
|
|
|
*
|
|
|
|
|
* Assign an int value to a property. If the property does not
|
|
|
|
|
* yet exist, it will be created and its type will be set to
|
|
|
|
|
* INT; if it has a type of UNKNOWN, the type will also be set to
|
|
|
|
|
* INT; otherwise, the bool value will be converted to the property's
|
|
|
|
|
* type.
|
|
|
|
|
*
|
|
|
|
|
* @param name The property name.
|
|
|
|
|
* @param val The new value for the property.
|
|
|
|
|
* @return true if the assignment succeeded, false otherwise.
|
|
|
|
|
*/
|
|
|
|
|
inline bool fgSetInt (const std::string & name, int val)
|
|
|
|
|
{
|
|
|
|
|
return fgSetInt( name.c_str(), val );
|
|
|
|
|
}
|
2001-07-12 23:36:04 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set a long value for a property.
|
|
|
|
|
*
|
|
|
|
|
* Assign a long value to a property. If the property does not
|
|
|
|
|
* yet exist, it will be created and its type will be set to
|
|
|
|
|
* LONG; if it has a type of UNKNOWN, the type will also be set to
|
|
|
|
|
* LONG; otherwise, the bool value will be converted to the property's
|
|
|
|
|
* type.
|
|
|
|
|
*
|
|
|
|
|
* @param name The property name.
|
|
|
|
|
* @param val The new value for the property.
|
|
|
|
|
* @return true if the assignment succeeded, false otherwise.
|
|
|
|
|
*/
|
2002-03-19 17:12:13 +00:00
|
|
|
|
extern bool fgSetLong (const char * name, long val);
|
2001-03-29 03:49:02 +00:00
|
|
|
|
|
2011-08-27 15:19:36 +00:00
|
|
|
|
/**
|
|
|
|
|
* Set a long value for a property.
|
|
|
|
|
*
|
|
|
|
|
* Assign a long value to a property. If the property does not
|
|
|
|
|
* yet exist, it will be created and its type will be set to
|
|
|
|
|
* LONG; if it has a type of UNKNOWN, the type will also be set to
|
|
|
|
|
* LONG; otherwise, the bool value will be converted to the property's
|
|
|
|
|
* type.
|
|
|
|
|
*
|
|
|
|
|
* @param name The property name.
|
|
|
|
|
* @param val The new value for the property.
|
|
|
|
|
* @return true if the assignment succeeded, false otherwise.
|
|
|
|
|
*/
|
|
|
|
|
inline bool fgSetLong (const std::string & name, long val)
|
|
|
|
|
{
|
|
|
|
|
return fgSetLong( name.c_str(), val );
|
|
|
|
|
}
|
|
|
|
|
|
2001-07-12 23:36:04 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set a float value for a property.
|
|
|
|
|
*
|
|
|
|
|
* Assign a float value to a property. If the property does not
|
|
|
|
|
* yet exist, it will be created and its type will be set to
|
|
|
|
|
* FLOAT; if it has a type of UNKNOWN, the type will also be set to
|
|
|
|
|
* FLOAT; otherwise, the bool value will be converted to the property's
|
|
|
|
|
* type.
|
|
|
|
|
*
|
|
|
|
|
* @param name The property name.
|
|
|
|
|
* @param val The new value for the property.
|
|
|
|
|
* @return true if the assignment succeeded, false otherwise.
|
|
|
|
|
*/
|
2002-03-19 17:12:13 +00:00
|
|
|
|
extern bool fgSetFloat (const char * name, float val);
|
2001-01-13 22:06:39 +00:00
|
|
|
|
|
2011-08-27 15:19:36 +00:00
|
|
|
|
/**
|
|
|
|
|
* Set a float value for a property.
|
|
|
|
|
*
|
|
|
|
|
* Assign a float value to a property. If the property does not
|
|
|
|
|
* yet exist, it will be created and its type will be set to
|
|
|
|
|
* FLOAT; if it has a type of UNKNOWN, the type will also be set to
|
|
|
|
|
* FLOAT; otherwise, the bool value will be converted to the property's
|
|
|
|
|
* type.
|
|
|
|
|
*
|
|
|
|
|
* @param name The property name.
|
|
|
|
|
* @param val The new value for the property.
|
|
|
|
|
* @return true if the assignment succeeded, false otherwise.
|
|
|
|
|
*/
|
|
|
|
|
inline bool fgSetFloat (const std::string & name, float val)
|
|
|
|
|
{
|
2011-08-31 17:54:59 +00:00
|
|
|
|
return fgSetFloat( name.c_str(), val );
|
2011-08-27 15:19:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-07-12 23:36:04 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set a double value for a property.
|
|
|
|
|
*
|
|
|
|
|
* Assign a double value to a property. If the property does not
|
|
|
|
|
* yet exist, it will be created and its type will be set to
|
|
|
|
|
* DOUBLE; if it has a type of UNKNOWN, the type will also be set to
|
|
|
|
|
* DOUBLE; otherwise, the double value will be converted to the property's
|
|
|
|
|
* type.
|
|
|
|
|
*
|
|
|
|
|
* @param name The property name.
|
|
|
|
|
* @param val The new value for the property.
|
|
|
|
|
* @return true if the assignment succeeded, false otherwise.
|
|
|
|
|
*/
|
2002-03-19 17:12:13 +00:00
|
|
|
|
extern bool fgSetDouble (const char * name, double val);
|
2001-01-13 22:06:39 +00:00
|
|
|
|
|
2011-08-27 15:19:36 +00:00
|
|
|
|
/**
|
|
|
|
|
* Set a double value for a property.
|
|
|
|
|
*
|
|
|
|
|
* Assign a double value to a property. If the property does not
|
|
|
|
|
* yet exist, it will be created and its type will be set to
|
|
|
|
|
* DOUBLE; if it has a type of UNKNOWN, the type will also be set to
|
|
|
|
|
* DOUBLE; otherwise, the double value will be converted to the property's
|
|
|
|
|
* type.
|
|
|
|
|
*
|
|
|
|
|
* @param name The property name.
|
|
|
|
|
* @param val The new value for the property.
|
|
|
|
|
* @return true if the assignment succeeded, false otherwise.
|
|
|
|
|
*/
|
|
|
|
|
inline bool fgSetDouble (const std::string & name, double val)
|
|
|
|
|
{
|
|
|
|
|
return fgSetDouble( name.c_str(), val );
|
|
|
|
|
}
|
|
|
|
|
|
2001-07-12 23:36:04 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set a string value for a property.
|
|
|
|
|
*
|
|
|
|
|
* Assign a string value to a property. If the property does not
|
|
|
|
|
* yet exist, it will be created and its type will be set to
|
|
|
|
|
* STRING; if it has a type of UNKNOWN, the type will also be set to
|
|
|
|
|
* STRING; otherwise, the string value will be converted to the property's
|
|
|
|
|
* type.
|
|
|
|
|
*
|
|
|
|
|
* @param name The property name.
|
|
|
|
|
* @param val The new value for the property.
|
|
|
|
|
* @return true if the assignment succeeded, false otherwise.
|
|
|
|
|
*/
|
2002-03-19 17:12:13 +00:00
|
|
|
|
extern bool fgSetString (const char * name, const char * val);
|
2001-01-13 22:06:39 +00:00
|
|
|
|
|
2011-08-27 15:19:36 +00:00
|
|
|
|
/**
|
|
|
|
|
* Set a string value for a property.
|
|
|
|
|
*
|
|
|
|
|
* Assign a string value to a property. If the property does not
|
|
|
|
|
* yet exist, it will be created and its type will be set to
|
|
|
|
|
* STRING; if it has a type of UNKNOWN, the type will also be set to
|
|
|
|
|
* STRING; otherwise, the string value will be converted to the property's
|
|
|
|
|
* type.
|
|
|
|
|
*
|
|
|
|
|
* @param name The property name.
|
|
|
|
|
* @param val The new value for the property.
|
|
|
|
|
* @return true if the assignment succeeded, false otherwise.
|
|
|
|
|
*/
|
|
|
|
|
inline bool fgSetString (const std::string & name, const std::string & val)
|
|
|
|
|
{
|
|
|
|
|
return fgSetString( name.c_str(), val.c_str() );
|
|
|
|
|
}
|
|
|
|
|
|
2001-01-13 22:06:39 +00:00
|
|
|
|
|
2001-07-12 23:36:04 +00:00
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Convenience functions for setting property attributes.
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set the state of the archive attribute for a property.
|
|
|
|
|
*
|
|
|
|
|
* If the archive attribute is true, the property will be written
|
|
|
|
|
* when a flight is saved; if it is false, the property will be
|
|
|
|
|
* skipped.
|
|
|
|
|
*
|
|
|
|
|
* A warning message will be printed if the property does not exist.
|
|
|
|
|
*
|
|
|
|
|
* @param name The property name.
|
|
|
|
|
* @param state The state of the archive attribute (defaults to true).
|
|
|
|
|
*/
|
2002-03-19 17:12:13 +00:00
|
|
|
|
extern void fgSetArchivable (const char * name, bool state = true);
|
2001-07-12 23:36:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set the state of the read attribute for a property.
|
|
|
|
|
*
|
|
|
|
|
* If the read attribute is true, the property value will be readable;
|
|
|
|
|
* if it is false, the property value will always be the default value
|
|
|
|
|
* for its type.
|
|
|
|
|
*
|
|
|
|
|
* A warning message will be printed if the property does not exist.
|
|
|
|
|
*
|
|
|
|
|
* @param name The property name.
|
|
|
|
|
* @param state The state of the read attribute (defaults to true).
|
|
|
|
|
*/
|
2002-03-19 17:12:13 +00:00
|
|
|
|
extern void fgSetReadable (const char * name, bool state = true);
|
2001-07-12 23:36:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set the state of the write attribute for a property.
|
|
|
|
|
*
|
|
|
|
|
* If the write attribute is true, the property value may be modified
|
|
|
|
|
* (depending on how it is tied); if the write attribute is false, the
|
|
|
|
|
* property value may not be modified.
|
|
|
|
|
*
|
|
|
|
|
* A warning message will be printed if the property does not exist.
|
|
|
|
|
*
|
|
|
|
|
* @param name The property name.
|
|
|
|
|
* @param state The state of the write attribute (defaults to true).
|
|
|
|
|
*/
|
2002-03-19 17:12:13 +00:00
|
|
|
|
extern void fgSetWritable (const char * name, bool state = true);
|
2001-07-12 23:36:04 +00:00
|
|
|
|
|
|
|
|
|
|
2001-01-05 17:37:59 +00:00
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Convenience functions for tying properties, with logging.
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2001-07-12 23:36:04 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Untie a property from an external data source.
|
|
|
|
|
*
|
|
|
|
|
* Classes should use this function to release control of any
|
|
|
|
|
* properties they are managing.
|
|
|
|
|
*/
|
2002-03-19 17:12:13 +00:00
|
|
|
|
extern void fgUntie (const char * name);
|
2001-01-05 17:37:59 +00:00
|
|
|
|
|
|
|
|
|
|
2001-07-12 23:36:04 +00:00
|
|
|
|
/**
|
|
|
|
|
* Tie a property to a pair of simple functions.
|
|
|
|
|
*
|
|
|
|
|
* Every time the property value is queried, the getter (if any) will
|
|
|
|
|
* be invoked; every time the property value is modified, the setter
|
|
|
|
|
* (if any) will be invoked. The getter can be 0 to make the property
|
|
|
|
|
* unreadable, and the setter can be 0 to make the property
|
|
|
|
|
* unmodifiable.
|
|
|
|
|
*
|
|
|
|
|
* @param name The property name to tie (full path).
|
|
|
|
|
* @param getter The getter function, or 0 if the value is unreadable.
|
|
|
|
|
* @param setter The setter function, or 0 if the value is unmodifiable.
|
2018-04-03 10:21:33 +00:00
|
|
|
|
* @param useDefault true if the setter should be invoked with any existing
|
2001-07-12 23:36:04 +00:00
|
|
|
|
* property value should be; false if the old value should be
|
|
|
|
|
* discarded; defaults to true.
|
|
|
|
|
*/
|
2001-01-05 17:37:59 +00:00
|
|
|
|
template <class V>
|
|
|
|
|
inline void
|
2002-03-19 17:12:13 +00:00
|
|
|
|
fgTie (const char * name, V (*getter)(), void (*setter)(V) = 0,
|
2001-01-19 22:57:24 +00:00
|
|
|
|
bool useDefault = true)
|
2001-01-05 17:37:59 +00:00
|
|
|
|
{
|
2001-01-19 22:57:24 +00:00
|
|
|
|
if (!globals->get_props()->tie(name, SGRawValueFunctions<V>(getter, setter),
|
2018-04-03 10:21:33 +00:00
|
|
|
|
useDefault))
|
2001-03-24 06:03:11 +00:00
|
|
|
|
SG_LOG(SG_GENERAL, SG_WARN,
|
2018-04-03 10:21:33 +00:00
|
|
|
|
"Failed to tie property " << name << " to functions");
|
2001-01-05 17:37:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-07-12 23:36:04 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Tie a property to a pair of indexed functions.
|
|
|
|
|
*
|
|
|
|
|
* Every time the property value is queried, the getter (if any) will
|
|
|
|
|
* be invoked with the index provided; every time the property value
|
|
|
|
|
* is modified, the setter (if any) will be invoked with the index
|
|
|
|
|
* provided. The getter can be 0 to make the property unreadable, and
|
|
|
|
|
* the setter can be 0 to make the property unmodifiable.
|
|
|
|
|
*
|
|
|
|
|
* @param name The property name to tie (full path).
|
|
|
|
|
* @param index The integer argument to pass to the getter and
|
|
|
|
|
* setter functions.
|
|
|
|
|
* @param getter The getter function, or 0 if the value is unreadable.
|
|
|
|
|
* @param setter The setter function, or 0 if the value is unmodifiable.
|
2018-04-03 10:21:33 +00:00
|
|
|
|
* @param useDefault true if the setter should be invoked with any existing
|
2001-07-12 23:36:04 +00:00
|
|
|
|
* property value should be; false if the old value should be
|
|
|
|
|
* discarded; defaults to true.
|
|
|
|
|
*/
|
2001-01-05 17:37:59 +00:00
|
|
|
|
template <class V>
|
|
|
|
|
inline void
|
2002-03-19 17:12:13 +00:00
|
|
|
|
fgTie (const char * name, int index, V (*getter)(int),
|
2001-01-19 22:57:24 +00:00
|
|
|
|
void (*setter)(int, V) = 0, bool useDefault = true)
|
2001-01-05 17:37:59 +00:00
|
|
|
|
{
|
|
|
|
|
if (!globals->get_props()->tie(name,
|
2018-04-03 10:21:33 +00:00
|
|
|
|
SGRawValueFunctionsIndexed<V>(index,
|
|
|
|
|
getter,
|
|
|
|
|
setter),
|
|
|
|
|
useDefault))
|
2001-03-24 06:03:11 +00:00
|
|
|
|
SG_LOG(SG_GENERAL, SG_WARN,
|
2018-04-03 10:21:33 +00:00
|
|
|
|
"Failed to tie property " << name << " to indexed functions");
|
2001-01-05 17:37:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-07-12 23:36:04 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Tie a property to a pair of object methods.
|
|
|
|
|
*
|
|
|
|
|
* Every time the property value is queried, the getter (if any) will
|
|
|
|
|
* be invoked; every time the property value is modified, the setter
|
|
|
|
|
* (if any) will be invoked. The getter can be 0 to make the property
|
|
|
|
|
* unreadable, and the setter can be 0 to make the property
|
|
|
|
|
* unmodifiable.
|
|
|
|
|
*
|
|
|
|
|
* @param name The property name to tie (full path).
|
|
|
|
|
* @param obj The object whose methods should be invoked.
|
|
|
|
|
* @param getter The object's getter method, or 0 if the value is
|
|
|
|
|
* unreadable.
|
|
|
|
|
* @param setter The object's setter method, or 0 if the value is
|
|
|
|
|
* unmodifiable.
|
2018-04-03 10:21:33 +00:00
|
|
|
|
* @param useDefault true if the setter should be invoked with any existing
|
2001-07-12 23:36:04 +00:00
|
|
|
|
* property value should be; false if the old value should be
|
|
|
|
|
* discarded; defaults to true.
|
|
|
|
|
*/
|
2001-01-05 17:37:59 +00:00
|
|
|
|
template <class T, class V>
|
|
|
|
|
inline void
|
2002-03-19 17:12:13 +00:00
|
|
|
|
fgTie (const char * name, T * obj, V (T::*getter)() const,
|
2001-01-19 22:57:24 +00:00
|
|
|
|
void (T::*setter)(V) = 0, bool useDefault = true)
|
2001-01-05 17:37:59 +00:00
|
|
|
|
{
|
|
|
|
|
if (!globals->get_props()->tie(name,
|
2018-04-03 10:21:33 +00:00
|
|
|
|
SGRawValueMethods<T,V>(*obj, getter, setter),
|
|
|
|
|
useDefault))
|
2001-03-24 06:03:11 +00:00
|
|
|
|
SG_LOG(SG_GENERAL, SG_WARN,
|
2018-04-03 10:21:33 +00:00
|
|
|
|
"Failed to tie property " << name << " to object methods");
|
2001-01-05 17:37:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-07-12 23:36:04 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Tie a property to a pair of indexed object methods.
|
|
|
|
|
*
|
|
|
|
|
* Every time the property value is queried, the getter (if any) will
|
|
|
|
|
* be invoked with the index provided; every time the property value
|
|
|
|
|
* is modified, the setter (if any) will be invoked with the index
|
|
|
|
|
* provided. The getter can be 0 to make the property unreadable, and
|
|
|
|
|
* the setter can be 0 to make the property unmodifiable.
|
|
|
|
|
*
|
|
|
|
|
* @param name The property name to tie (full path).
|
|
|
|
|
* @param obj The object whose methods should be invoked.
|
|
|
|
|
* @param index The integer argument to pass to the getter and
|
|
|
|
|
* setter methods.
|
|
|
|
|
* @param getter The getter method, or 0 if the value is unreadable.
|
|
|
|
|
* @param setter The setter method, or 0 if the value is unmodifiable.
|
2018-04-03 10:21:33 +00:00
|
|
|
|
* @param useDefault true if the setter should be invoked with any existing
|
2001-07-12 23:36:04 +00:00
|
|
|
|
* property value should be; false if the old value should be
|
|
|
|
|
* discarded; defaults to true.
|
|
|
|
|
*/
|
2001-01-05 17:37:59 +00:00
|
|
|
|
template <class T, class V>
|
2018-04-03 10:21:33 +00:00
|
|
|
|
inline void
|
2002-03-19 17:12:13 +00:00
|
|
|
|
fgTie (const char * name, T * obj, int index,
|
2001-01-19 22:57:24 +00:00
|
|
|
|
V (T::*getter)(int) const, void (T::*setter)(int, V) = 0,
|
|
|
|
|
bool useDefault = true)
|
2001-01-05 17:37:59 +00:00
|
|
|
|
{
|
|
|
|
|
if (!globals->get_props()->tie(name,
|
2018-04-03 10:21:33 +00:00
|
|
|
|
SGRawValueMethodsIndexed<T,V>(*obj,
|
|
|
|
|
index,
|
|
|
|
|
getter,
|
|
|
|
|
setter),
|
|
|
|
|
useDefault))
|
2001-03-24 06:03:11 +00:00
|
|
|
|
SG_LOG(SG_GENERAL, SG_WARN,
|
2018-04-03 10:21:33 +00:00
|
|
|
|
"Failed to tie property " << name << " to indexed object methods");
|
2001-01-05 17:37:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-03-10 11:46:03 +00:00
|
|
|
|
class FGMakeUpperCase : public SGPropertyChangeListener {
|
|
|
|
|
public:
|
|
|
|
|
void valueChanged(SGPropertyNode *node) {
|
2009-07-15 23:15:17 +00:00
|
|
|
|
if (node->getType() != simgear::props::STRING)
|
2006-03-10 11:46:03 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2007-05-07 14:06:05 +00:00
|
|
|
|
char *s = const_cast<char *>(node->getStringValue());
|
2006-03-10 11:46:03 +00:00
|
|
|
|
for (; *s; s++)
|
|
|
|
|
*s = toupper(*s);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2001-01-05 17:37:59 +00:00
|
|
|
|
#endif // __FG_PROPS_HXX
|
|
|
|
|
|