]> git.donarmstrong.com Git - bamtools.git/blobdiff - BGZF.h
Minor formatting cleanup in BamIndex.*
[bamtools.git] / BGZF.h
diff --git a/BGZF.h b/BGZF.h
index 29d6d142e1ad53fe8f548a81ceefd30a0215c208..37bcff75bd2a3a93bb9665c21b250f2b69321246 100644 (file)
--- a/BGZF.h
+++ b/BGZF.h
@@ -3,7 +3,7 @@
 // Marth Lab, Department of Biology, Boston College\r
 // All rights reserved.\r
 // ---------------------------------------------------------------------------\r
-// Last modified: 22 June 2010 (DB)\r
+// Last modified: 16 August 2010 (DB)\r
 // ---------------------------------------------------------------------------\r
 // BGZF routines were adapted from the bgzf.c code developed at the Broad\r
 // Institute.\r
 // zlib includes\r
 #include "zlib.h"\r
 \r
+// Platform-specific large-file support\r
+#ifndef BAMTOOLS_LFS\r
+#define BAMTOOLS_LFS\r
+    #ifdef WIN32\r
+        #define ftell64(a)     _ftelli64(a)\r
+        #define fseek64(a,b,c) _fseeki64(a,b,c)\r
+    #else\r
+        #define ftell64(a)     ftello(a)\r
+        #define fseek64(a,b,c) fseeko(a,b,c) \r
+    #endif\r
+#endif // BAMTOOLS_LFS\r
+\r
 // Platform-specific type definitions\r
 #ifndef BAMTOOLS_TYPES\r
 #define BAMTOOLS_TYPES\r
