[Kst] branches/kst/1.3/kst/src/libkstmath

Adam Treat treat at kde.org
Sat Oct 7 00:25:19 CEST 2006


SVN commit 593148 by treat:

*Backport for commit #593145


 M  +18 -9     enodes.cpp  
 M  +5 -5      enodes.h  
 M  +10 -7     kstequation.cpp  


--- branches/kst/1.3/kst/src/libkstmath/enodes.cpp #593147:593148
@@ -93,7 +93,8 @@
 }
 
 
-void Node::collectObjects(KstVectorMap&, KstScalarMap&, KstStringMap&) {
+bool Node::collectObjects(KstVectorMap&, KstScalarMap&, KstStringMap&) {
+  return true;
 }
 
 
@@ -128,9 +129,11 @@
 }
 
 
-void BinaryNode::collectObjects(KstVectorMap& v, KstScalarMap& s, KstStringMap& t) {
-  _left->collectObjects(v, s, t);
-  _right->collectObjects(v, s, t);
+bool BinaryNode::collectObjects(KstVectorMap& v, KstScalarMap& s, KstStringMap& t) {
+  bool ok = true;
+  ok = _left->collectObjects(v, s, t) ? ok : false;
+  ok = _right->collectObjects(v, s, t) ? ok : false;
+  return ok;
 }
 
 
@@ -600,8 +603,8 @@
 }
 
 
-void Function::collectObjects(KstVectorMap& v, KstScalarMap& s, KstStringMap& t) {
-  _args->collectObjects(v, s, t);
+bool Function::collectObjects(KstVectorMap& v, KstScalarMap& s, KstStringMap& t) {
+  return _args->collectObjects(v, s, t);
 }
 
 
@@ -651,10 +654,12 @@
 }
 
 
-void ArgumentList::collectObjects(KstVectorMap& v, KstScalarMap& s, KstStringMap& t) {
+bool ArgumentList::collectObjects(KstVectorMap& v, KstScalarMap& s, KstStringMap& t) {
+  bool ok = true;
   for (Node *i = _args.first(); i; i = _args.next()) {
-    i->collectObjects(v, s, t);
+    ok = i->collectObjects(v, s, t) ? ok : false;
   }
+  return ok;
 }
 
 
@@ -853,7 +858,7 @@
 }
 
 
-void Data::collectObjects(KstVectorMap& v, KstScalarMap& s, KstStringMap& t) {
+bool Data::collectObjects(KstVectorMap& v, KstScalarMap& s, KstStringMap& t) {
   if (_isEquation) {
     if (_equation) {
       _equation->collectObjects(v, s, t);
@@ -862,7 +867,11 @@
     v.insert(_tagName, _vector);
   } else if (_scalar && !s.contains(_tagName)) {
     s.insert(_tagName, _scalar);
+  } else {
+    KstDebug::self()->log(i18n("Equation has unknown object [%1].").arg(_tagName), KstDebug::Error);
+    return false;
   }
+  return true;
 }
 
 
--- branches/kst/1.3/kst/src/libkstmath/enodes.h #593147:593148
@@ -57,7 +57,7 @@
       virtual ~Node();
 
       virtual bool isConst() = 0; // can't be const
-      virtual void collectObjects(KstVectorMap& v, KstScalarMap& s, KstStringMap& t);
+      virtual bool collectObjects(KstVectorMap& v, KstScalarMap& s, KstStringMap& t);
       virtual bool takeVectors(const KstVectorMap& c);
       virtual double value(Context*) = 0;
       virtual void visit(NodeVisitor*);
@@ -75,7 +75,7 @@
       BinaryNode(Node *left, Node *right);
       virtual ~BinaryNode();
 
-      virtual void collectObjects(KstVectorMap& v, KstScalarMap& s, KstStringMap& t);
+      virtual bool collectObjects(KstVectorMap& v, KstScalarMap& s, KstStringMap& t);
       virtual bool takeVectors(const KstVectorMap& c);
       virtual void visit(NodeVisitor*);
       virtual KstObject::UpdateType update(int counter, Context *ctx);
@@ -102,7 +102,7 @@
       double value(Context*) { return 0.0; }
 
       bool isConst();
-      void collectObjects(KstVectorMap& v, KstScalarMap& s, KstStringMap& t);
+      bool collectObjects(KstVectorMap& v, KstScalarMap& s, KstStringMap& t);
       bool takeVectors(const KstVectorMap& c);
       double at(int, Context*);
       Node *node(int idx);
@@ -124,7 +124,7 @@
       bool isPlugin() const;
       bool isConst();
       double value(Context*);
-      void collectObjects(KstVectorMap& v, KstScalarMap& s, KstStringMap& t);
+      bool collectObjects(KstVectorMap& v, KstScalarMap& s, KstStringMap& t);
       bool takeVectors(const KstVectorMap& c);
       KstObject::UpdateType update(int counter, Context *ctx);
       QString text() const;
@@ -186,7 +186,7 @@
 
       bool isConst();
       double value(Context*);
-      void collectObjects(KstVectorMap& v, KstScalarMap& s, KstStringMap& t);
+      bool collectObjects(KstVectorMap& v, KstScalarMap& s, KstStringMap& t);
       bool takeVectors(const KstVectorMap& c);
       KstObject::UpdateType update(int counter, Context *ctx);
       QString text() const;
--- branches/kst/1.3/kst/src/libkstmath/kstequation.cpp #593147:593148
@@ -268,9 +268,6 @@
   setDirty();
   _equation = in_fn;
   VectorsUsed.clear();
-  for (KstScalarMap::Iterator i = _inputScalars.begin(); i != _inputScalars.end(); ++i) {
-    (*i)->unlock();
-  }
   _inputScalars.clear();
   _ns = 2; // reset the updating
   delete _pe;
@@ -288,17 +285,23 @@
       ctx.xVector = *_xInVector;
       Equation::FoldVisitor vis(&ctx, &_pe);
       KstStringMap sm;
-      _pe->collectObjects(VectorsUsed, _inputScalars, sm);
-      for (KstScalarMap::Iterator i = _inputScalars.begin(); i != _inputScalars.end(); ++i) {
-        (*i)->readLock();
+      if (_pe->collectObjects(VectorsUsed, _inputScalars, sm)) {
+        _pe->update(-1, &ctx);
+      } else {
+        //we have bad objects...
+        KstDebug::self()->log(i18n("Equation [%1] references non-existent objects.").arg(_equation), KstDebug::Error);
+        _inputScalars.clear();
+        delete (Equation::Node*)ParsedEquation;
+        ParsedEquation = 0L;
+        Equation::mutex().unlock();
       }
-      _pe->update(-1, &ctx);
     } else {
       // Parse error
       KstDebug::self()->log(i18n("Equation [%1] failed to parse.  Errors follow.").arg(_equation), KstDebug::Warning);
       for (QStringList::ConstIterator i = Equation::errorStack.begin(); i != Equation::errorStack.end(); ++i) {
         KstDebug::self()->log(i18n("Parse Error: %1").arg(*i), KstDebug::Warning);
       }
+      _inputScalars.clear();
       delete (Equation::Node*)ParsedEquation;
       ParsedEquation = 0L;
       Equation::mutex().unlock();


More information about the Kst mailing list