]> git.donarmstrong.com Git - bamtools.git/blobdiff - src/api/BamAux.h
Cleaned up intra-API includes & moved version numbers to 2.0.0
[bamtools.git] / src / api / BamAux.h
index 4c5a99aca66eb76d3e0646f152ff25bf402cbdae..f4511259ea67136934e736a3cebf0846353d65ed 100644 (file)
@@ -2,7 +2,7 @@
 // BamAux.h (c) 2009 Derek Barnett, Michael Str�mberg\r
 // Marth Lab, Department of Biology, Boston College\r
 // ---------------------------------------------------------------------------\r
-// Last modified: 4 March 2011 (DB)\r
+// Last modified: 10 October 2011 (DB)\r
 // ---------------------------------------------------------------------------\r
 // Provides data structures & utility methods that are used throughout the API.\r
 // ***************************************************************************\r
@@ -10,7 +10,7 @@
 #ifndef BAMAUX_H\r
 #define BAMAUX_H\r
 \r
-#include <api/api_global.h>\r
+#include "api/api_global.h"\r
 #include <fstream> \r
 #include <iostream>\r
 #include <string>\r
@@ -20,6 +20,7 @@
 \r
     Provides data structures & utility methods that are used throughout the API.\r
 */\r
+\r
 /*! \namespace BamTools\r
     \brief Contains all BamTools classes & methods.\r
 \r
@@ -34,11 +35,11 @@ namespace BamTools {
 /*! \struct BamTools::CigarOp\r
     \brief Represents a CIGAR alignment operation.\r
 \r
-    \sa http://samtools.sourceforge.net/SAM-1.3.pdf for more details on using CIGAR operations.\r
+    \sa \samSpecURL for more details on using CIGAR operations.\r
 */\r
 struct API_EXPORT CigarOp {\r
   \r
-    char     Type;   //!< CIGAR operation type (MIDNSHP)\r
+    char     Type;   //!< CIGAR operation type (MIDNSHPX=)\r
     uint32_t Length; //!< CIGAR operation length (number of bases)\r
     \r
     //! constructor\r
@@ -78,6 +79,10 @@ typedef std::vector<RefData> RefVector;
     \brief Represents a sequential genomic region\r
 \r
     Allowed to span multiple (sequential) references.\r
+\r
+    \warning BamRegion now represents a zero-based, HALF-OPEN interval.\r
+    In previous versions of BamTools (0.x & 1.x) all intervals were treated\r
+    as zero-based, CLOSED.\r
 */\r
 struct API_EXPORT BamRegion {\r
   \r
@@ -123,7 +128,7 @@ struct API_EXPORT BamRegion {
 \r
     //! Returns true if region has a right boundary\r
     bool isRightBoundSpecified(void) const {\r
-        return ( RightRefID >= 0 && RightPosition >= 0 );\r
+        return ( RightRefID >= 0 && RightPosition >= 1 );\r
     }\r
 };\r
 \r
@@ -131,11 +136,7 @@ struct API_EXPORT BamRegion {
 // General utility methods\r
 \r
 /*! \fn bool FileExists(const std::string& filename)\r
-    \brief checks if file exists\r
-\r
-    Attempts to open file in a read-only mode.\r
-\r
-    \return \c true if file can be opened successfully\r
+    \brief returns true if the file exists\r
 */\r
 API_EXPORT inline bool FileExists(const std::string& filename) {\r
     std::ifstream f(filename.c_str(), std::ifstream::in);\r
@@ -144,8 +145,6 @@ API_EXPORT inline bool FileExists(const std::string& filename) {
 \r
 /*! \fn void SwapEndian_16(int16_t& x)\r
     \brief swaps endianness of signed 16-bit integer, in place\r
-\r
-    Swaps endian representation of value in \a x.\r
 */\r
 API_EXPORT inline void SwapEndian_16(int16_t& x) {\r
     x = ((x >> 8) | (x << 8));\r
@@ -153,8 +152,6 @@ API_EXPORT inline void SwapEndian_16(int16_t& x) {
 \r
 /*! \fn void SwapEndian_16(uint16_t& x)\r
     \brief swaps endianness of unsigned 16-bit integer, in place\r
-\r
-    Swaps endian representation of value in \a x.\r
 */\r
 API_EXPORT inline void SwapEndian_16(uint16_t& x) {\r
     x = ((x >> 8) | (x << 8));\r
@@ -162,8 +159,6 @@ API_EXPORT inline void SwapEndian_16(uint16_t& x) {
 \r
 /*! \fn void SwapEndian_32(int32_t& x)\r
     \brief swaps endianness of signed 32-bit integer, in place\r
-\r
-    Swaps endian representation of value in \a x.\r
 */\r
 API_EXPORT inline void SwapEndian_32(int32_t& x) {\r
     x = ( (x >> 24) | \r
@@ -175,8 +170,6 @@ API_EXPORT inline void SwapEndian_32(int32_t& x) {
 \r
 /*! \fn void SwapEndian_32(uint32_t& x)\r
     \brief swaps endianness of unsigned 32-bit integer, in place\r
-\r
-    Swaps endian representation of value in \a x.\r
 */\r
 API_EXPORT inline void SwapEndian_32(uint32_t& x) {\r
     x = ( (x >> 24) | \r
@@ -188,8 +181,6 @@ API_EXPORT inline void SwapEndian_32(uint32_t& x) {
 \r
 /*! \fn void SwapEndian_64(int64_t& x)\r
     \brief swaps endianness of signed 64-bit integer, in place\r
-\r
-    Swaps endian representation of value in \a x.\r
 */\r
 API_EXPORT inline void SwapEndian_64(int64_t& x) {\r
     x = ( (x >> 56) | \r
@@ -205,8 +196,6 @@ API_EXPORT inline void SwapEndian_64(int64_t& x) {
 \r
 /*! \fn void SwapEndian_64(uint64_t& x)\r
     \brief swaps endianness of unsigned 64-bit integer, in place\r
-\r
-    Swaps endian representation of value in \a x.\r
 */\r
 API_EXPORT inline void SwapEndian_64(uint64_t& x) {\r
     x = ( (x >> 56) | \r
@@ -222,8 +211,6 @@ API_EXPORT inline void SwapEndian_64(uint64_t& x) {
 \r
 /*! \fn void SwapEndian_16p(char* data)\r
     \brief swaps endianness of the next 2 bytes in a buffer, in place\r
-\r
-    Swaps endian representation the next 2 bytes in \a data.\r
 */\r
 API_EXPORT inline void SwapEndian_16p(char* data) {\r
     uint16_t& value = (uint16_t&)*data; \r
@@ -232,8 +219,6 @@ API_EXPORT inline void SwapEndian_16p(char* data) {
 \r
 /*! \fn void SwapEndian_32p(char* data)\r
     \brief swaps endianness of the next 4 bytes in a buffer, in place\r
-\r
-    Swaps endian representation the next 4 bytes in \a data.\r
 */\r
 API_EXPORT inline void SwapEndian_32p(char* data) {\r
     uint32_t& value = (uint32_t&)*data; \r
@@ -242,8 +227,6 @@ API_EXPORT inline void SwapEndian_32p(char* data) {
 \r
 /*! \fn void SwapEndian_64p(char* data)\r
     \brief swaps endianness of the next 8 bytes in a buffer, in place\r
-\r
-    Swaps endian representation the next 8 bytes in \a data.\r
 */\r
 API_EXPORT inline void SwapEndian_64p(char* data) {\r
     uint64_t& value = (uint64_t&)*data; \r
@@ -262,8 +245,8 @@ API_EXPORT inline bool SystemIsBigEndian(void) {
 /*! \fn void PackUnsignedInt(char* buffer, unsigned int value)\r
     \brief stores unsigned integer value in a byte buffer\r
 \r
-    \param buffer destination buffer\r
-    \param value  unsigned integer to 'pack' in buffer\r
+    \param[out] buffer destination buffer\r
+    \param[in]  value  value to 'pack' in buffer\r
 */\r
 API_EXPORT inline void PackUnsignedInt(char* buffer, unsigned int value) {\r
     buffer[0] = (char)value;\r
@@ -275,8 +258,8 @@ API_EXPORT inline void PackUnsignedInt(char* buffer, unsigned int value) {
 /*! \fn void PackUnsignedShort(char* buffer, unsigned short value)\r
     \brief stores unsigned short integer value in a byte buffer\r
 \r
-    \param buffer destination buffer\r
-    \param value  unsigned short integer to 'pack' in buffer\r
+    \param[out] buffer destination buffer\r
+    \param[in]  value  value to 'pack' in buffer\r
 */\r
 API_EXPORT inline void PackUnsignedShort(char* buffer, unsigned short value) {\r
     buffer[0] = (char)value;\r
@@ -286,7 +269,7 @@ API_EXPORT inline void PackUnsignedShort(char* buffer, unsigned short value) {
 /*! \fn double UnpackDouble(const char* buffer)\r
     \brief reads a double value from byte buffer\r
 \r
-    \param buffer source byte buffer\r
+    \param[in] buffer source byte buffer\r
     \return the (double) value read from the buffer\r
 */\r
 API_EXPORT inline double UnpackDouble(const char* buffer) {\r
@@ -308,7 +291,7 @@ API_EXPORT inline double UnpackDouble(const char* buffer) {
 \r
     This is an overloaded function.\r
 \r
-    \param buffer source byte buffer\r
+    \param[in] buffer source byte buffer\r
     \return the (double) value read from the buffer\r
 */\r
 API_EXPORT inline double UnpackDouble(char* buffer) {\r
@@ -318,7 +301,7 @@ API_EXPORT inline double UnpackDouble(char* buffer) {
 /*! \fn double UnpackFloat(const char* buffer)\r
     \brief reads a float value from byte buffer\r
 \r
-    \param buffer source byte buffer\r
+    \param[in] buffer source byte buffer\r
     \return the (float) value read from the buffer\r
 */\r
 API_EXPORT inline float UnpackFloat(const char* buffer) {\r
@@ -336,7 +319,7 @@ API_EXPORT inline float UnpackFloat(const char* buffer) {
 \r
     This is an overloaded function.\r
 \r
-    \param buffer source byte buffer\r
+    \param[in] buffer source byte buffer\r
     \return the (float) value read from the buffer\r
 */\r
 API_EXPORT inline float UnpackFloat(char* buffer) {\r
@@ -346,7 +329,7 @@ API_EXPORT inline float UnpackFloat(char* buffer) {
 /*! \fn signed int UnpackSignedInt(const char* buffer)\r
     \brief reads a signed integer value from byte buffer\r
 \r
-    \param buffer source byte buffer\r
+    \param[in] buffer source byte buffer\r
     \return the (signed int) value read from the buffer\r
 */\r
 API_EXPORT inline signed int UnpackSignedInt(const char* buffer) {\r
@@ -364,7 +347,7 @@ API_EXPORT inline signed int UnpackSignedInt(const char* buffer) {
 \r
     This is an overloaded function.\r
 \r
-    \param buffer source byte buffer\r
+    \param[in] buffer source byte buffer\r
     \return the (signed int) value read from the buffer\r
 */\r
 API_EXPORT inline signed int UnpackSignedInt(char* buffer) {\r
@@ -374,7 +357,7 @@ API_EXPORT inline signed int UnpackSignedInt(char* buffer) {
 /*! \fn signed short UnpackSignedShort(const char* buffer)\r
     \brief reads a signed short integer value from byte buffer\r
 \r
-    \param buffer source byte buffer\r
+    \param[in] buffer source byte buffer\r
     \return the (signed short) value read from the buffer\r
 */\r
 API_EXPORT inline signed short UnpackSignedShort(const char* buffer) {\r
@@ -390,7 +373,7 @@ API_EXPORT inline signed short UnpackSignedShort(const char* buffer) {
 \r
     This is an overloaded function.\r
 \r
-    \param buffer source byte buffer\r
+    \param[in] buffer source byte buffer\r
     \return the (signed short) value read from the buffer\r
 */\r
 API_EXPORT inline signed short UnpackSignedShort(char* buffer) {\r
@@ -400,7 +383,7 @@ API_EXPORT inline signed short UnpackSignedShort(char* buffer) {
 /*! \fn unsigned int UnpackUnsignedInt(const char* buffer)\r
     \brief reads an unsigned integer value from byte buffer\r
 \r
-    \param buffer source byte buffer\r
+    \param[in] buffer source byte buffer\r
     \return the (unsigned int) value read from the buffer\r
 */\r
 API_EXPORT inline unsigned int UnpackUnsignedInt(const char* buffer) {\r
@@ -418,7 +401,7 @@ API_EXPORT inline unsigned int UnpackUnsignedInt(const char* buffer) {
 \r
     This is an overloaded function.\r
 \r
-    \param buffer source byte buffer\r
+    \param[in] buffer source byte buffer\r
     \return the (unsigned int) value read from the buffer\r
 */\r
 API_EXPORT inline unsigned int UnpackUnsignedInt(char* buffer) {\r
@@ -428,7 +411,7 @@ API_EXPORT inline unsigned int UnpackUnsignedInt(char* buffer) {
 /*! \fn unsigned short UnpackUnsignedShort(const char* buffer)\r
     \brief reads an unsigned short integer value from byte buffer\r
 \r
-    \param buffer source byte buffer\r
+    \param[in] buffer source byte buffer\r
     \return the (unsigned short) value read from the buffer\r
 */\r
 API_EXPORT inline unsigned short UnpackUnsignedShort(const char* buffer) {\r
@@ -444,13 +427,29 @@ API_EXPORT inline unsigned short UnpackUnsignedShort(const char* buffer) {
 \r
     This is an overloaded function.\r
 \r
-    \param buffer source byte buffer\r
+    \param[in] buffer source byte buffer\r
     \return the (unsigned short) value read from the buffer\r
 */\r
 API_EXPORT inline unsigned short UnpackUnsignedShort(char* buffer) {\r
     return UnpackUnsignedShort( (const char*)buffer );\r
 }\r
 \r
+// ----------------------------------------------------------------\r
+// 'internal' helper structs\r
+\r
+/*! \struct RaiiBuffer\r
+    \internal\r
+*/\r
+struct RaiiBuffer {\r
+    RaiiBuffer(const size_t n)\r
+        : Buffer( new char[n]() )\r
+    { }\r
+    ~RaiiBuffer(void) {\r
+        delete[] Buffer;\r
+    }\r
+    char* Buffer;\r
+};\r
+\r
 } // namespace BamTools\r
 \r
 #endif // BAMAUX_H\r