@@ -65,81 +77,77 @@ const int DEFAULT_BLOCK_SIZE  = 65536;
 \r
 struct BgzfData {\r
 \r
-    // ---------------------------------\r
     // data members\r
-    \r
-    unsigned int UncompressedBlockSize;\r
-    unsigned int CompressedBlockSize;\r
-    unsigned int BlockLength;\r
-    unsigned int BlockOffset;\r
-    uint64_t BlockAddress;\r
-    bool     IsOpen;\r
-    bool     IsWriteOnly;\r
-    FILE*    Stream;\r
-    char*    UncompressedBlock;\r
-    char*    CompressedBlock;\r
-\r
-    // ---------------------------------\r
+    public:\r
+        unsigned int UncompressedBlockSize;\r
+        unsigned int CompressedBlockSize;\r
+        unsigned int BlockLength;\r
+        unsigned int BlockOffset;\r
+        uint64_t BlockAddress;\r
+        bool     IsOpen;\r
+        bool     IsWriteOnly;\r
+        bool     IsWriteUncompressed;\r
+        FILE*    Stream;\r
+        char*    UncompressedBlock;\r
+        char*    CompressedBlock;\r
+\r
     // constructor & destructor\r
-    \r
-    BgzfData(void);\r
-    ~BgzfData(void);\r
+    public:\r
+        BgzfData(void);\r
+        ~BgzfData(void);\r
 \r
-    // ---------------------------------\r
     // main interface methods\r
-    \r
-    // closes BGZF file\r
-    void Close(void);\r
-    // opens the BGZF file for reading (mode is either "rb" for reading, or "wb" for writing\r
-    bool Open(const std::string& filename, const char* mode);\r
-    // reads BGZF data into a byte buffer\r
-    int Read(char* data, const unsigned int dataLength);\r
-    // seek to position in BGZF file\r
-    bool Seek(int64_t position);\r
-    // get file position in BGZF file\r
-    int64_t Tell(void);\r
-    // writes the supplied data into the BGZF buffer\r
-    unsigned int Write(const char* data, const unsigned int dataLen);\r
-\r
-    // ---------------------------------\r
+    public:       \r
+        // closes BGZF file\r
+        void Close(void);\r
+        // opens the BGZF file (mode is either "rb" for reading, or "wb" for writing)\r
+        bool Open(const std::string& filename, const char* mode, bool isWriteUncompressed = false);\r
+        // reads BGZF data into a byte buffer\r
+        int Read(char* data, const unsigned int dataLength);\r
+        // seek to position in BGZF file\r
+        bool Seek(int64_t position);\r
+        // get file position in BGZF file\r
+        int64_t Tell(void);\r
+        // writes the supplied data into the BGZF buffer\r
+        unsigned int Write(const char* data, const unsigned int dataLen);\r
+\r
     // internal methods\r
+    private:\r
+        // compresses the current block\r
+        int DeflateBlock(void);\r
+        // flushes the data in the BGZF block\r
+        void FlushBlock(void);\r
+        // de-compresses the current block\r
+        int InflateBlock(const int& blockLength);\r
+        // reads a BGZF block\r
+        bool ReadBlock(void);\r
     \r
-    // compresses the current block\r
-    int DeflateBlock(void);\r
-    // flushes the data in the BGZF block\r
-    void FlushBlock(void);\r
-    // de-compresses the current block\r
-    int InflateBlock(const int& blockLength);\r
-    // reads a BGZF block\r
-    bool ReadBlock(void);\r
-    \r
-    // ---------------------------------\r
     // static 'utility' methods\r
-    \r
-    // checks BGZF block header\r
-    static inline bool CheckBlockHeader(char* header);\r
-    // packs an unsigned integer into the specified buffer\r
-    static inline void PackUnsignedInt(char* buffer, unsigned int value);\r
-    // packs an unsigned short into the specified buffer\r
-    static inline void PackUnsignedShort(char* buffer, unsigned short value);\r
-    // unpacks a buffer into a double\r
-    static inline double UnpackDouble(char* buffer);\r
-    static inline double UnpackDouble(const char* buffer);\r
-    // unpacks a buffer into a float\r
-    static inline float UnpackFloat(char* buffer);\r
-    static inline float UnpackFloat(const char* buffer);\r
-    // unpacks a buffer into a signed int\r
-    static inline signed int UnpackSignedInt(char* buffer);\r
-    static inline signed int UnpackSignedInt(const char* buffer);\r
-    // unpacks a buffer into a signed short\r
-    static inline signed short UnpackSignedShort(char* buffer);\r
-    static inline signed short UnpackSignedShort(const char* buffer);\r
-    // unpacks a buffer into an unsigned int\r
-    static inline unsigned int UnpackUnsignedInt(char* buffer);\r
-    static inline unsigned int UnpackUnsignedInt(const char* buffer);\r
-    // unpacks a buffer into an unsigned short\r
-    static inline unsigned short UnpackUnsignedShort(char* buffer);\r
-    static inline unsigned short UnpackUnsignedShort(const char* buffer);\r
+    public:\r
+        // checks BGZF block header\r
+        static inline bool CheckBlockHeader(char* header);\r
+        // packs an unsigned integer into the specified buffer\r
+        static inline void PackUnsignedInt(char* buffer, unsigned int value);\r
+        // packs an unsigned short into the specified buffer\r
+        static inline void PackUnsignedShort(char* buffer, unsigned short value);\r
+        // unpacks a buffer into a double\r
+        static inline double UnpackDouble(char* buffer);\r
+        static inline double UnpackDouble(const char* buffer);\r
+        // unpacks a buffer into a float\r
+        static inline float UnpackFloat(char* buffer);\r
+        static inline float UnpackFloat(const char* buffer);\r
+        // unpacks a buffer into a signed int\r
+        static inline signed int UnpackSignedInt(char* buffer);\r
+        static inline signed int UnpackSignedInt(const char* buffer);\r
+        // unpacks a buffer into a signed short\r
+        static inline signed short UnpackSignedShort(char* buffer);\r
+        static inline signed short UnpackSignedShort(const char* buffer);\r
+        // unpacks a buffer into an unsigned int\r
+        static inline unsigned int UnpackUnsignedInt(char* buffer);\r
+        static inline unsigned int UnpackUnsignedInt(const char* buffer);\r
+        // unpacks a buffer into an unsigned short\r
+        static inline unsigned short UnpackUnsignedShort(char* buffer);\r
+        static inline unsigned short UnpackUnsignedShort(const char* buffer);\r
 };\r
 \r
 // -------------------------------------------------------------\r