X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FMain%2Ffg_props.hxx;h=023d4dbbff4c1f42db65f3f935b5e01c832c7b0b;hb=a704a6208131cad4f12123a72acdb1fb3dc6658f;hp=41772ff358345d94f66eeab7b8f9563e9f26d7ae;hpb=0cdb9d4efb249dd85b7e56d1885d8183de231373;p=flightgear.git diff --git a/src/Main/fg_props.hxx b/src/Main/fg_props.hxx index 41772ff35..023d4dbbf 100644 --- a/src/Main/fg_props.hxx +++ b/src/Main/fg_props.hxx @@ -9,7 +9,7 @@ #include #include -#include +#include #include
@@ -27,6 +27,9 @@ public: void bind (); void unbind (); void update (double dt); + +private: + simgear::TiedPropertyList _tiedProperties; }; @@ -70,6 +73,8 @@ extern bool fgLoadFlight (std::istream &input); extern bool fgLoadProps (const char * path, SGPropertyNode * props, bool in_fg_root = true, int default_mode = 0); +void setLoggingClasses (const char * c); +void setLoggingPriority (const char * p); //////////////////////////////////////////////////////////////////////// @@ -85,6 +90,18 @@ extern bool fgLoadProps (const char * path, SGPropertyNode * props, */ extern SGPropertyNode * fgGetNode (const char * path, bool create = false); +/** + * 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 ); +} + /** * Get a property node with separate index. @@ -103,6 +120,26 @@ extern SGPropertyNode * fgGetNode (const char * path, bool create = false); extern SGPropertyNode * fgGetNode (const char * path, int index, bool create = false); +/** + * 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, + int index, bool create = false) +{ + return fgGetNode(path.c_str(), index, create ); +} + /** * Test whether a given node exists. @@ -112,6 +149,17 @@ extern SGPropertyNode * fgGetNode (const char * path, */ extern bool fgHasNode (const char * path); +/** + * 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() ); +} + /** * Add a listener to a node. @@ -124,6 +172,20 @@ extern bool fgHasNode (const char * path); extern void fgAddChangeListener (SGPropertyChangeListener * listener, const char * path); +/** + * 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, + const std::string & path) +{ + fgAddChangeListener( listener, path.c_str() ); +} + /** * Add a listener to a node. @@ -136,6 +198,20 @@ extern void fgAddChangeListener (SGPropertyChangeListener * listener, extern void fgAddChangeListener (SGPropertyChangeListener * listener, const char * path, int index); +/** + * 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, + const std::string & path, int index) +{ + fgAddChangeListener( listener, path.c_str(), index ); +} + /** * Get a bool value for a property. @@ -153,6 +229,25 @@ extern void fgAddChangeListener (SGPropertyChangeListener * listener, */ extern bool fgGetBool (const char * name, bool defaultValue = false); +/** + * 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 ); +} + /** * Get an int value for a property. @@ -170,6 +265,41 @@ extern bool fgGetBool (const char * name, bool defaultValue = false); */ extern int fgGetInt (const char * name, int defaultValue = 0); +/** + * 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 ); +} + + +/** + * 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. + */ +extern long fgGetLong (const char * name, long defaultValue = 0L); /** * Get a long value for a property. @@ -185,7 +315,10 @@ extern int fgGetInt (const char * name, int defaultValue = 0); * does not exist. * @return The property's value as a long, or the default value provided. */ -extern int fgGetLong (const char * name, long defaultValue = 0L); +inline long fgGetLong (const std::string & name, long defaultValue = 0L) +{ + return fgGetLong( name.c_str(), defaultValue ); +} /** @@ -204,6 +337,25 @@ extern int fgGetLong (const char * name, long defaultValue = 0L); */ extern float fgGetFloat (const char * name, float defaultValue = 0.0); +/** + * 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 ); +} + /** * Get a double value for a property. @@ -221,6 +373,25 @@ extern float fgGetFloat (const char * name, float defaultValue = 0.0); */ extern double fgGetDouble (const char * name, double defaultValue = 0.0); +/** + * 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 ); +} + /** * Get a string value for a property. @@ -239,6 +410,26 @@ extern double fgGetDouble (const char * name, double defaultValue = 0.0); extern const char * fgGetString (const char * name, const char * defaultValue = ""); +/** + * 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, + const std::string & defaultValue = std::string("")) +{ + return fgGetString( name.c_str(), defaultValue.c_str() ); +} + /** * Set a bool value for a property. @@ -255,6 +446,24 @@ extern const char * fgGetString (const char * name, */ extern bool fgSetBool (const char * name, bool val); +/** + * 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 ); +} + /** * Set an int value for a property. @@ -271,6 +480,23 @@ extern bool fgSetBool (const char * name, bool val); */ extern bool fgSetInt (const char * name, int val); +/** + * 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 ); +} /** * Set a long value for a property. @@ -287,6 +513,24 @@ extern bool fgSetInt (const char * name, int val); */ extern bool fgSetLong (const char * name, long val); +/** + * 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 ); +} + /** * Set a float value for a property. @@ -303,6 +547,24 @@ extern bool fgSetLong (const char * name, long val); */ extern bool fgSetFloat (const char * name, float val); +/** + * 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) +{ + return fgSetFloat( name.c_str(), val ); +} + /** * Set a double value for a property. @@ -319,6 +581,24 @@ extern bool fgSetFloat (const char * name, float val); */ extern bool fgSetDouble (const char * name, double val); +/** + * 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 ); +} + /** * Set a string value for a property. @@ -335,6 +615,24 @@ extern bool fgSetDouble (const char * name, double val); */ extern bool fgSetString (const char * name, const char * val); +/** + * 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() ); +} + ////////////////////////////////////////////////////////////////////////