]> git.mxchange.org Git - simgear.git/blobdiff - simgear/structure/SGExpression.hxx
Fix use count for deleted, reference counted objects.
[simgear.git] / simgear / structure / SGExpression.hxx
index 440f41a2313d381dcee49ee5b819f90d05c280b6..2cfa3dc8909d629959816210282535f3be13f37c 100644 (file)
@@ -25,6 +25,8 @@
 #include <string>
 #include <vector>
 #include <functional>
+#include <set>
+#include <string>
 
 #include <simgear/props/condition.hxx>
 #include <simgear/props/props.hxx>
@@ -136,6 +138,8 @@ public:
   {
     return simgear::expression::TypeTraits<T>::typeTag;
   }
+  virtual void collectDependentProperties(std::set<const SGPropertyNode*>& props) const
+  { }
 };
 
 /// Constant value expression
@@ -184,7 +188,9 @@ public:
     _expression = _expression->simplify();
     return SGExpression<T>::simplify();
   }
-
+  
+  virtual void collectDependentProperties(std::set<const SGPropertyNode*>& props) const
+    { _expression->collectDependentProperties(props); }  
 protected:
   SGUnaryExpression(SGExpression<T>* expression = 0)
   { setOperand(expression); }
@@ -218,6 +224,12 @@ public:
     return SGExpression<T>::simplify();
   }
 
+  virtual void collectDependentProperties(std::set<const SGPropertyNode*>& props) const
+  {
+    _expressions[0]->collectDependentProperties(props);
+    _expressions[1]->collectDependentProperties(props); 
+  } 
+  
 protected:
   SGBinaryExpression(SGExpression<T>* expr0, SGExpression<T>* expr1)
   { setOperand(0, expr0); setOperand(1, expr1); }
@@ -266,6 +278,11 @@ public:
     return SGExpression<T>::simplify();
   }
 
+  virtual void collectDependentProperties(std::set<const SGPropertyNode*>& props) const
+  {
+    for (size_t i = 0; i < _expressions.size(); ++i)
+      _expressions[i]->collectDependentProperties(props);
+  } 
 protected:
   SGNaryExpression()
   { }
@@ -288,6 +305,9 @@ public:
   { _prop = prop; }
   virtual void eval(T& value, const simgear::expression::Binding*) const
   { doEval(value); }
+  
+  virtual void collectDependentProperties(std::set<const SGPropertyNode*>& props) const
+    { props.insert(_prop.get()); }
 private:
   void doEval(float& value) const
   { if (_prop) value = _prop->getFloatValue(); }
@@ -713,6 +733,12 @@ public:
       return getOperand()->simplify();
     return SGUnaryExpression<T>::simplify();
   }
+  
+  virtual void collectDependentProperties(std::set<const SGPropertyNode*>& props) const
+  {
+    SGUnaryExpression<T>::collectDependentProperties(props);
+    _enable->collectDependentProperties(props);
+  }
 
   using SGUnaryExpression<T>::getOperand;
 private:
@@ -875,6 +901,11 @@ typedef SGExpression<float> SGExpressionf;
 typedef SGExpression<double> SGExpressiond;
 typedef SGExpression<bool> SGExpressionb;
 
+typedef SGSharedPtr<SGExpressioni> SGExpressioni_ref;
+typedef SGSharedPtr<SGExpressionf> SGExpressionf_ref;
+typedef SGSharedPtr<SGExpressiond> SGExpressiond_ref;
+typedef SGSharedPtr<SGExpressionb> SGExpressionb_ref;
+
 /**
  * Global function to make an expression out of properties.
 
@@ -919,7 +950,7 @@ namespace simgear
   {
   struct ParseError : public sg_exception
   {
-      ParseError(const string& message = std::string())
+      ParseError(const std::string& message = std::string())
           : sg_exception(message) {}
   };
     
@@ -983,8 +1014,8 @@ namespace simgear
   class BindingLayout
   {
   public:
-      int addBinding(const std::string& name, expression::Type type);
-      bool findBinding(const string& name, VariableBinding& result) const;
+      size_t addBinding(const std::string& name, expression::Type type);
+      bool findBinding(const std::string& name, VariableBinding& result) const;
       std::vector<VariableBinding> bindings;
   };
 
@@ -1001,7 +1032,7 @@ namespace simgear
           ParserMap& map = getParserMap();
           ParserMap::iterator itr = map.find(exp->getName());
           if (itr == map.end())
-              throw ParseError(string("unknown expression ") + exp->getName());
+              throw ParseError(std::string("unknown expression ") + exp->getName());
           exp_parser parser = itr->second;
           return (*parser)(exp, this);
       }