Added SWCSA
[SXSI/TextCollection.git] / TextCollection.cpp
index 2aef067..1755b6b 100644 (file)
@@ -1,5 +1,6 @@
 #include "TextCollection.h"
-#include "TCImplementation.h"
+#include "FMIndex.h"
+#include "SWCSAWrapper.h"
 
 namespace SXSI
 {
@@ -9,9 +10,22 @@ namespace SXSI
      *
      * See TCImplementation.h for more details.
      */
-    TextCollection * TextCollection::Load(FILE *fp, index_mode_t im, unsigned samplerate)
+    TextCollection * TextCollection::Load(FILE *fp, char const *filename, index_mode_t im, unsigned samplerate)
     {
-        TextCollection *result = new TCImplementation(fp, im, samplerate);
-        return result;
+        char type = 0;
+        if (std::fread(&type, 1, 1, fp) != 1)
+            throw std::runtime_error("TextCollection::Load(): file read error (type flag).");
+        switch (type)
+        {
+        case 'F':
+            return new FMIndex(fp, im, samplerate);
+            break;
+        case 'W':
+            return new SWCSAWrapper(fp, filename);
+            break;
+        }
+
+        std::cerr << "TextCollection::Load(): invalid save file version or corrupted input file." << std::endl;
+        std::exit(1);
     }
 }