X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;f=TextCollection.cpp;h=abc6f912c9a2f52ddb64f8c98a40ffa6c9143de9;hb=25d3dd967bced59699ef5cf3e54d3eff8a6ae883;hp=0300899e97faf1c5d7e94442c32f027e2dc988f4;hpb=7d27a4450ed429e3b63e9d3ba7217a28cbbf9a31;p=SXSI%2FTextCollection.git diff --git a/TextCollection.cpp b/TextCollection.cpp index 0300899..abc6f91 100644 --- a/TextCollection.cpp +++ b/TextCollection.cpp @@ -1,16 +1,35 @@ #include "TextCollection.h" -#include "CSA.h" +#include "FMIndex.h" +#include "SWCSAWrapper.h" +#include "RLCSAWrapper.h" namespace SXSI { + /** - * Init text collection + * Init text collection from a file * - * See CSA.h for more details. + * See TCImplementation.h for more details. */ - TextCollection * TextCollection::InitTextCollection(unsigned samplerate) + TextCollection * TextCollection::Load(FILE *fp, char const *filename, index_mode_t im, unsigned samplerate) { - TextCollection *result = new CSA(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); } }