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

Andrew Walker arwalker at sumusltd.com
Fri Jan 11 23:14:10 CET 2008


SVN commit 760096 by arwalker:

add inputs and outputs javaScript properties to c-style plugins

 M  +112 -2    bind_objectcollection.cpp  
 M  +5 -0      bind_objectcollection.h  
 M  +31 -1     bind_plugin.cpp  
 M  +10 -0     bind_plugin.h  
 M  +0 -2      bind_window.h  


--- branches/work/kst/1.6/kst/src/extensions/js/bind_objectcollection.cpp #760095:760096
@@ -20,18 +20,29 @@
 
 #include <qdeepcopy.h>
 
+#include <kstdatacollection.h>
 #include <kstobject.h>
+#include <plugin.h>
 
 #include <kdebug.h>
 
 KstBindObjectCollection::KstBindObjectCollection(KJS::ExecState *exec, const KstObjectList<KstObjectPtr>& objects)
 : KstBindCollection(exec, "ObjectCollection", true) {
   _objects = QDeepCopy<KstObjectList<KstObjectPtr> >(objects);
+  _inputs = false;
 }
 
 
+KstBindObjectCollection::KstBindObjectCollection(KJS::ExecState *exec, const KstCPluginPtr plugin, bool inputs)
+: KstBindCollection(exec, "ObjectCollection", true) {
+  _plugin = plugin;
+  _inputs = inputs;
+}
+
+
 KstBindObjectCollection::KstBindObjectCollection(KJS::ExecState *exec)
 : KstBindCollection(exec, "ObjectCollection", true) {
+  _inputs = false;
 }
 
 
