// BamAux.h (c) 2009 Derek Barnett, Michael Str�mberg\r
// Marth Lab, Department of Biology, Boston College\r
// ---------------------------------------------------------------------------\r
-// Last modified: 8 October 2011 (DB)\r
+// Last modified: 25 October 2011 (DB)\r
// ---------------------------------------------------------------------------\r
// Provides data structures & utility methods that are used throughout the API.\r
// ***************************************************************************\r
#ifndef BAMAUX_H\r
#define BAMAUX_H\r
\r
-#include <api/api_global.h>\r
+#include "api/api_global.h"\r
+#include <cstring>\r
#include <fstream> \r
#include <iostream>\r
#include <string>\r
\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
/*! \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
\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. I whole-heartedly apologize for any inconsistencies this\r
- may have caused if you assumed that BT was always half-open; full aplogies also\r
- to those who recognized that BamTools originally used a closed interval, but may\r
- need to update their code to reflect this new change.\r
+ as zero-based, CLOSED.\r
*/\r
struct API_EXPORT BamRegion {\r
\r
// 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
\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
\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
\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
\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
\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
\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
\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
\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
\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
/*! \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
/*! \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
/*! \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
\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
/*! \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
\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
/*! \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
\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
/*! \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
\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
/*! \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
\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
/*! \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
\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
// ----------------------------------------------------------------\r
// 'internal' helper structs\r
\r
+/*! \struct RaiiBuffer\r
+ \internal\r
+*/\r
struct RaiiBuffer {\r
- RaiiBuffer(const unsigned int n)\r
+\r
+ // data members\r
+ char* Buffer;\r
+ const size_t NumBytes;\r
+\r
+ // ctor & dtor\r
+ RaiiBuffer(const size_t n)\r
: Buffer( new char[n]() )\r
+ , NumBytes(n)\r
{ }\r
+\r
~RaiiBuffer(void) {\r
delete[] Buffer;\r
}\r
- char* Buffer;\r
+\r
+ // add'l methods\r
+ void Clear(void) {\r
+ memset(Buffer, 0, NumBytes);\r
+ }\r
};\r
\r
} // namespace BamTools\r