X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;f=TextCollection.cpp;h=abc6f912c9a2f52ddb64f8c98a40ffa6c9143de9;hb=898f6e5c6b7223f4753b7ccb7939809ee5f53aae;hp=d099a3c4e9ef0d0d5077695ffe29ca3de0d7dec7;hpb=9042e7b1b181a50b15e8ec1b79d5a5c2f913bfff;p=SXSI%2FTextCollection.git diff --git a/TextCollection.cpp b/TextCollection.cpp index d099a3c..abc6f91 100644 --- a/TextCollection.cpp +++ b/TextCollection.cpp @@ -1,5 +1,7 @@ #include "TextCollection.h" -#include "TCImplementation.h" +#include "FMIndex.h" +#include "SWCSAWrapper.h" +#include "RLCSAWrapper.h" namespace SXSI { @@ -9,9 +11,25 @@ namespace SXSI * * 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; + case 'R': + return new RLCSAWrapper(fp, filename); + break; + } + + std::cerr << "TextCollection::Load(): invalid save file version or corrupted input file." << std::endl; + std::exit(1); } }