X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=src%2Fapi%2Finternal%2FBamPipe_p.cpp;h=e13ad7c759c6c1cce5870dfe83465fde1513836f;hb=8b4c010999a8d0c482d84bbf17c98dc4bbae02b7;hp=6bfbf6f7397bc0ff558b7b0b73d827bb5bf3ad6d;hpb=88577e25bbf4b6b43642cb679c5f9f5cba026fec;p=bamtools.git diff --git a/src/api/internal/BamPipe_p.cpp b/src/api/internal/BamPipe_p.cpp index 6bfbf6f..e13ad7c 100644 --- a/src/api/internal/BamPipe_p.cpp +++ b/src/api/internal/BamPipe_p.cpp @@ -2,40 +2,22 @@ // BamPipe_p.cpp (c) 2011 Derek Barnett // Marth Lab, Department of Biology, Boston College // --------------------------------------------------------------------------- -// Last modified: 8 September 2011 (DB) +// Last modified: 10 October 2011 (DB) // --------------------------------------------------------------------------- -// Provides reading/writing of piped BAM files (stdin/stdout) +// Provides BAM pipe-specific IO behavior // *************************************************************************** -#include +#include "api/internal/BamPipe_p.h" using namespace BamTools; using namespace BamTools::Internal; #include +#include using namespace std; -BamPipe::BamPipe(void) - : IBamIODevice() - , m_stream(0) -{ } +BamPipe::BamPipe(void) : ILocalIODevice() { } -BamPipe::~BamPipe(void) { - Close(); -} - -void BamPipe::Close(void) { - - // skip if not open - if ( !IsOpen() ) return; - - // flush & close FILE* - fflush(m_stream); - fclose(m_stream); - - // reset internals - m_mode = IBamIODevice::NotOpen; - m_stream = 0; -} +BamPipe::~BamPipe(void) { } bool BamPipe::IsRandomAccess(void) const { return false; @@ -52,15 +34,15 @@ bool BamPipe::Open(const IBamIODevice::OpenMode mode) { else if ( mode == IBamIODevice::WriteOnly ) m_stream = freopen(0, "wb", stdout); else { - SetErrorString("BamPipe ERROR - unsupported device mode"); + SetErrorString("BamPipe::Open", "unknown open mode requested"); return false; } // check that we obtained a valid FILE* if ( m_stream == 0 ) { - string error = "BamPipe ERROR - could not open handle on "; - error += ( (mode == IBamIODevice::ReadOnly) ? "stdin" : "stdout" ); - SetErrorString(error); + const string message_base = string("could not open handle on "); + const string message = message_base + ( (mode == IBamIODevice::ReadOnly) ? "stdin" : "stdout" ); + SetErrorString("BamPipe::Open", message); return false; } @@ -69,24 +51,7 @@ bool BamPipe::Open(const IBamIODevice::OpenMode mode) { return true; } -size_t BamPipe::Read(char* data, const unsigned int numBytes) { - BT_ASSERT_X( m_stream, "BamPipe::Read() - null stream" ); - BT_ASSERT_X( (m_mode == IBamIODevice::ReadOnly), "BamPipe::Read() - device not in read-only mode"); - return fread(data, sizeof(char), numBytes, m_stream); -} - -bool BamPipe::Seek(const int64_t& position) { - (void)position; // suppress compiler warning about unused variable - return false; // seeking not allowed in pipe -} - -int64_t BamPipe::Tell(void) const { - BT_ASSERT_X( m_stream, "BamPipe::Tell() - null stream" ); - return ftell64(m_stream); -} - -size_t BamPipe::Write(const char* data, const unsigned int numBytes) { - BT_ASSERT_X( m_stream, "BamPipe::Write() - null stream" ); - BT_ASSERT_X( (m_mode == IBamIODevice::WriteOnly), "BamPipe::Write() - device not in write-only mode" ); - return fwrite(data, sizeof(char), numBytes, m_stream); +bool BamPipe::Seek(const int64_t& ) { + SetErrorString("BamPipe::Seek", "random access not allowed in FIFO pipe"); + return false; }