X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=src%2Fapi%2FBamAux.h;h=f4511259ea67136934e736a3cebf0846353d65ed;hb=9f1ce8c47aeadb6dc1320b52ee671c3341b97935;hp=d171e7069db998da82ac346689cea68fee068611;hpb=8c80d760637f8df39262683cd2570f0589423d36;p=bamtools.git diff --git a/src/api/BamAux.h b/src/api/BamAux.h index d171e70..f451125 100644 --- a/src/api/BamAux.h +++ b/src/api/BamAux.h @@ -1,9 +1,8 @@ // *************************************************************************** // BamAux.h (c) 2009 Derek Barnett, Michael Str�mberg // Marth Lab, Department of Biology, Boston College -// All rights reserved. // --------------------------------------------------------------------------- -// Last modified: 4 March 2011 (DB) +// Last modified: 10 October 2011 (DB) // --------------------------------------------------------------------------- // Provides data structures & utility methods that are used throughout the API. // *************************************************************************** @@ -11,7 +10,7 @@ #ifndef BAMAUX_H #define BAMAUX_H -#include +#include "api/api_global.h" #include #include #include @@ -21,6 +20,7 @@ Provides data structures & utility methods that are used throughout the API. */ + /*! \namespace BamTools \brief Contains all BamTools classes & methods. @@ -35,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 @@ -79,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 { @@ -124,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 ); } }; @@ -132,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); @@ -145,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)); @@ -154,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)); @@ -163,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) | @@ -176,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) | @@ -189,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) | @@ -206,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) | @@ -223,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; @@ -233,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; @@ -243,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; @@ -263,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; @@ -276,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; @@ -287,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) { @@ -309,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) { @@ -319,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) { @@ -337,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) { @@ -347,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) { @@ -365,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) { @@ -375,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) { @@ -391,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) { @@ -401,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) { @@ -419,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) { @@ -429,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) { @@ -445,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