From: Derek Date: Tue, 17 Aug 2010 19:19:10 +0000 (-0400) Subject: Modified BamWriter::Open() to return bool on success/fail - was silent before, so... X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=6222ce815dc4cb69d5d4c276cb435087e1cd77a8;p=bamtools.git Modified BamWriter::Open() to return bool on success/fail - was silent before, so clients had no way of handling errors --- diff --git a/BamWriter.cpp b/BamWriter.cpp index a794dff..5052eaa 100644 --- a/BamWriter.cpp +++ b/BamWriter.cpp @@ -3,7 +3,7 @@ // Marth Lab, Department of Biology, Boston College // All rights reserved. // --------------------------------------------------------------------------- -// Last modified: 15 July 2010 (DB) +// Last modified: 17 August 2010 (DB) // --------------------------------------------------------------------------- // Uses BGZF routines were adapted from the bgzf.c code developed at the Broad // Institute. @@ -35,7 +35,7 @@ struct BamWriter::BamWriterPrivate { // "public" interface void Close(void); - void Open(const string& filename, const string& samHeader, const RefVector& referenceSequences); + bool Open(const string& filename, const string& samHeader, const RefVector& referenceSequences); void SaveAlignment(const BamAlignment& al); // internal methods @@ -65,8 +65,8 @@ void BamWriter::Close(void) { } // opens the alignment archive -void BamWriter::Open(const string& filename, const string& samHeader, const RefVector& referenceSequences) { - d->Open(filename, samHeader, referenceSequences); +bool BamWriter::Open(const string& filename, const string& samHeader, const RefVector& referenceSequences) { + return d->Open(filename, samHeader, referenceSequences); } // saves the alignment to the alignment archive @@ -202,10 +202,11 @@ void BamWriter::BamWriterPrivate::EncodeQuerySequence(const string& query, strin } // opens the alignment archive -void BamWriter::BamWriterPrivate::Open(const string& filename, const string& samHeader, const RefVector& referenceSequences) { +bool BamWriter::BamWriterPrivate::Open(const string& filename, const string& samHeader, const RefVector& referenceSequences) { - // open the BGZF file for writing - mBGZF.Open(filename, "wb"); + // open the BGZF file for writing, return failure if error + if ( !mBGZF.Open(filename, "wb") ) + return false; // ================ // write the header @@ -250,6 +251,9 @@ void BamWriter::BamWriterPrivate::Open(const string& filename, const string& sam if (IsBigEndian) SwapEndian_32(referenceLength); mBGZF.Write((char*)&referenceLength, BT_SIZEOF_INT); } + + // return success + return true; } // saves the alignment to the alignment archive diff --git a/BamWriter.h b/BamWriter.h index 2608ddb..e8e7a14 100644 --- a/BamWriter.h +++ b/BamWriter.h @@ -3,7 +3,7 @@ // Marth Lab, Department of Biology, Boston College // All rights reserved. // --------------------------------------------------------------------------- -// Last modified: 8 December 2009 (DB) +// Last modified: 17 August 2010 (DB) // --------------------------------------------------------------------------- // Uses BGZF routines were adapted from the bgzf.c code developed at the Broad // Institute. @@ -34,7 +34,7 @@ class BamWriter { // closes the alignment archive void Close(void); // opens the alignment archive - void Open(const std::string& filename, const std::string& samHeader, const BamTools::RefVector& referenceSequences); + bool Open(const std::string& filename, const std::string& samHeader, const BamTools::RefVector& referenceSequences); // saves the alignment to the alignment archive void SaveAlignment(const BamTools::BamAlignment& al);