[Kst] branches/work/kst/1.6/kst/src/extensions/js

Andrew Walker arwalker at sumusltd.com
Fri Oct 19 01:19:16 CEST 2007


SVN commit 726797 by arwalker:

BUG:151001 ensure that the min, max, and mean values associated with a vector are always updated before being returned. Add an update method to force update of these and other scalar values associated with a vector

 M  +39 -3     bind_matrix.cpp  
 M  +5 -0      bind_matrix.h  
 M  +39 -4     bind_vector.cpp  
 M  +5 -0      bind_vector.h  


--- branches/work/kst/1.6/kst/src/extensions/js/bind_matrix.cpp #726796:726797
@@ -71,6 +71,7 @@
 static MatrixBindings matrixBindings[] = {
   { "resize", &KstBindMatrix::resize },
   { "zero", &KstBindMatrix::zero },
+  { "update", &KstBindMatrix::update },
   { 0L, 0L }
 };
 
@@ -187,24 +188,45 @@
 
 
 KJS::Value KstBindMatrix::min(KJS::ExecState *exec) const {
-  Q_UNUSED(exec)
   KstMatrixPtr m = makeMatrix(_d);
+  if (!m) {
+    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
+    exec->setException(eobj);
+    return KJS::Undefined();
+  }
+  if (m->dirty()) {
+    m->update();
+  }
   KstReadLocker rl(m);
   return KJS::Number(m->minValue());
 }
 
 
 KJS::Value KstBindMatrix::max(KJS::ExecState *exec) const {
-  Q_UNUSED(exec)
   KstMatrixPtr m = makeMatrix(_d);
+  if (!m) {
+    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
+    exec->setException(eobj);
+    return KJS::Undefined();
+  }
+  if (m->dirty()) {
+    m->update();
+  }
   KstReadLocker rl(m);
   return KJS::Number(m->maxValue());
 }
 
 
 KJS::Value KstBindMatrix::mean(KJS::ExecState *exec) const {
-  Q_UNUSED(exec)
   KstMatrixPtr m = makeMatrix(_d);
+  if (!m) {
+    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
+    exec->setException(eobj);
+    return KJS::Undefined();
+  }
+  if (m->dirty()) {
+    m->update();
+  }
   KstReadLocker rl(m);
   return KJS::Number(m->meanValue());
 }
@@ -284,6 +306,20 @@
 }
 
 
+KJS::Value KstBindMatrix::update(KJS::ExecState *exec, const KJS::List& args) {
+  Q_UNUSED(args)
+  KstMatrixPtr m = makeMatrix(_d);
+  if (!m || !m->editable()) {
+    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
+    exec->setException(eobj);
+    return KJS::Undefined();
+  }
+  KstWriteLocker wl(m);
+  m->update();
+  return KJS::Undefined();
+}
+
+
 int KstBindMatrix::methodCount() const {
   return sizeof matrixBindings + KstBindObject::methodCount();
 }
--- branches/work/kst/1.6/kst/src/extensions/js/bind_matrix.h #726796:726797
@@ -60,6 +60,11 @@
        @exception GeneralError Throws this exception if the matrix is not editable.
      */
     KJS::Value zero(KJS::ExecState *exec, const KJS::List& args);
+    /* @method update
+       @description Updates the statistical values associated with a matrix.
+       @exception GeneralError Throws this exception if the matrix is not editable.
+     */
+    KJS::Value update(KJS::ExecState *exec, const KJS::List& args);
 
     /* @property number editable
        @readonly
--- branches/work/kst/1.6/kst/src/extensions/js/bind_vector.cpp #726796:726797
@@ -73,6 +73,7 @@
   { "resize", &KstBindVector::resize },
   { "interpolate", &KstBindVector::interpolate },
   { "zero", &KstBindVector::zero },
+  { "update", &KstBindVector::update },
   { 0L, 0L }
 };
 
@@ -286,24 +287,45 @@
 
 
 KJS::Value KstBindVector::min(KJS::ExecState *exec) const {
-  Q_UNUSED(exec)
   KstVectorPtr v = makeVector(_d);
+  if (!v) {
+    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
+    exec->setException(eobj);
+    return KJS::Undefined();
+  }
+  if (v->dirty()) {
+    v->update();
+  }
   KstReadLocker rl(v);
   return KJS::Number(v->min());
 }
 
 
 KJS::Value KstBindVector::max(KJS::ExecState *exec) const {
-  Q_UNUSED(exec)
   KstVectorPtr v = makeVector(_d);
+  if (!v) {
+    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
+    exec->setException(eobj);
+    return KJS::Undefined();
+  }
+  if (v->dirty()) {
+    v->update();
+  }
   KstReadLocker rl(v);
   return KJS::Number(v->max());
 }
 
 
 KJS::Value KstBindVector::mean(KJS::ExecState *exec) const {
-  Q_UNUSED(exec)
   KstVectorPtr v = makeVector(_d);
+  if (!v) {
+    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
+    exec->setException(eobj);
+    return KJS::Undefined();
+  }
+  if (v->dirty()) {
+    v->update();
+  }
   KstReadLocker rl(v);
   return KJS::Number(v->mean());
 }
@@ -373,6 +395,20 @@
 }
 
 
+KJS::Value KstBindVector::update(KJS::ExecState *exec, const KJS::List& args) {
+  Q_UNUSED(args)
+  KstVectorPtr v = makeVector(_d);
+  if (!v || !v->editable()) {
+    KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError);
+    exec->setException(eobj);
+    return KJS::Undefined();
+  }
+  KstWriteLocker wl(v);
+  v->update();
+  return KJS::Undefined();
+}
+
+
 KJS::Value KstBindVector::editable(KJS::ExecState *exec) const {
   Q_UNUSED(exec)
   KstVectorPtr v = makeVector(_d);
@@ -383,4 +419,3 @@
 
 #undef makeVector
 
-// vim: ts=2 sw=2 et
--- branches/work/kst/1.6/kst/src/extensions/js/bind_vector.h #726796:726797
@@ -72,6 +72,11 @@
        @exception GeneralError Throws this exception if the vector is not editable.
     */
     KJS::Value zero(KJS::ExecState *exec, const KJS::List& args);
+    /* @method update
+       @description Updates the statistical values associated with a vector.
+       @exception GeneralError Throws this exception if the vector is not editable.
+    */
+    KJS::Value update(KJS::ExecState *exec, const KJS::List& args);    
     /* @property number length
        @readonly
        @description The number of samples in the vector.


More information about the Kst mailing list