X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;f=TextCollection.cpp;h=1755b6bf24e98be2f92c2e62e4b5a9765a4babb4;hb=89dc22aee980ba16f757cd9a7f77478c2da50051;hp=9c9472416747ce522ec18cfa0251073c2f379991;hpb=40ddf9aca842bdc081b6350a4ebfe36b066c94c9;p=SXSI%2FTextCollection.git diff --git a/TextCollection.cpp b/TextCollection.cpp index 9c94724..1755b6b 100644 --- a/TextCollection.cpp +++ b/TextCollection.cpp @@ -1,16 +1,31 @@ #include "TextCollection.h" -#include "TCImplementation.h" +#include "FMIndex.h" +#include "SWCSAWrapper.h" namespace SXSI { + /** * Init text collection from a file * * See TCImplementation.h for more details. */ - TextCollection * TextCollection::Load(FILE *fp, unsigned samplerate) + TextCollection * TextCollection::Load(FILE *fp, char const *filename, index_mode_t im, unsigned samplerate) { - TextCollection *result = new TCImplementation(fp, 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); } }