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

Andrew Walker arwalker at sumusltd.com
Mon Oct 22 21:39:40 CEST 2007


SVN commit 728237 by arwalker:

BUG:151063 added a method to scripting to return the number of NaN values in a vector

 M  +19 -0     extensions/js/bind_vector.cpp  
 M  +5 -1      extensions/js/bind_vector.h  
 M             extensions/js/examples/quietriot.js  
 M  +7 -7      libkst/kstvector.h  


--- branches/work/kst/1.6/kst/src/extensions/js/bind_vector.cpp #728236:728237
@@ -86,6 +86,7 @@
   { "newSamples", 0L, &KstBindVector::numNew },
   { "shiftedSamples", 0L, &KstBindVector::numShifted },
   { "editable", 0L, &KstBindVector::editable },
+  { "numNaN", 0L, &KstBindVector::numNaN },
   { 0L, 0L, 0L }
 };
 
@@ -412,10 +413,28 @@
 KJS::Value KstBindVector::editable(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();
+  }
   KstReadLocker rl(v);
   return KJS::Boolean(v->editable());
 }
 
 
+KJS::Value KstBindVector::numNaN(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();
+  }
+  KstReadLocker rl(v);
+  return KJS::Number(v->numNaN());
+}
+
+
 #undef makeVector
 
--- branches/work/kst/1.6/kst/src/extensions/js/bind_vector.h #728236:728237
@@ -111,7 +111,11 @@
                     checked before attempting to modify a vector in any way.
     */
     KJS::Value editable(KJS::ExecState *exec) const;
-
+    /* @property number numNaN
+       @readonly
+       @description The number of NaN values in the vector.
+    */
+    KJS::Value numNaN(KJS::ExecState *exec) const;
   protected:
     KstBindVector(int id, const char *name = 0L);
     void addBindings(KJS::ExecState *exec, KJS::Object& obj);
--- branches/work/kst/1.6/kst/src/libkst/kstvector.h #728236:728237
@@ -105,7 +105,10 @@
     inline int numShift() const { return NumShifted; }
 
     inline bool isRising() const { return _is_rising; }
+    inline bool hasNaN() const { return _nsum < _size; }
+    inline int numNaN() const { return _size - _nsum; }
 
+
     /** reset New Samples and Shifted samples */
     void newSync();
 
@@ -122,9 +125,6 @@
     /** Make the vector truly empty.  All values set to NOPOINT (NaN). */
     void blank();
 
-    /* Generally you don't need to call this */
-    void updateScalars();
-
     /** return a sensible label for this vector */
     virtual QString label() const;
 
@@ -160,6 +160,8 @@
     int indexNearX(double x, int NS); //returns the index of the element w/ value closest to v.
 
   protected:
+    QString _label;
+
     /** current number of samples */
     int _size;
 
@@ -202,12 +204,10 @@
     double _min, _max, _mean, _minPos;
     int _minIndex, _maxIndex;
 
-    /** Scalar Maintenance methods */
     void createScalars();
     void renameScalars();
+    void updateScalars();
 
-    QString _label;
-
     friend class KstDataObject;
     virtual double* realloced(double *memptr, int newSize);
     KstObject::UpdateType internalUpdate(KstObject::UpdateType providerRC);
@@ -218,4 +218,4 @@
 typedef KstObjectCollection<KstVector> KstVectorCollection;
 
 #endif
-// vim: ts=2 sw=2 et
+


More information about the Kst mailing list