@@ -41,34 +52,133 @@
 
 KJS::Value KstBindObjectCollection::length(KJS::ExecState *exec) const {
   Q_UNUSED(exec)
+
+  if (_plugin) {
+    if (_plugin->plugin()) {
+      if (_inputs) {
+        return KJS::Number(_plugin->plugin()->data()._inputs.size());
+      } else {
+        return KJS::Number(_plugin->plugin()->data()._outputs.size());
+      }
+    } else {
+      return KJS::Undefined();
+    }
+  }
+
   return KJS::Number(_objects.count());
 }
 
 
 QStringList KstBindObjectCollection::collection(KJS::ExecState *exec) const {
   Q_UNUSED(exec)
+
+  if (_plugin) {
+    if (_plugin->plugin()) {
+      return _plugin->inputVectors().tagNames() + _plugin->inputStrings().tagNames() + _plugin->inputScalars().tagNames();
+    }
+  }
+
   return _objects.tagNames();
 }
 
 
 KJS::Value KstBindObjectCollection::extract(KJS::ExecState *exec, const KJS::Identifier& item) const {
-  KstObjectPtr vp = *_objects.findTag(item.qstring());
+  KstObjectPtr vp;
 
+  if (_plugin) {
+    if (_plugin->plugin()) {
+      if (_inputs) {
+        for (QValueList<Plugin::Data::IOValue>::ConstIterator it = _plugin->plugin()->data()._inputs.begin(); it != _plugin->plugin()->data()._inputs.end(); ++it) {
+          if (item.qstring().compare((*it)._name) == 0) {
+            Plugin::Data::IOValue::ValueType type = (*it)._type;
+
+            if (type == Plugin::Data::IOValue::TableType) {
+              vp = _plugin->inputVectors()[(*it)._name];
+            } else if (type == Plugin::Data::IOValue::StringType) {
+              vp = _plugin->inputStrings()[(*it)._name];
+            } else if (type == Plugin::Data::IOValue::FloatType ||
+                      type == Plugin::Data::IOValue::PidType) {
+              vp = _plugin->inputScalars()[(*it)._name];
+            }
+
+            break;
+          }
+        }
+      } else {
+        for (QValueList<Plugin::Data::IOValue>::ConstIterator it = _plugin->plugin()->data()._outputs.begin(); it != _plugin->plugin()->data()._outputs.end(); ++it) {
+          if (item.qstring().compare((*it)._name) == 0) {
+            Plugin::Data::IOValue::ValueType type = (*it)._type;
+
+            if (type == Plugin::Data::IOValue::TableType) {
+              vp = _plugin->outputVectors()[(*it)._name];
+            } else if (type == Plugin::Data::IOValue::StringType) {
+              vp = _plugin->outputStrings()[(*it)._name];
+            } else if (type == Plugin::Data::IOValue::FloatType ||
+                      type == Plugin::Data::IOValue::PidType) {
+              vp = _plugin->outputScalars()[(*it)._name];
+            }
+
+            break;
+          }
+        }
+      }
+    }
+  } else {
+    vp = *_objects.findTag(item.qstring());
+  }
+
   if (!vp) {
     return KJS::Undefined();
   }
+
   return KJS::Object(new KstBindObject(exec, vp));
 }
 
 
 KJS::Value KstBindObjectCollection::extract(KJS::ExecState *exec, unsigned item) const {
   KstObjectPtr vp;
-  if (item < _objects.count()) {
+
+  if (_plugin) {
+    if (_plugin->plugin()) {
+      if (_inputs) {
+        if (item < _plugin->plugin()->data()._inputs.size()) {
+          Plugin::Data::IOValue::ValueType type;
+
+          type = _plugin->plugin()->data()._inputs[item]._type;
+
+          if (type == Plugin::Data::IOValue::TableType) {
+            vp = _plugin->inputVectors()[_plugin->plugin()->data()._inputs[item]._name];
+          } else if (type == Plugin::Data::IOValue::StringType) {
+            vp = _plugin->inputStrings()[_plugin->plugin()->data()._inputs[item]._name];
+          } else if (type == Plugin::Data::IOValue::FloatType ||
+                     type == Plugin::Data::IOValue::PidType) {
+            vp = _plugin->inputScalars()[_plugin->plugin()->data()._inputs[item]._name];
+          }
+        }
+      } else {
+        if (item < _plugin->plugin()->data()._outputs.size()) {
+          Plugin::Data::IOValue::ValueType type;
+
+          type = _plugin->plugin()->data()._outputs[item]._type;
+
+          if (type == Plugin::Data::IOValue::TableType) {
+            vp = _plugin->inputVectors()[_plugin->plugin()->data()._outputs[item]._name];
+          } else if (type == Plugin::Data::IOValue::StringType) {
+            vp = _plugin->inputStrings()[_plugin->plugin()->data()._outputs[item]._name];
+          } else if (type == Plugin::Data::IOValue::FloatType ||
+                     type == Plugin::Data::IOValue::PidType) {
+            vp = _plugin->inputScalars()[_plugin->plugin()->data()._outputs[item]._name];
+          }
+        }
+      }
+    }
+  } else if (item < _objects.count()) {
     vp = _objects[item];
   }
 
   if (!vp) {
     return KJS::Undefined();
   }
+
   return KJS::Object(new KstBindObject(exec, vp));
 }
--- branches/work/kst/1.6/kst/src/extensions/js/bind_objectcollection.h #760095:760096
@@ -20,6 +20,8 @@
 
 #include "bind_collection.h"
 
+#include <kstbasicplugin.h>
+#include <kstcplugin.h>
 #include <kstobject.h>
 
 #include <kjs/interpreter.h>
@@ -34,6 +36,7 @@
 class KstBindObjectCollection : public KstBindCollection {
   public:
     KstBindObjectCollection(KJS::ExecState *exec, const KstObjectList<KstObjectPtr>& vectors);
+    KstBindObjectCollection(KJS::ExecState *exec, const KstCPluginPtr plugin, bool inputs);
     KstBindObjectCollection(KJS::ExecState *exec);
     ~KstBindObjectCollection();
 
@@ -45,6 +48,8 @@
 
   protected:
     KstObjectList<KstObjectPtr> _objects;
+    KstCPluginPtr _plugin;
+    bool _inputs;
 };
 
 
--- branches/work/kst/1.6/kst/src/extensions/js/bind_plugin.cpp #760095:760096
@@ -15,6 +15,7 @@
  *                                                                         *
  ***************************************************************************/
 
+#include "bind_objectcollection.h"
 #include "bind_plugin.h"
 #include "bind_pluginmodule.h"
 #include "bind_scalar.h"
@@ -97,7 +98,7 @@
 };
 
 
