]> git.mxchange.org Git - simgear.git/blobdiff - simgear/props/condition.cxx
Fix missing include in simgear/misc/strutils_test.cxx
[simgear.git] / simgear / props / condition.cxx
index 363b9f465f1aa6a2a1ce8bbf768f331f265871e7..1da575a4dbfe3c51623f59fc8633f5ed627ac373 100644 (file)
 #include "props.hxx"
 #include "condition.hxx"
 
-#include <simgear/math/SGMath.hxx>
 #include <simgear/structure/SGExpression.hxx>
 
 using std::istream;
 using std::ostream;
-\f
+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<const SGPropertyNode*>& 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<const SGPropertyNode*>& props) const;
 private:
-  SGSharedPtr<SGCondition> _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<const SGPropertyNode*>& props) const;
 private:
-  std::vector<SGSharedPtr<SGCondition> > _conditions;
+  std::vector<SGConditionRef> _conditions;
 };
 
 
@@ -103,8 +107,9 @@ public:
   virtual bool test () const;
                                // transfer pointer ownership
   virtual void addCondition (SGCondition * condition);
+  virtual void collectDependentProperties(std::set<const SGPropertyNode*>& props) const;
 private:
-  std::vector<SGSharedPtr<SGCondition> > _conditions;
+  std::vector<SGConditionRef> _conditions;
 };
 
 
@@ -137,6 +142,7 @@ public:
   void setRightDExpression(SGExpressiond* dexp);
   void setPrecisionDExpression(SGExpressiond* dexp);
   
+  virtual void collectDependentProperties(std::set<const SGPropertyNode*>& props) const;
 private:
   Type _type;
   bool _reverse;
@@ -163,7 +169,6 @@ SGCondition::~SGCondition ()
 }
 
 
-\f
 ////////////////////////////////////////////////////////////////////////
 // Implementation of SGPropertyCondition.
 ////////////////////////////////////////////////////////////////////////
@@ -179,7 +184,6 @@ SGPropertyCondition::~SGPropertyCondition ()
 }
 
 
-\f
 ////////////////////////////////////////////////////////////////////////
 // Implementation of SGNotCondition.
 ////////////////////////////////////////////////////////////////////////
@@ -199,8 +203,12 @@ SGNotCondition::test () const
   return !(_condition->test());
 }
 
+void
+SGNotCondition::collectDependentProperties(std::set<const SGPropertyNode*>& props) const
+{
+    _condition->collectDependentProperties(props);
+}
 
-\f
 ////////////////////////////////////////////////////////////////////////
 // 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<const SGPropertyNode*>& props) const
+{
+  for( size_t i = 0; i < _conditions.size(); i++ )
+    _conditions[i]->collectDependentProperties(props);
+}
+
 
-\f
 ////////////////////////////////////////////////////////////////////////
 // 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<const SGPropertyNode*>& props) const
+{
+  for( size_t i = 0; i < _conditions.size(); i++ )
+    _conditions[i]->collectDependentProperties(props);
+}
+
 
-\f
 ////////////////////////////////////////////////////////////////////////
 // Implementation of SGComparisonCondition.
 ////////////////////////////////////////////////////////////////////////
@@ -428,7 +448,28 @@ SGComparisonCondition::setPrecisionDExpression(SGExpressiond* dexp)
 {
   _precision_property = new SGPropertyNode();
   _precision_dexp = dexp;
-}\f
+}
+
+void
+SGComparisonCondition::collectDependentProperties(std::set<const SGPropertyNode*>& 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 )
 }
 
 
-\f
 ////////////////////////////////////////////////////////////////////////
 // Implementation of SGConditional.
 ////////////////////////////////////////////////////////////////////////
@@ -611,7 +651,6 @@ SGConditional::test () const
 }
 
 
-\f
 // The top-level is always an implicit 'and' group
 SGCondition *
 sgReadCondition( SGPropertyNode *prop_root, const SGPropertyNode *node )