X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fprops%2Fcondition.cxx;h=1da575a4dbfe3c51623f59fc8633f5ed627ac373;hb=6672a1212cfccb2a08be21ff5271eae9b6f91b2a;hp=3770049aabfbdacae57273f0c8cb87db08e27de9;hpb=cc37713a66345ce3e88d66dbc12a4b6b677134ad;p=simgear.git diff --git a/simgear/props/condition.cxx b/simgear/props/condition.cxx index 3770049a..1da575a4 100644 --- a/simgear/props/condition.cxx +++ b/simgear/props/condition.cxx @@ -22,7 +22,8 @@ using std::istream; using std::ostream; - +using std::string; + /** * Condition for a single property. * @@ -36,6 +37,8 @@ public: const char * propname ); virtual ~SGPropertyCondition (); virtual bool test () const { return _node->getBoolValue(); } + virtual void collectDependentProperties(std::set& props) const + { props.insert(_node.get()); } private: SGConstPropertyNode_ptr _node; }; @@ -64,8 +67,9 @@ public: SGNotCondition (SGCondition * condition); virtual ~SGNotCondition (); virtual bool test () const; + virtual void collectDependentProperties(std::set& props) const; private: - SGSharedPtr _condition; + SGConditionRef _condition; }; @@ -83,8 +87,9 @@ public: virtual bool test () const; // transfer pointer ownership virtual void addCondition (SGCondition * condition); + virtual void collectDependentProperties(std::set& props) const; private: - std::vector > _conditions; + std::vector _conditions; }; @@ -102,8 +107,9 @@ public: virtual bool test () const; // transfer pointer ownership virtual void addCondition (SGCondition * condition); + virtual void collectDependentProperties(std::set& props) const; private: - std::vector > _conditions; + std::vector _conditions; }; @@ -136,6 +142,7 @@ public: void setRightDExpression(SGExpressiond* dexp); void setPrecisionDExpression(SGExpressiond* dexp); + virtual void collectDependentProperties(std::set& props) const; private: Type _type; bool _reverse; @@ -162,7 +169,6 @@ SGCondition::~SGCondition () } - //////////////////////////////////////////////////////////////////////// // Implementation of SGPropertyCondition. //////////////////////////////////////////////////////////////////////// @@ -178,7 +184,6 @@ SGPropertyCondition::~SGPropertyCondition () } - //////////////////////////////////////////////////////////////////////// // Implementation of SGNotCondition. //////////////////////////////////////////////////////////////////////// @@ -198,8 +203,12 @@ SGNotCondition::test () const return !(_condition->test()); } +void +SGNotCondition::collectDependentProperties(std::set& props) const +{ + _condition->collectDependentProperties(props); +} - //////////////////////////////////////////////////////////////////////// // Implementation of SGAndCondition. //////////////////////////////////////////////////////////////////////// @@ -215,8 +224,8 @@ SGAndCondition::~SGAndCondition () bool SGAndCondition::test () const { - int nConditions = _conditions.size(); - for (int i = 0; i < nConditions; i++) { + for( size_t i = 0; i < _conditions.size(); i++ ) + { if (!_conditions[i]->test()) return false; } @@ -229,8 +238,14 @@ SGAndCondition::addCondition (SGCondition * condition) _conditions.push_back(condition); } +void +SGAndCondition::collectDependentProperties(std::set& props) const +{ + for( size_t i = 0; i < _conditions.size(); i++ ) + _conditions[i]->collectDependentProperties(props); +} + - //////////////////////////////////////////////////////////////////////// // Implementation of SGOrCondition. //////////////////////////////////////////////////////////////////////// @@ -246,8 +261,8 @@ SGOrCondition::~SGOrCondition () bool SGOrCondition::test () const { - int nConditions = _conditions.size(); - for (int i = 0; i < nConditions; i++) { + for( size_t i = 0; i < _conditions.size(); i++ ) + { if (_conditions[i]->test()) return true; } @@ -260,8 +275,14 @@ SGOrCondition::addCondition (SGCondition * condition) _conditions.push_back(condition); } +void +SGOrCondition::collectDependentProperties(std::set& props) const +{ + for( size_t i = 0; i < _conditions.size(); i++ ) + _conditions[i]->collectDependentProperties(props); +} + - //////////////////////////////////////////////////////////////////////// // Implementation of SGComparisonCondition. //////////////////////////////////////////////////////////////////////// @@ -427,7 +448,28 @@ SGComparisonCondition::setPrecisionDExpression(SGExpressiond* dexp) { _precision_property = new SGPropertyNode(); _precision_dexp = dexp; -} +} + +void +SGComparisonCondition::collectDependentProperties(std::set& props) const +{ + if (_left_dexp) + _left_dexp->collectDependentProperties(props); + else + props.insert(_left_property); + + if (_right_dexp) + _right_dexp->collectDependentProperties(props); + else + props.insert(_right_property); + + if (_precision_dexp) + _precision_dexp->collectDependentProperties(props); + else if (_precision_property) + props.insert(_precision_property); + +} + //////////////////////////////////////////////////////////////////////// // Read a condition and use it if necessary. //////////////////////////////////////////////////////////////////////// @@ -583,7 +625,6 @@ readCondition( SGPropertyNode *prop_root, const SGPropertyNode *node ) } - //////////////////////////////////////////////////////////////////////// // Implementation of SGConditional. //////////////////////////////////////////////////////////////////////// @@ -610,7 +651,6 @@ SGConditional::test () const } - // The top-level is always an implicit 'and' group SGCondition * sgReadCondition( SGPropertyNode *prop_root, const SGPropertyNode *node )