Debug swcsa
[SXSI/TextCollection.git] / TextCollection.cpp
1 #include "TextCollection.h"
2 #include "FMIndex.h"
3 #include "SWCSAWrapper.h"
4 #include "RLCSAWrapper.h"
5
6 namespace SXSI
7 {
8
9     /**
10      * Init text collection from a file
11      *
12      * See TCImplementation.h for more details.
13      */
14     TextCollection * TextCollection::Load(FILE *fp, char const *filename, index_mode_t im, unsigned samplerate)
15     {
16         char type = 0;
17         if (std::fread(&type, 1, 1, fp) != 1)
18             throw std::runtime_error("TextCollection::Load(): file read error (type flag).");
19         switch (type)
20         {
21         case 'F':
22             return new FMIndex(fp, im, samplerate);
23             break;
24         case 'W':
25             return new SWCSAWrapper(fp, filename);
26             break;
27         case 'R':
28             return new RLCSAWrapper(fp, filename);
29             break;
30         }
31
32         std::cerr << "TextCollection::Load(): invalid save file version or corrupted input file." << std::endl;
33         std::exit(1);
34     }
35 }