X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fprops%2Fcondition.cxx;h=1da575a4dbfe3c51623f59fc8633f5ed627ac373;hb=6672a1212cfccb2a08be21ff5271eae9b6f91b2a;hp=363b9f465f1aa6a2a1ce8bbf768f331f265871e7;hpb=6e662fe4d6d26732244aa6631bc0bef5d484962f;p=simgear.git diff --git a/simgear/props/condition.cxx b/simgear/props/condition.cxx index 363b9f46..1da575a4 100644 --- a/simgear/props/condition.cxx +++ b/simgear/props/condition.cxx @@ -18,12 +18,12 @@ #include "props.hxx" #include "condition.hxx" -#include #include using std::istream; using std::ostream; - +using std::string; + /** * Condition for a single property. * @@ -37,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; }; @@ -65,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; }; @@ -84,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; }; @@ -103,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; }; @@ -137,6 +142,7 @@ public: void setRightDExpression(SGExpressiond* dexp); void setPrecisionDExpression(SGExpressiond* dexp); + virtual void collectDependentProperties(std::set& props) const; private: Type _type; bool _reverse; @@ -163,7 +169,6 @@ SGCondition::~SGCondition () } - //////////////////////////////////////////////////////////////////////// // Implementation of SGPropertyCondition. //////////////////////////////////////////////////////////////////////// @@ -179,7 +184,6 @@ SGPropertyCondition::~SGPropertyCondition () } - //////////////////////////////////////////////////////////////////////// // Implementation of SGNotCondition. //////////////////////////////////////////////////////////////////////// @@ -199,8 +203,12 @@ SGNotCondition::test () const return !(_condition->test()); } +void +SGNotCondition::collectDependentProperties(std::set& props) const +{ + _condition->collectDependentProperties(props); +} - //////////////////////////////////////////////////////////////////////// // Implementation of SGAndCondition. //////////////////////////////////////////////////////////////////////// @@ -216,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; } @@ -230,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. //////////////////////////////////////////////////////////////////////// @@ -247,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; } @@ -261,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. //////////////////////////////////////////////////////////////////////// @@ -428,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. //////////////////////////////////////////////////////////////////////// @@ -584,7 +625,6 @@ readCondition( SGPropertyNode *prop_root, const SGPropertyNode *node ) } - //////////////////////////////////////////////////////////////////////// // Implementation of SGConditional. //////////////////////////////////////////////////////////////////////// @@ -611,7 +651,6 @@ SGConditional::test () const } - // The top-level is always an implicit 'and' group SGCondition * sgReadCondition( SGPropertyNode *prop_root, const SGPropertyNode *node )