-static PluginBindings pluginBindings[] = {\
+static PluginBindings pluginBindings[] = {
   { "validate", &KstBindPlugin::validate },
   { "setInput", &KstBindPlugin::setInput },
   { 0L, 0L }
@@ -105,6 +106,8 @@
 
 
 static PluginProperties pluginProperties[] = {
+  { "inputs", 0L, &KstBindPlugin::inputs },
+  { "outputs", 0L, &KstBindPlugin::outputs },
   { "module", &KstBindPlugin::setModule, &KstBindPlugin::module },
   { "lastError", 0L, &KstBindPlugin::lastError },
   { "valid", 0L, &KstBindPlugin::valid },
@@ -287,6 +290,7 @@
           KstVectorPtr vp = extractVector(exec, args[1]);
           if (vp) {
             d->inputVectors().insert(d->plugin()->data()._inputs[index]._name, vp);
+            d->setDirty(true);
           } else {
             KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError, "Argument was not of the expected type.");
             exec->setException(eobj);
@@ -308,6 +312,7 @@
 
           if (sp) {
             d->inputStrings().insert(input, sp);
+            d->setDirty(true);
           } else {
             KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError, "Argument was not of the expected type.");
             exec->setException(eobj);
@@ -330,6 +335,7 @@
 
           if (sp) {
             d->inputScalars().insert(input, sp);
+            d->setDirty(true);
           } else {
             KJS::Object eobj = KJS::Error::create(exec, KJS::GeneralError, "Argument was not of the expected type.");
             exec->setException(eobj);
@@ -360,6 +366,30 @@
 }
 
 
+KJS::Value KstBindPlugin::inputs(KJS::ExecState *exec) const {
+  KstCPluginPtr d = makePlugin(_d);
+  if (d) {
+    KstReadLocker rl(d);
+    if (d->plugin()) {
+      return KJS::Object(new KstBindObjectCollection(exec, d, true));
+    }
+  }
+  return KJS::Undefined();
+}
+
+
+KJS::Value KstBindPlugin::outputs(KJS::ExecState *exec) const {
+  KstCPluginPtr d = makePlugin(_d);
+  if (d) {
+    KstReadLocker rl(d);
+    if (d->plugin()) {
+      return KJS::Object(new KstBindObjectCollection(exec, d, false));
+    }
+  }
+  return KJS::Undefined();
+}
+
+
 KJS::Value KstBindPlugin::module(KJS::ExecState *exec) const {
   KstCPluginPtr d = makePlugin(_d);
   if (d) {
--- branches/work/kst/1.6/kst/src/extensions/js/bind_plugin.h #760095:760096
@@ -65,6 +65,16 @@
     */
     KJS::Value validate(KJS::ExecState *exec, const KJS::List& args);
 
+    /* @property ObjectCollection inputs
+       @description The list of inputs to the plugin.
+    */
+    KJS::Value inputs(KJS::ExecState *exec) const;
+
+    /* @property ObjectCollection outputs
+       @description The list of outputs to the plugin.
+    */
+    KJS::Value outputs(KJS::ExecState *exec) const;
+
     /* @property PluginModule module
        @description The library or module that is used for data processing by
                     this plugin object.
--- branches/work/kst/1.6/kst/src/extensions/js/bind_window.h #760095:760096
@@ -64,8 +64,6 @@
 
     /* @property PlotCollection plots
        @description The list of plots contained in this window, flattened.
-                    This property is subject to change!  Do not rely on it for
-                    production code yet!
     */
     KJS::Value plots(KJS::ExecState *exec) const;
 


More information about the Kst mailing list