X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FMain%2Ffg_props.hxx;h=41772ff358345d94f66eeab7b8f9563e9f26d7ae;hb=6eadcb8dfcd6f925dac73cb5a023e5bb73921b47;hp=6e62ffe7dc26c9f7c909cfc7ad604b8fdbeef2c9;hpb=0cc3bed841c8b75d6fe48705a3589a8bb500c609;p=flightgear.git diff --git a/src/Main/fg_props.hxx b/src/Main/fg_props.hxx index 6e62ffe7d..41772ff35 100644 --- a/src/Main/fg_props.hxx +++ b/src/Main/fg_props.hxx @@ -6,36 +6,28 @@ #ifndef __FG_PROPS_HXX #define __FG_PROPS_HXX 1 -#include -#include -#include +#include -#include "globals.hxx" +#include +#include + +#include
- //////////////////////////////////////////////////////////////////////// // Property management. //////////////////////////////////////////////////////////////////////// +class FGProperties : public SGSubsystem +{ +public: + FGProperties (); + virtual ~FGProperties (); -/** - * Initialize the default FlightGear properties. - * - * These are mostly properties that haven't been claimed by a - * specific module yet. This function should be invoked once, - * while the program is starting (and after the global property - * tree has been created). - */ -extern void fgInitProps (); // fixme: how are they untied? - - -/** - * Update the default FlightGear properties. - * - * This function should be invoked once in each loop to update all - * of the default properties. - */ -extern void fgUpdateProps (); + void init (); + void bind (); + void unbind (); + void update (double dt); +}; /** @@ -49,7 +41,7 @@ extern void fgUpdateProps (); * just the ones flagged as archivable. * @return true if the flight was saved successfully. */ -extern bool fgSaveFlight (ostream &output, bool write_all = false); +extern bool fgSaveFlight (std::ostream &output, bool write_all = false); /** @@ -61,7 +53,22 @@ extern bool fgSaveFlight (ostream &output, bool write_all = false); * @param input The input stream to read the XML from. * @return true if the flight was restored successfully. */ -extern bool fgLoadFlight (istream &input); +extern bool fgLoadFlight (std::istream &input); + + +/** + * Load properties from a file. + * + * @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. + */ +extern bool fgLoadProps (const char * path, SGPropertyNode * props, + bool in_fg_root = true, int default_mode = 0); @@ -106,6 +113,30 @@ extern SGPropertyNode * fgGetNode (const char * path, extern bool fgHasNode (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). + */ +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). + */ +extern void fgAddChangeListener (SGPropertyChangeListener * listener, + const char * path, int index); + + /** * Get a bool value for a property. * @@ -500,162 +531,18 @@ fgTie (const char * name, T * obj, int index, } - -//////////////////////////////////////////////////////////////////////// -// Conditions. -//////////////////////////////////////////////////////////////////////// - - -/** - * An encoded condition. - * - * This class encodes a single condition of some sort, possibly - * connected with properties. - * - * This class should migrate to somewhere more general. - */ -class FGCondition -{ +class FGMakeUpperCase : public SGPropertyChangeListener { public: - FGCondition (); - virtual ~FGCondition (); - virtual bool test () const = 0; + void valueChanged(SGPropertyNode *node) { + if (node->getType() != simgear::props::STRING) + return; + + char *s = const_cast(node->getStringValue()); + for (; *s; s++) + *s = toupper(*s); + } }; -/** - * Condition for a single property. - * - * This condition is true only if the property returns a boolean - * true value. - */ -class FGPropertyCondition : public FGCondition -{ -public: - FGPropertyCondition (const char * propname); - virtual ~FGPropertyCondition (); - virtual bool test () const { return _node->getBoolValue(); } -private: - const SGPropertyNode * _node; -}; - - -/** - * Condition for a 'not' operator. - * - * This condition is true only if the child condition is false. - */ -class FGNotCondition : public FGCondition -{ -public: - // transfer pointer ownership - FGNotCondition (FGCondition * condition); - virtual ~FGNotCondition (); - virtual bool test () const; -private: - FGCondition * _condition; -}; - - -/** - * Condition for an 'and' group. - * - * This condition is true only if all of the conditions - * in the group are true. - */ -class FGAndCondition : public FGCondition -{ -public: - FGAndCondition (); - virtual ~FGAndCondition (); - virtual bool test () const; - // transfer pointer ownership - virtual void addCondition (FGCondition * condition); -private: - vector _conditions; -}; - - -/** - * Condition for an 'or' group. - * - * This condition is true if at least one of the conditions in the - * group is true. - */ -class FGOrCondition : public FGCondition -{ -public: - FGOrCondition (); - virtual ~FGOrCondition (); - virtual bool test () const; - // transfer pointer ownership - virtual void addCondition (FGCondition * condition); -private: - vector _conditions; -}; - - -/** - * Abstract base class for property comparison conditions. - */ -class FGComparisonCondition : public FGCondition -{ -public: - enum Type { - LESS_THAN, - GREATER_THAN, - EQUALS - }; - FGComparisonCondition (Type type, bool reverse = false); - virtual ~FGComparisonCondition (); - virtual bool test () const; - virtual void setLeftProperty (const char * propname); - virtual void setRightProperty (const char * propname); - // will make a local copy - virtual void setRightValue (const SGPropertyNode * value); -private: - Type _type; - bool _reverse; - const SGPropertyNode * _left_property; - const SGPropertyNode * _right_property; - const SGPropertyNode * _right_value; -}; - - -/** - * Base class for a conditional components. - * - * This class manages the conditions and tests; the component should - * invoke the test() method whenever it needs to decide whether to - * active itself, draw itself, and so on. - */ -class FGConditional -{ -public: - FGConditional (); - virtual ~FGConditional (); - // transfer pointer ownership - virtual void setCondition (FGCondition * condition); - virtual const FGCondition * getCondition () const { return _condition; } - virtual bool test () const; -private: - FGCondition * _condition; -}; - - -/** - * Global function to make a condition out of properties. - * - * The top-level is always an implicit 'and' group, whatever the - * node's name (it should usually be "condition"). - * - * @param node The top-level condition node (usually named "condition"). - * @return A pointer to a newly-allocated condition; it is the - * responsibility of the caller to delete the condition when - * it is no longer needed. - */ -FGCondition * fgReadCondition (const SGPropertyNode * node); - - #endif // __FG_PROPS_HXX