1 // ***************************************************************************
2 // ILocalIODevice_p.cpp (c) 2011 Derek Barnett
3 // Marth Lab, Department of Biology, Boston College
4 // ---------------------------------------------------------------------------
5 // Last modified: 7 October 2011 (DB)
6 // ---------------------------------------------------------------------------
7 // Provides shared behavior for files & pipes
8 // ***************************************************************************
10 #include <api/internal/ILocalIODevice_p.h>
11 using namespace BamTools;
12 using namespace BamTools::Internal;
17 ILocalIODevice::ILocalIODevice(void)
22 ILocalIODevice::~ILocalIODevice(void) {
26 void ILocalIODevice::Close(void) {
32 // flush & close FILE*
37 // reset other device state
38 m_mode = IBamIODevice::NotOpen;
41 size_t ILocalIODevice::Read(char* data, const unsigned int numBytes) {
42 BT_ASSERT_X( m_stream, "ILocalIODevice::Read: trying to read from null stream" );
43 BT_ASSERT_X( (m_mode == IBamIODevice::ReadOnly), "ILocalIODevice::Read: device not in read-only mode");
44 return fread(data, sizeof(char), numBytes, m_stream);
47 int64_t ILocalIODevice::Tell(void) const {
48 BT_ASSERT_X( m_stream, "ILocalIODevice::Tell: trying to get file position fromnull stream" );
49 return ftell64(m_stream);
52 size_t ILocalIODevice::Write(const char* data, const unsigned int numBytes) {
53 BT_ASSERT_X( m_stream, "ILocalIODevice::Write: tryint to write to null stream" );
54 BT_ASSERT_X( (m_mode == IBamIODevice::WriteOnly), "ILocalIODevice::Write: device not in write-only mode" );
55 return fwrite(data, sizeof(char), numBytes, m_stream);