1 // ***************************************************************************
2 // BamPipe_p.cpp (c) 2011 Derek Barnett
3 // Marth Lab, Department of Biology, Boston College
4 // ---------------------------------------------------------------------------
5 // Last modified: 10 November 2011 (DB)
6 // ---------------------------------------------------------------------------
7 // Provides BAM pipe-specific IO behavior
8 // ***************************************************************************
10 #include "api/internal/io/BamPipe_p.h"
11 using namespace BamTools;
12 using namespace BamTools::Internal;
18 BamPipe::BamPipe(void) : ILocalIODevice() { }
20 BamPipe::~BamPipe(void) { }
22 bool BamPipe::IsRandomAccess(void) const {
26 bool BamPipe::Open(const IBamIODevice::OpenMode mode) {
28 // make sure we're starting with a fresh pipe
31 // open stdin/stdout depending on requested openmode
32 if ( mode == IBamIODevice::ReadOnly )
33 m_stream = freopen(0, "rb", stdin);
34 else if ( mode == IBamIODevice::WriteOnly )
35 m_stream = freopen(0, "wb", stdout);
37 const string errorType = string( (mode == IBamIODevice::ReadWrite) ? "unsupported"
39 const string message = errorType + " open mode requested";
40 SetErrorString("BamPipe::Open", message);
44 // check that we obtained a valid FILE*
45 if ( m_stream == 0 ) {
46 const string message_base = string("could not open handle on ");
47 const string message = message_base + ( (mode == IBamIODevice::ReadOnly) ? "stdin"
49 SetErrorString("BamPipe::Open", message);
53 // store current IO mode & return success
58 bool BamPipe::Seek(const int64_t&, const int) {
59 SetErrorString("BamPipe::Seek", "random access not allowed in FIFO pipe");