// -*- c++ -*- /*****************************************************************************/ // 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). /*****************************************************************************/ #ifndef FILE_BUFFER_IMPL_H #define FILE_BUFFER_IMPL_H /*****************************************************************************/ #include #include #include "config.h" #if defined(HAVE_ZLIB) #include #endif #if defined(HAVE_BZLIB) #include #endif #include "common/File_Buffer.h" /*****************************************************************************/ struct File_Hndl { typedef enum { NONE, READ, WRITE } File_Use; File_Hndl() : my_compression_type(File_Buffer::compressionNone), my_file_use(NONE), my_file_hndl(0) #if defined(HAVE_ZLIB) , my_gz_file_hndl(0) #endif #if defined(HAVE_BZLIB) , my_bz2_file_hndl(0) #endif { } File_Buffer::Compression_Type my_compression_type; File_Use my_file_use; FILE* my_file_hndl; #if defined(HAVE_ZLIB) gzFile my_gz_file_hndl; #endif #if defined(HAVE_BZLIB) BZFILE* my_bz2_file_hndl; // N.B. : for bzip2 also need my_file_hndl. #endif }; /*****************************************************************************/ class File_Buffer_Impl { public: File_Buffer_Impl(const std::string& file_path_str, File_Buffer::Compression_Type compression_type); virtual ~File_Buffer_Impl(); bool write_some_lines(const File_Buffer::Line_Vec& line_vec); bool write_buffer(char* buf_ptr, unsigned int num_bytes); bool end_file(); bool read_line(std::string& line_str, bool& at_eof); const std::string file_path_str() { return my_file_path_str; } private: bool read_some_lines(File_Buffer::Line_Vec& line_vec, bool& at_eof); std::string my_file_path_str; File_Hndl my_file_hndl; bool my_file_is_open; std::string my_left_over_str; // Cache for use by read_line. File_Buffer::Line_Vec my_read_line_vec; File_Buffer::Line_Vec_CIter my_read_line_citer; bool my_eof_is_pending; }; /*****************************************************************************/ #endif // ! FILE_BUFFER_IMPL_H /*****************************************************************************/