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

Peter Kümmel syntheticpp at gmx.net
Mon Mar 21 22:59:08 CET 2011


SVN commit 1225592 by kuemmel:

save vectors ordered, to make reconstructing possible when loading

 M  +31 -1     libkst/objectmap.h  
 M  +1 -1      libkst/primitive.h  
 M  +23 -39    libkstmath/basicplugin.cpp  


--- branches/work/kst/portto4/kst/src/libkst/objectmap.h #1225591:1225592
@@ -21,7 +21,37 @@
 namespace Kst {
 
 template<class T>
-class ObjectMap : public QHash<QString, SharedPtr<T> > {
+class ObjectMap : public QHash<QString, SharedPtr<T> >
+{
+public:
+  typedef QHash<QString, SharedPtr<T> > HashMap;
+
+  typename HashMap::iterator insert(const QString& key, const SharedPtr<T>& value)
+  {
+    addKey(key);
+    return HashMap::insert(key, value);
+  }
+
+  SharedPtr<T>& operator[](const QString& key)
+  {
+    addKey(key);
+    return HashMap::operator[](key);
+  }
+
+  const SharedPtr<T> operator[](const QString& key) const
+  {
+    addKey(key);
+    return HashMap::operator[](key);
+  }
+
+  void addKey(const QString& key) const
+  {
+    if (!ordered.contains(key)) {
+      ordered << key;
+    }
+  }
+
+  mutable QStringList ordered;
 };
 
 }
--- branches/work/kst/portto4/kst/src/libkst/primitive.h #1225591:1225592
@@ -47,7 +47,7 @@
     inline ObjectPtr provider() const { return ObjectPtr(_provider); }
 
     void setSlaveName(QString slaveName);
-    QString slaveName() { return _slaveName; }
+    QString slaveName() const { return _slaveName; }
     virtual QString propertyString() const;
     virtual QString  sizeString() const;
 
--- branches/work/kst/portto4/kst/src/libkstmath/basicplugin.cpp #1225591:1225592
@@ -306,48 +306,32 @@
 }
 
 
-void BasicPlugin::save(QXmlStreamWriter &s) {
-  s.writeStartElement(staticTypeTag);
-  s.writeAttribute("type", _pluginName);
-  saveNameInfo(s, VNUM|PNUM|XNUM);
-  for (VectorMap::Iterator i = _inputVectors.begin(); i != _inputVectors.end(); ++i) {
-    s.writeStartElement("inputvector");
-    s.writeAttribute("type", i.key());
-    s.writeAttribute("tag", i.value()->Name());
-    s.writeEndElement();
+template<class T, class V>
+static void writeVectors(T& vectors, const QString& element, QXmlStreamWriter& stream, QString (V::* name)() const) {
+  for (QStringList::iterator it = vectors.ordered.begin(); it != vectors.ordered.end(); ++it) {
+    typename T::iterator i = vectors.find(*it);
+    stream.writeStartElement(element);
+    stream.writeAttribute("type", i.key());
+    stream.writeAttribute("tag", (i.value()->*name)());
+    stream.writeEndElement();
   }
-  for (ScalarMap::Iterator i = _inputScalars.begin(); i != _inputScalars.end(); ++i) {
-    s.writeStartElement("inputscalar");
-    s.writeAttribute("type", i.key());
-    s.writeAttribute("tag", i.value()->Name());
-    s.writeEndElement();
   }
-  for (StringMap::Iterator i = _inputStrings.begin(); i != _inputStrings.end(); ++i) {
-    s.writeStartElement("inputstring");
-    s.writeAttribute("type", i.key());
-    s.writeAttribute("tag", i.value()->Name());
-    s.writeEndElement();
+
+
+void BasicPlugin::save(QXmlStreamWriter &stream) {
+  stream.writeStartElement(staticTypeTag);
+  stream.writeAttribute("type", _pluginName);
+  saveNameInfo(stream, VNUM|PNUM|XNUM);
+
+  writeVectors(_inputVectors, "inputvector", stream, &NamedObject::Name);
+  writeVectors(_inputScalars, "inputscalar", stream, &NamedObject::Name);
+  writeVectors(_inputStrings, "inputstring", stream, &NamedObject::Name);
+  writeVectors(_outputVectors, "outputvector", stream, &Primitive::slaveName);
+  writeVectors(_outputScalars, "outputscalar", stream, &Primitive::slaveName);
+  writeVectors(_outputStrings, "outputstring", stream, &Primitive::slaveName);
+
+  stream.writeEndElement();
   }
-  for (VectorMap::Iterator i = _outputVectors.begin(); i != _outputVectors.end(); ++i) {
-    s.writeStartElement("outputvector");
-    s.writeAttribute("type", i.key());
-    s.writeAttribute("tag", i.value()->slaveName());
-    s.writeEndElement();
-  }
-  for (ScalarMap::Iterator i = _outputScalars.begin(); i != _outputScalars.end(); ++i) {
-    s.writeStartElement("outputscalar");
-    s.writeAttribute("type", i.key());
-    s.writeAttribute("tag", i.value()->slaveName());
-    s.writeEndElement();
-  }
-  for (StringMap::Iterator i = _outputStrings.begin(); i != _outputStrings.end(); ++i) {
-    s.writeStartElement("outputstring");
-    s.writeAttribute("type", i.key());
-    s.writeAttribute("tag", i.value()->slaveName());
-    s.writeEndElement();
-  }
-  s.writeEndElement();
-}
 
 
 void BasicPlugin::saveProperties(QXmlStreamWriter &s) {


More information about the Kst mailing list