// BamPipe_p.cpp (c) 2011 Derek Barnett
// Marth Lab, Department of Biology, Boston College
// ---------------------------------------------------------------------------
-// Last modified: 8 September 2011 (DB)
+// Last modified: 9 September 2011 (DB)
// ---------------------------------------------------------------------------
-// Provides reading/writing of piped BAM files (stdin/stdout)
+// Provides BAM pipe-specific IO behavior
// ***************************************************************************
#include <api/internal/BamPipe_p.h>
using namespace BamTools::Internal;
#include <cstdio>
+#include <iostream>
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;
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
-}
+// (void)position; // suppress compiler warning about unused variable
+// return false; // seeking not allowed in pipe
+
+ BT_ASSERT_X( m_stream, "BamFile::Seek() - null stream" );
+ cerr << "BamPipe::Seek() - about to attempt seek" << endl;
+ bool result = ( fseek64(m_stream, position, SEEK_SET) == 0);
+ if ( !result ) {
+ cerr << "BamPipe can't be seeked in" << endl;
+ }
+ return result;
-int64_t BamPipe::Tell(void) const {
- BT_ASSERT_X( m_stream, "BamPipe::Tell() - null stream" );
- return ftell64(m_stream);
-}
+// return ( fseek64(m_stream, position, SEEK_SET) == 0);
-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);
}