From 5bb90b428311e169e8ca713ea3d6d33846c53f49 Mon Sep 17 00:00:00 2001 From: Bo Li Date: Mon, 15 Apr 2013 00:56:55 -0500 Subject: [PATCH] Modified my_assert.h to postpone error message string generation --- my_assert.h | 9 +++++---- scanForPairedEndReads.cpp | 6 +++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/my_assert.h b/my_assert.h index d63c3a2..3688d96 100644 --- a/my_assert.h +++ b/my_assert.h @@ -31,17 +31,18 @@ inline std::string cstrtos(const char* s) { } -inline void general_assert(int expr, const std::string& errmsg, bool putEnter = false) { - if (expr) return; +#define general_assert(expr, errmsg) if (!(expr)) general_report((errmsg), false) +#define general_assert_1(expr, errmsg) if (!(expr)) general_report((errmsg), true) +inline void general_report(const std::string& errmsg, bool putEnter) { if (putEnter) printf("\n"); fprintf(stderr, "%s\n", errmsg.c_str()); exit(-1); } -inline void pthread_assert(int rc, const std::string& func_name, const std::string& errmsg) { - if (rc == 0) return; +#define pthread_assert(rc, func_name, errmsg) if ((rc) != 0) pthread_report((rc), (func_name), (errmsg)) +inline void pthread_report(int rc, const std::string& func_name, const std::string& errmsg) { fprintf(stderr, "%s\n", errmsg.c_str()); if (func_name == "pthread_create") { diff --git a/scanForPairedEndReads.cpp b/scanForPairedEndReads.cpp index b220fa8..7b20e11 100644 --- a/scanForPairedEndReads.cpp +++ b/scanForPairedEndReads.cpp @@ -75,12 +75,12 @@ int main(int argc, char* argv[]) { if (isPaired) { add_to_appropriate_arr(b); while ((go_on = (samread(in, b) >= 0)) && (qname == bam1_qname(b))) { - general_assert(b->core.flag & 0x0001, "Read " + qname + " is detected as both single-end and paired-end read!", true); + general_assert_1(b->core.flag & 0x0001, "Read " + qname + " is detected as both single-end and paired-end read!"); add_to_appropriate_arr(b); } - general_assert(arr_both.size() % 2 == 0, "Number of first and second mates in read " + qname + "'s full alignments (both mates are aligned) are not matched!", true); - general_assert((arr_partial_1.size() + arr_partial_2.size() + arr_partial_unknown.size()) % 2 == 0, "Number of first and second mates in read " + qname + "'s partial alignments (at most one mate is aligned) are not matched!", true); + general_assert_1(arr_both.size() % 2 == 0, "Number of first and second mates in read " + qname + "'s full alignments (both mates are aligned) are not matched!"); + general_assert_1((arr_partial_1.size() + arr_partial_2.size() + arr_partial_unknown.size()) % 2 == 0, "Number of first and second mates in read " + qname + "'s partial alignments (at most one mate is aligned) are not matched!"); if (!arr_both.empty()) { sort(arr_both.begin(), arr_both.end(), less_than); -- 2.39.2