X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=src%2Fapi%2Finternal%2FBgzfStream_p.h;h=88d7472eeebfa81bed6cd2021841a2534877b7ac;hb=9f1ce8c47aeadb6dc1320b52ee671c3341b97935;hp=04b6c34b88c0d122e3bc43f966b1cbafc4d39108;hpb=243a21d278e81d0a05997ad8bef109153443fb75;p=bamtools.git diff --git a/src/api/internal/BgzfStream_p.h b/src/api/internal/BgzfStream_p.h index 04b6c34..88d7472 100644 --- a/src/api/internal/BgzfStream_p.h +++ b/src/api/internal/BgzfStream_p.h @@ -1,9 +1,8 @@ // *************************************************************************** // BgzfStream_p.h (c) 2011 Derek Barnett // Marth Lab, Department of Biology, Boston College -// All rights reserved. // --------------------------------------------------------------------------- -// Last modified: 5 April 2011(DB) +// Last modified: 10 October 2011(DB) // --------------------------------------------------------------------------- // Based on BGZF routines developed at the Broad Institute. // Provides the basic functionality for reading & writing BGZF files @@ -23,11 +22,8 @@ // // We mean it. -#include -#include -#include -#include "zlib.h" -#include +#include "api/api_global.h" +#include "api/IBamIODevice.h" #include namespace BamTools { @@ -44,14 +40,14 @@ class BgzfStream { public: // closes BGZF file void Close(void); + // returns true if BgzfStream open for IO bool IsOpen(void) const; - // opens the BGZF stream in requested mode - bool Open(const std::string& filename, const char* mode); - bool Open(const std::string& filename, const IBamIODevice::OpenMode mode); + // opens the BGZF file + void Open(const std::string& filename, const IBamIODevice::OpenMode mode); // reads BGZF data into a byte buffer - unsigned int Read(char* data, const unsigned int dataLength); + size_t Read(char* data, const size_t dataLength); // seek to position in BGZF file - bool Seek(const int64_t& position); + void Seek(const int64_t& position); // sets IO device (closes previous, if any, but does not attempt to open) void SetIODevice(IBamIODevice* device); // enable/disable compressed output @@ -59,58 +55,41 @@ class BgzfStream { // get file position in BGZF file int64_t Tell(void) const; // writes the supplied data into the BGZF buffer - unsigned int Write(const char* data, const unsigned int dataLength); + size_t Write(const char* data, const size_t dataLength); // internal methods private: // compresses the current block - unsigned int DeflateBlock(void); + size_t DeflateBlock(void); // flushes the data in the BGZF block void FlushBlock(void); // de-compresses the current block - int InflateBlock(const int& blockLength); + size_t InflateBlock(const size_t& blockLength); // reads a BGZF block - bool ReadBlock(void); + void ReadBlock(void); // static 'utility' methods public: // checks BGZF block header - static inline bool CheckBlockHeader(char* header); + static bool CheckBlockHeader(char* header); // data members public: - unsigned int m_uncompressedBlockSize; - unsigned int m_compressedBlockSize; unsigned int m_blockLength; unsigned int m_blockOffset; uint64_t m_blockAddress; - char* m_uncompressedBlock; - char* m_compressedBlock; - - bool m_isOpen; - bool m_isWriteOnly; bool m_isWriteCompressed; - IBamIODevice* m_device; - FILE* m_stream; -}; -// ------------------------------------------------------------- -// static 'utility' method implementations - -// checks BGZF block header -inline -bool BgzfStream::CheckBlockHeader(char* header) { - return (header[0] == Constants::GZIP_ID1 && - header[1] == (char)Constants::GZIP_ID2 && - header[2] == Z_DEFLATED && - (header[3] & Constants::FLG_FEXTRA) != 0 && - BamTools::UnpackUnsignedShort(&header[10]) == Constants::BGZF_XLEN && - header[12] == Constants::BGZF_ID1 && - header[13] == Constants::BGZF_ID2 && - BamTools::UnpackUnsignedShort(&header[14]) == Constants::BGZF_LEN ); -} + struct RaiiWrapper { + RaiiWrapper(void); + ~RaiiWrapper(void); + char* UncompressedBlock; + char* CompressedBlock; + }; + RaiiWrapper Resources; +}; } // namespace Internal } // namespace BamTools