]> git.donarmstrong.com Git - bamtools.git/blobdiff - src/api/internal/BgzfStream_p.cpp
Minor cleanup
[bamtools.git] / src / api / internal / BgzfStream_p.cpp
index fb67799c9079d7e5f8e7aebe759ebde2a5c8ccfc..36599b5b363fd6241fcd9fe6dff9a5c3b168235d 100644 (file)
@@ -1,9 +1,8 @@
 // ***************************************************************************
 // BgzfStream_p.cpp (c) 2011 Derek Barnett
 // Marth Lab, Department of Biology, Boston College
-// All rights reserved.
 // ---------------------------------------------------------------------------
-// Last modified: 21 March 2011(DB)
+// Last modified: 2 September 2011(DB)
 // ---------------------------------------------------------------------------
 // Based on BGZF routines developed at the Broad Institute.
 // Provides the basic functionality for reading & writing BGZF files
@@ -253,15 +252,15 @@ bool BgzfStream::Open(const string& filename, const char* mode) {
     }
 
     // open BGZF stream on a file
-    if ( (filename != "stdin") && (filename != "stdout") )
+    if ( (filename != "stdin") && (filename != "stdout") && (filename != "-"))
         Stream = fopen(filename.c_str(), mode);
 
     // open BGZF stream on stdin
-    else if ( (filename == "stdin") && (strcmp(mode, "rb") == 0 ) )
+    else if ( (filename == "stdin" || filename == "-") && (strcmp(mode, "rb") == 0 ) )
         Stream = freopen(NULL, mode, stdin);
 
     // open BGZF stream on stdout
-    else if ( (filename == "stdout") && (strcmp(mode, "wb") == 0) )
+    else if ( (filename == "stdout" || filename == "-") && (strcmp(mode, "wb") == 0) )
         Stream = freopen(NULL, mode, stdout);
 
     if ( !Stream ) {
@@ -375,7 +374,7 @@ bool BgzfStream::ReadBlock(void) {
 }
 
 // seek to position in BGZF file
-bool BgzfStream::Seek(int64_t position) {
+bool BgzfStream::Seek(const int64_t& position) {
 
     // skip if not open
     if ( !IsOpen ) return false;
@@ -390,12 +389,10 @@ bool BgzfStream::Seek(int64_t position) {
         return false;
     }
 
-    // update block data
+    // update block data & return success
     BlockLength  = 0;
     BlockAddress = blockAddress;
     BlockOffset  = blockOffset;
-
-    // return success
     return true;
 }
 
@@ -404,12 +401,9 @@ void BgzfStream::SetWriteCompressed(bool ok) {
 }
 
 // get file position in BGZF file
-int64_t BgzfStream::Tell(void) {
-
-    // skip if file not open
-    if ( !IsOpen ) return false;
-
-    // otherwise return file pointer position
+int64_t BgzfStream::Tell(void) const {
+    if ( !IsOpen )
+        return 0;
     return ( (BlockAddress << 16) | (BlockOffset & 0xFFFF) );
 }