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

Peter Kümmel syntheticpp at gmx.net
Wed Jan 19 14:25:20 CET 2011


SVN commit 1215734 by kuemmel:

use templates so we could use this code also for Strings,
Primitives have metas.

 M  +0 -3      libkst/primitive.cpp  
 M  +5 -8      libkst/primitive.h  
 M  +13 -0     libkst/vector.cpp  
 M  +3 -0      libkst/vector.h  
 M  +3 -21     libkstapp/scalarmodel.cpp  
 M  +19 -3     libkstapp/scalarmodel.h  


--- branches/work/kst/portto4/kst/src/libkst/primitive.cpp #1215733:1215734
@@ -95,11 +95,8 @@
 }
 
 
-ScalarMap Primitive::scalars() const {return ScalarMap();}
-StringMap Primitive::strings() const {return StringMap();}
 
 
-
 }
 
 // vim: et sw=2 ts=2
--- branches/work/kst/portto4/kst/src/libkst/primitive.h #1215733:1215734
@@ -28,11 +28,10 @@
 
 namespace Kst {
 
-class Scalar;
-class String;
-typedef ObjectMap<String> StringMap;
-typedef ObjectMap<Scalar> ScalarMap;
 
+class Primitive;
+typedef ObjectMap<Primitive> PrimitiveMap;
+
 class KSTCORE_EXPORT Primitive : public Object 
 {
     Q_OBJECT
@@ -56,9 +55,7 @@
 
     virtual ObjectList<Primitive> outputPrimitives() const {return ObjectList<Primitive>();}
 
-    // metas of Primitive
-    virtual ScalarMap scalars() const;
-    virtual StringMap strings() const;
+    virtual PrimitiveMap metas() const { return PrimitiveMap(); }
 
 
   protected:
@@ -84,7 +81,7 @@
 
 typedef SharedPtr<Primitive> PrimitivePtr;
 typedef ObjectList<Primitive> PrimitiveList;
-typedef ObjectMap<PrimitivePtr> PrimitiveMap;
+typedef ObjectMap<Primitive> PrimitiveMap;
 
 }
 
--- branches/work/kst/portto4/kst/src/libkst/vector.cpp #1215733:1215734
@@ -629,6 +629,19 @@
   return primitive_list;
 }
 
+PrimitiveMap Vector::metas() const
+{
+  PrimitiveMap meta;
+  for (QHash<QString, ScalarPtr>::ConstIterator it = _scalars.begin(); it != _scalars.end(); ++it) {
+    meta[it.key()] = it.value();
+  }
+  for (QHash<QString, StringPtr>::ConstIterator it = _strings.begin(); it != _strings.end(); ++it) {
+    meta[it.key()] = it.value();
+  }
+  return meta;
+}
+
+
 #undef INITSIZE
 
 }
--- branches/work/kst/portto4/kst/src/libkst/vector.h #1215733:1215734
@@ -157,6 +157,9 @@
     ScalarMap scalars() const {return _scalars;}
     StringMap strings() const {return _strings;}
 
+    virtual PrimitiveMap metas() const;
+
+
     virtual ObjectList<Primitive> outputPrimitives() const;
 
   protected:
--- branches/work/kst/portto4/kst/src/libkstapp/scalarmodel.cpp #1215733:1215734
@@ -92,18 +92,6 @@
 }
 
 
-void ScalarModel::addScalar(ScalarPtr scalar, ScalarTreeItem* parent) {
-  addScalarTreeItem(QList<QVariant>() << scalar->Name() << scalar->value(), parent);
-}
-
-
-void ScalarModel::addScalars(const QHash<QString, Kst::ScalarPtr> scalarMap, ScalarTreeItem* parent) {
-  foreach(const ScalarPtr& scalar, scalarMap) {
-    addScalar(scalar, parent);
-  }
-}
-
-
 ScalarTreeItem* ScalarModel::addScalarTreeItem(const QList<QVariant>& data, ScalarTreeItem* parent) {
   ScalarTreeItem* parentItem;
   if (parent) {
@@ -115,19 +103,13 @@
 }
 
 
-void ScalarModel::addPrimitivesScalars(const PrimitivePtr& prim, ScalarTreeItem* parent) {
-  ScalarTreeItem* item = addScalarTreeItem(QList<QVariant>() << prim->Name(), parent);
-  addScalars(prim->scalars(), item);
-}
-
-
 void ScalarModel::addDataObject(DataObjectPtr dataObject, ScalarTreeItem* parent) {
   ScalarTreeItem* item = addScalarTreeItem(QList<QVariant>() << dataObject->Name(), parent);
 
   ObjectList<Primitive> primitives = dataObject->outputPrimitives();
-  foreach(const PrimitivePtr& prim, primitives) {
+  foreach(PrimitivePtr prim, primitives) {
     if (!kst_cast<String>(prim)) {
-      addPrimitivesScalars(prim, item);
+      addPrimitivesScalars<Scalar>(prim.data(), item);
     }
   }
 }
@@ -156,7 +138,7 @@
       if (kst_cast<Scalar>(obj) && !kst_cast<Scalar>(obj)->orphan()) {
         continue;
       }
-      addPrimitivesScalars(kst_cast<Primitive>(obj));
+      addPrimitivesScalars<Scalar>(kst_cast<Primitive>(obj));
     } else if (kst_cast<DataSource>(obj) && !kst_cast<DataSource>(obj)->scalar().list().isEmpty()) {
       addDataSource(kst_cast<DataSource>(obj));
     } else if (kst_cast<DataObject>(obj)) {
--- branches/work/kst/portto4/kst/src/libkstapp/scalarmodel.h #1215733:1215734
@@ -61,13 +61,29 @@
 
   void createTree();
   
-  void addScalar(ScalarPtr scalar, ScalarTreeItem* parent = 0);
-  void addScalars(const QHash<QString, Kst::ScalarPtr> scalarMap, ScalarTreeItem* parent = 0);
+  template<class T>
+  void addScalar(T* scalar, ScalarTreeItem* parent = 0) {
+    addScalarTreeItem(QList<QVariant>() << scalar->Name() << scalar->value(), parent);
+  }
 
+  template<class T>
+  void addScalars(const PrimitiveMap& scalarMap, ScalarTreeItem* parent) {
+    foreach(const PrimitivePtr& scalar, scalarMap) {
+      if(kst_cast<T>(scalar)) {
+        addScalar<Scalar>(kst_cast<T>(scalar), parent);
+      }
+    }
+  }
+
+  template<class T>
+  void addPrimitivesScalars(const PrimitivePtr& prim, ScalarTreeItem* parent = 0) {
+    ScalarTreeItem* item = addScalarTreeItem(QList<QVariant>() << prim->Name(), parent);
+    addScalars<T>(prim->metas(), item);
+  }
+
   void addDataObject(DataObjectPtr dataObject, ScalarTreeItem* parent = 0);
   void addDataSource(DataSourcePtr dataSource, ScalarTreeItem* parent = 0);
 
-  void addPrimitivesScalars(const PrimitivePtr&, ScalarTreeItem* parent = 0);
 
 private:
   ObjectStore *_store;


More information about the Kst mailing list