/* $Id: filtertypes.cc 4025 2008-10-01 00:01:14Z abehm $ Copyright (C) 2008 by The Regents of the University of California Redistribution of this file is permitted under the terms of the BSD license Date: 04/04/2008 Author: Alexander Behm */ #include "filtertypes.h" #include "util/misc.h" AbstractFilter* AbstractFilter:: loadFilterInstance(ifstream& fpIn) { FilterType filterType; fpIn.read((char*)&filterType, sizeof(FilterType)); switch(filterType) { case FT_LENGTH: return new LengthFilter(fpIn); break; case FT_CHECKSUM: return new ChecksumFilter(fpIn); break; default: { cout << "WARNING: attempt to read filter from file failed. Unknown filter type." << endl; return NULL; } break; } } LengthFilter:: LengthFilter(ifstream& fpIn) { ft = FT_LENGTH; fpIn.read((char*)&maxStrLength, sizeof(unsigned)); } unsigned LengthFilter:: getFilterLbound() const { return 0; } unsigned LengthFilter:: getFilterUbound() const { return maxStrLength; } unsigned LengthFilter:: getKey(const string& s) const { return s.length(); } AbstractFilter* LengthFilter:: clone() const { return new LengthFilter(maxStrLength); } void LengthFilter:: saveFilterInstance(ofstream& fpOut) const { fpOut.write((const char*)&ft, sizeof(FilterType)); fpOut.write((const char*)&maxStrLength, sizeof(unsigned)); } ChecksumFilter:: ChecksumFilter(ifstream& fpIn) { ft = FT_CHECKSUM; fpIn.read((char*)&maxStrLength, sizeof(unsigned)); maxChecksum = maxStrLength * CHECKSUM_ASCII_MAX; } unsigned ChecksumFilter:: getFilterLbound() const { return 0; } unsigned ChecksumFilter:: getFilterUbound() const { return maxChecksum; } unsigned ChecksumFilter:: getKey(const string& s) const { return checksum(s); } AbstractFilter* ChecksumFilter:: clone() const { return new ChecksumFilter(maxStrLength); } void ChecksumFilter:: saveFilterInstance(ofstream& fpOut) const { fpOut.write((const char*)&ft, sizeof(FilterType)); fpOut.write((const char*)&maxStrLength, sizeof(unsigned)); }