/** ** Copyright (c) 2007-2009 Illumina, Inc. ** ** This software is covered by the "Illumina Genome Analyzer Software ** License Agreement" and the "Illumina Source Code License Agreement", ** and certain third party copyright/licenses, and any user of this ** source file is bound by the terms therein (see accompanying files ** Illumina_Genome_Analyzer_Software_License_Agreement.pdf and ** Illumina_Source_Code_License_Agreement.pdf and third party ** copyright/license notices). ** ** This file is part of the Consensus Assessment of Sequence And VAriation ** (CASAVA) software package. ** ** \file Compression.cpp ** ** \brief Implementation of the support for various compression types. ** ** \author Come Raczy **/ #include #include #include #include #include "common/Compression.hh" #ifdef HAVE_ZLIB # include #endif #ifdef HAVE_BZIP2 # include #endif namespace casava { namespace common { #ifdef HAVE_ZLIB void CompressionFilter::operator()(boost::iostreams::filtering_ostream &os) const { os.push(boost::iostreams::gzip_compressor(params_)); } void CompressionFilter::operator()(boost::iostreams::filtering_istream &is) const { is.push(boost::iostreams::gzip_decompressor(params_.window_bits)); } #endif #ifdef HAVE_BZIP2 void CompressionFilter::operator()(boost::iostreams::filtering_ostream &os) const { os.push(boost::iostreams::bzip2_compressor(params_)); } void CompressionFilter::operator()(boost::iostreams::filtering_istream &is) const { is.push(boost::iostreams::bzip2_decompressor(params_.small)); } #endif const CompressionFactory::CompressionMap &CompressionFactory::getCompressionMap() { static CompressionMap compressionMap; if (compressionMap.empty()) { // always support no-compression static Compression none; compressionMap["none"] = &none; // support other compressions via boost, when available #ifdef HAVE_ZLIB static boost::iostreams::gzip_params defGzipParams; static CompressionFilter gzip(defGzipParams); compressionMap["gzip"] = &gzip; #endif #ifdef HAVE_BZIP2 static boost::iostreams::bzip2_params defBzip2Params; static CompressionFilter bzip2(defBzip2Params); compressionMap["bzip2"] = &bzip2; #endif } return compressionMap; } const Compression &CompressionFactory::get(const std::string &compression) throw(UnsupportedCompressionException) { const CompressionMap &compressionMap = getCompressionMap(); CompressionMap::const_iterator found = compressionMap.find(compression); if (compressionMap.end() != found) { return *(found->second); } else { throw UnsupportedCompressionException(compression); } } const Compression &CompressionFactory::none() { return get("none"); } const std::vector CompressionFactory::getCompressionList() { const CompressionMap &compressionMap = getCompressionMap(); using namespace boost::lambda; std::vector compressionList; std::transform(compressionMap.begin(), compressionMap.end(), back_inserter( compressionList), bind(&CompressionMap::value_type::first, _1)); return compressionList; } bool CompressionFactory::isSupported(const std::string &compression) { const std::vector compressionList = getCompressionList(); return std::find(compressionList.begin(), compressionList.end(), compression) != compressionList.end(); } UnsupportedCompressionException::UnsupportedCompressionException( const std::string &algorithm) : std::logic_error(std::string("Unsupported compression algorithm: ") + algorithm) { } } // namespace common } // namespacecasava