fix up serialization a bit more
[satune.git] / src / Tuner / searchtuner.cc
index e594abe..f4f4cfc 100644 (file)
@@ -95,12 +95,50 @@ SearchTuner::SearchTuner(const char *filename) {
                                setting = new TunableSetting(param);
                        }
                        setting->setDecision(lowValue, highValue, defaultValue, selectedValue);
                                setting = new TunableSetting(param);
                        }
                        setting->setDecision(lowValue, highValue, defaultValue, selectedValue);
+                       settings.add(setting);
                        usedSettings.add(setting);
                }
                myfile.close();
        }
 }
 
                        usedSettings.add(setting);
                }
                myfile.close();
        }
 }
 
+void SearchTuner::addUsed(const char *filename) {
+       ifstream myfile;
+       myfile.open (filename, ios::in);
+       if (myfile.is_open()) {
+               bool hasVar;
+               VarType type1;
+               VarType type2;
+               TunableParam param;
+               int lowValue;
+               int highValue;
+               int defaultValue;
+               int selectedValue;
+               while (myfile >> hasVar >> type1 >> type2 >> param >> lowValue >> highValue >> defaultValue >> selectedValue) {
+                       TunableSetting *setting;
+
+                       if (hasVar) {
+                               setting = new TunableSetting(type1, type2, param);
+                       } else {
+                               setting = new TunableSetting(param);
+                       }
+                       setting->setDecision(lowValue, highValue, defaultValue, selectedValue);
+                       if (!settings.contains(setting)) {
+                               settings.add(setting);
+                               usedSettings.add(setting);
+                       } else {
+                               TunableSetting *tmp = settings.get(setting);
+                               settings.remove(tmp);
+                               usedSettings.remove(tmp);
+                               delete tmp;
+                               settings.add(setting);
+                               usedSettings.add(setting);
+                       }
+               }
+               myfile.close();
+       }
+}
+
 SearchTuner *SearchTuner::copyUsed() {
        SearchTuner *tuner = new SearchTuner();
        SetIteratorTunableSetting *iterator = usedSettings.iterator();
 SearchTuner *SearchTuner::copyUsed() {
        SearchTuner *tuner = new SearchTuner();
        SetIteratorTunableSetting *iterator = usedSettings.iterator();
@@ -212,6 +250,18 @@ void SearchTuner::serialize(const char *filename) {
        delete iterator;
 }
 
        delete iterator;
 }
 
+void SearchTuner::serializeUsed(const char *filename) {
+       ofstream myfile;
+       myfile.open (filename, ios::out | ios::trunc);
+       SetIteratorTunableSetting *iterator = usedSettings.iterator();
+       while (iterator->hasNext()) {
+               TunableSetting *setting = iterator->next();
+               myfile << *setting << endl;
+       }
+       myfile.close();
+       delete iterator;
+}
+
 void SearchTuner::printUsed() {
        SetIteratorTunableSetting *iterator = usedSettings.iterator();
        while (iterator->hasNext()) {
 void SearchTuner::printUsed() {
        SetIteratorTunableSetting *iterator = usedSettings.iterator();
        while (iterator->hasNext()) {