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