]> git.donarmstrong.com Git - bamtools.git/blobdiff - BGZF.h
further cleanup of duplicate @RG tag warning reporting
[bamtools.git] / BGZF.h
diff --git a/BGZF.h b/BGZF.h
index 289654279d91260aae08754cdfd7c15cb0f4d789..0cca24ccc344b893a04705f791d0de06d50ce090 100644 (file)
--- a/BGZF.h
+++ b/BGZF.h
@@ -1,9 +1,9 @@
 // ***************************************************************************\r
-// BGZF.h (c) 2009 Derek Barnett, Michael Strömberg\r
+// BGZF.h (c) 2009 Derek Barnett, Michael Strmberg\r
 // Marth Lab, Department of Biology, Boston College\r
 // All rights reserved.\r
 // ---------------------------------------------------------------------------\r
-// Last modified: 8 December 2009 (DB)\r
+// Last modified: 11 January 2010 (DB)\r
 // ---------------------------------------------------------------------------\r
 // BGZF routines were adapted from the bgzf.c code developed at the Broad\r
 // Institute.\r
 #include "zlib.h"\r
 \r
 // Platform-specific type definitions\r
-#ifdef _MSC_VER\r
-        typedef char                 int8_t;\r
-        typedef unsigned char       uint8_t;\r
-        typedef short               int16_t;\r
-        typedef unsigned short     uint16_t;\r
-        typedef int                 int32_t;\r
-        typedef unsigned int       uint32_t;\r
-        typedef long long           int64_t;\r
-        typedef unsigned long long uint64_t;\r
-#else\r
-        #include <stdint.h>\r
-#endif\r
+#ifndef BAMTOOLS_TYPES\r
+#define BAMTOOLS_TYPES\r
+       #ifdef _MSC_VER\r
+               typedef char                 int8_t;\r
+               typedef unsigned char       uint8_t;\r
+               typedef short               int16_t;\r
+               typedef unsigned short     uint16_t;\r
+               typedef int                 int32_t;\r
+               typedef unsigned int       uint32_t;\r
+               typedef long long           int64_t;\r
+               typedef unsigned long long uint64_t;\r
+       #else\r
+               #include <stdint.h>\r
+       #endif\r
+#endif // BAMTOOLS_TYPES\r
 \r
 namespace BamTools {\r
 \r
@@ -105,19 +108,38 @@ struct BgzfData {
     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
+    \r
     // unpacks a buffer into a signed int\r
     static inline signed int UnpackSignedInt(char* buffer);\r
-    // unpacks a buffer into a unsigned int\r
+    // unpacks a buffer into an unsigned int\r
     static inline unsigned int UnpackUnsignedInt(char* buffer);\r
-    // unpacks a buffer into a unsigned short\r
+    // unpacks a buffer into a signed short\r
+    static inline signed short UnpackSignedShort(char* buffer);\r
+    // unpacks a buffer into an unsigned short\r
     static inline unsigned short UnpackUnsignedShort(char* buffer);\r
+    // unpacks a buffer into a double\r
+    static inline double UnpackDouble(char* buffer);\r
+    // unpacks a buffer into a float\r
+    static inline float UnpackFloat(char* buffer); \r
+    \r
+    // unpacks a buffer into a signed int\r
+    static inline signed int UnpackSignedInt(const char* buffer);\r
+    // unpacks a buffer into an unsigned int\r
+    static inline unsigned int UnpackUnsignedInt(const char* buffer);\r
+    // unpacks a buffer into a signed short\r
+    static inline signed short UnpackSignedShort(const char* buffer);\r
+    // unpacks a buffer into an unsigned short\r
+    static inline unsigned short UnpackUnsignedShort(const char* buffer);\r
+    // unpacks a buffer into a double\r
+    static inline double UnpackDouble(const char* buffer);\r
+    // unpacks a buffer into a float\r
+    static inline float UnpackFloat(const char* buffer); \r
 };\r
 \r
 // -------------------------------------------------------------\r
 \r
 inline\r
 bool BgzfData::CheckBlockHeader(char* header) {\r
-\r
     return (header[0] == GZIP_ID1 &&\r
             header[1] == (char)GZIP_ID2 &&\r
             header[2] == Z_DEFLATED &&\r
@@ -128,7 +150,7 @@ bool BgzfData::CheckBlockHeader(char* header) {
             BgzfData::UnpackUnsignedShort(&header[14]) == BGZF_LEN );\r
 }\r
 \r
-// packs an unsigned integer into the specified buffer\r
+// 'packs' an unsigned integer into the specified buffer\r
 inline\r
 void BgzfData::PackUnsignedInt(char* buffer, unsigned int value) {\r
     buffer[0] = (char)value;\r
@@ -137,14 +159,14 @@ void BgzfData::PackUnsignedInt(char* buffer, unsigned int value) {
     buffer[3] = (char)(value >> 24);\r
 }\r
 \r
-// packs an unsigned short into the specified buffer\r
+// 'packs' an unsigned short into the specified buffer\r
 inline\r
 void BgzfData::PackUnsignedShort(char* buffer, unsigned short value) {\r
     buffer[0] = (char)value;\r
     buffer[1] = (char)(value >> 8);\r
 }\r
 \r
-// unpacks a buffer into a signed int\r
+// 'unpacks' a buffer into a signed int\r
 inline\r
 signed int BgzfData::UnpackSignedInt(char* buffer) {\r
     union { signed int value; unsigned char valueBuffer[sizeof(signed int)]; } un;\r
@@ -156,7 +178,7 @@ signed int BgzfData::UnpackSignedInt(char* buffer) {
     return un.value;\r
 }\r
 \r
-// unpacks a buffer into an unsigned int\r
+// 'unpacks' a buffer into an unsigned int\r
 inline\r
 unsigned int BgzfData::UnpackUnsignedInt(char* buffer) {\r
     union { unsigned int value; unsigned char valueBuffer[sizeof(unsigned int)]; } un;\r
@@ -168,13 +190,125 @@ unsigned int BgzfData::UnpackUnsignedInt(char* buffer) {
     return un.value;\r
 }\r
 \r
-// unpacks a buffer into an unsigned short\r
+// 'unpacks' a buffer into a signed short\r
+inline\r
+signed short BgzfData::UnpackSignedShort(char* buffer) {\r
+    union { signed short value; unsigned char valueBuffer[sizeof(signed short)]; } un;\r
+    un.value = 0;\r
+    un.valueBuffer[0] = buffer[0];\r
+    un.valueBuffer[1] = buffer[1];\r
+    return un.value;\r
+}\r
+\r
+// 'unpacks' a buffer into an unsigned short\r
 inline\r
 unsigned short BgzfData::UnpackUnsignedShort(char* buffer) {\r
-    union { unsigned short value; unsigned char valueBuffer[sizeof(unsigned short)];} un;\r
+    union { unsigned short value; unsigned char valueBuffer[sizeof(unsigned short)]; } un;\r
+    un.value = 0;\r
+    un.valueBuffer[0] = buffer[0];\r
+    un.valueBuffer[1] = buffer[1];\r
+    return un.value;\r
+}\r
+\r
+// 'unpacks' a buffer into a double\r
+inline\r
+double BgzfData::UnpackDouble(char* buffer) {\r
+    union { double value; unsigned char valueBuffer[sizeof(double)]; } un;\r
+    un.value = 0;\r
+    un.valueBuffer[0] = buffer[0];\r
+    un.valueBuffer[1] = buffer[1];\r
+    un.valueBuffer[2] = buffer[2];\r
+    un.valueBuffer[3] = buffer[3];\r
+    un.valueBuffer[4] = buffer[4];\r
+    un.valueBuffer[5] = buffer[5];\r
+    un.valueBuffer[6] = buffer[6];\r
+    un.valueBuffer[7] = buffer[7];\r
+    return un.value;\r
+}\r
+\r
+// 'unpacks' a buffer into a float\r
+inline\r
+float BgzfData::UnpackFloat(char* buffer) {\r
+    union { float value; unsigned char valueBuffer[sizeof(float)]; } un;\r
+    un.value = 0;\r
+    un.valueBuffer[0] = buffer[0];\r
+    un.valueBuffer[1] = buffer[1];\r
+    un.valueBuffer[2] = buffer[2];\r
+    un.valueBuffer[3] = buffer[3];\r
+    return un.value;\r
+}\r
+\r
+// ---------\r
+\r
+// 'unpacks' a buffer into a signed int\r
+inline\r
+signed int BgzfData::UnpackSignedInt(const char* buffer) {\r
+    union { signed int value; unsigned char valueBuffer[sizeof(signed int)]; } un;\r
+    un.value = 0;\r
+    un.valueBuffer[0] = buffer[0];\r
+    un.valueBuffer[1] = buffer[1];\r
+    un.valueBuffer[2] = buffer[2];\r
+    un.valueBuffer[3] = buffer[3];\r
+    return un.value;\r
+}\r
+\r
+// 'unpacks' a buffer into an unsigned int\r
+inline\r
+unsigned int BgzfData::UnpackUnsignedInt(const char* buffer) {\r
+    union { unsigned int value; unsigned char valueBuffer[sizeof(unsigned int)]; } un;\r
+    un.value = 0;\r
+    un.valueBuffer[0] = buffer[0];\r
+    un.valueBuffer[1] = buffer[1];\r
+    un.valueBuffer[2] = buffer[2];\r
+    un.valueBuffer[3] = buffer[3];\r
+    return un.value;\r
+}\r
+\r
+// 'unpacks' a buffer into a signed short\r
+inline\r
+signed short BgzfData::UnpackSignedShort(const char* buffer) {\r
+    union { signed short value; unsigned char valueBuffer[sizeof(signed short)]; } un;\r
+    un.value = 0;\r
+    un.valueBuffer[0] = buffer[0];\r
+    un.valueBuffer[1] = buffer[1];\r
+    return un.value;\r
+}\r
+\r
+// 'unpacks' a buffer into an unsigned short\r
+inline\r
+unsigned short BgzfData::UnpackUnsignedShort(const char* buffer) {\r
+    union { unsigned short value; unsigned char valueBuffer[sizeof(unsigned short)]; } un;\r
+    un.value = 0;\r
+    un.valueBuffer[0] = buffer[0];\r
+    un.valueBuffer[1] = buffer[1];\r
+    return un.value;\r
+}\r
+\r
+// 'unpacks' a buffer into a double\r
+inline\r
+double BgzfData::UnpackDouble(const char* buffer) {\r
+    union { double value; unsigned char valueBuffer[sizeof(double)]; } un;\r
+    un.value = 0;\r
+    un.valueBuffer[0] = buffer[0];\r
+    un.valueBuffer[1] = buffer[1];\r
+    un.valueBuffer[2] = buffer[2];\r
+    un.valueBuffer[3] = buffer[3];\r
+    un.valueBuffer[4] = buffer[4];\r
+    un.valueBuffer[5] = buffer[5];\r
+    un.valueBuffer[6] = buffer[6];\r
+    un.valueBuffer[7] = buffer[7];\r
+    return un.value;\r
+}\r
+\r
+// 'unpacks' a buffer into a float\r
+inline\r
+float BgzfData::UnpackFloat(const char* buffer) {\r
+    union { float value; unsigned char valueBuffer[sizeof(float)]; } un;\r
     un.value = 0;\r
     un.valueBuffer[0] = buffer[0];\r
     un.valueBuffer[1] = buffer[1];\r
+    un.valueBuffer[2] = buffer[2];\r
+    un.valueBuffer[3] = buffer[3];\r
     return un.value;\r
 }\r
 \r