/*****************************************************************************/ // Copyright (c) Illumina 2008 // Author: Richard Shaw // // 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). /*****************************************************************************/ #include #include "common/File_Buffer.h" #include "File_Buffer_Impl.h" /*****************************************************************************/ File_Buffer::File_Buffer(const std::string& file_name, Compression_Type compression_type) { my_impl_ptr = new File_Buffer_Impl(file_name, compression_type); } /*****************************************************************************/ File_Buffer::~File_Buffer() { if (my_impl_ptr) { delete my_impl_ptr; } } /*****************************************************************************/ bool File_Buffer::write_some_lines(const Line_Vec& line_vec) { if (!my_impl_ptr) { return false; } return my_impl_ptr->write_some_lines(line_vec); } /*****************************************************************************/ bool File_Buffer::write_buffer(char* buf_ptr, unsigned int num_bytes) { if (!my_impl_ptr) { return false; } return my_impl_ptr->write_buffer(buf_ptr, num_bytes); } /*****************************************************************************/ bool File_Buffer::end_file() { if (!my_impl_ptr) { return false; } return my_impl_ptr->end_file(); } /*****************************************************************************/ bool File_Buffer::read_line(std::string& line_str, bool& at_eof) { if (!my_impl_ptr) { return false; } return my_impl_ptr->read_line(line_str, at_eof); } /*****************************************************************************/ const std::string File_Buffer::file_path_str() { if (!my_impl_ptr) { return std::string(); } return my_impl_ptr->file_path_str(); } /*****************************************************************************/ bool resolve_compression(const std::string& compr_name, File_Buffer::Compression_Type& compr_type, std::string& msg_str) { typedef std::map Str_Compr_Map; typedef Str_Compr_Map::const_iterator Str_Compr_Map_CIter; Str_Compr_Map str_compr_map; str_compr_map["none"] = File_Buffer::compressionNone; str_compr_map["gzip"] = File_Buffer::compressionGzip; str_compr_map["bzip2"] = File_Buffer::compressionBzip2; Str_Compr_Map_CIter match_str_compr_citer(str_compr_map.find(compr_name)); if (str_compr_map.end() == match_str_compr_citer) { msg_str += "compression must be"; for (Str_Compr_Map_CIter str_compr_citer = str_compr_map.begin(); str_compr_citer != str_compr_map.end(); ++str_compr_citer) { msg_str += (((str_compr_citer == str_compr_map.begin()) ? " " : " or ") + str_compr_citer->first); } return false; } compr_type = match_str_compr_citer->second; return true; } /*****************************************************************************/ std::string add_std_extension(const std::string& file_path_str, const File_Buffer::Compression_Type compr_type) { std::string ext_file_path_str(file_path_str); switch (compr_type) { case File_Buffer::compressionNone: break; case File_Buffer::compressionGzip: ext_file_path_str += ".gz"; break; case File_Buffer::compressionBzip2: ext_file_path_str += ".bz2"; break; } return ext_file_path_str; } /*****************************************************************************/