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