Changeset 3630 for trunk


Ignore:
Timestamp:
Mar 14, 2017, 8:05:31 AM (6 years ago)
Author:
Peter
Message:

Avoid compiler warnings when compiling against HTSLIB 1.4.

In struct bam1_t, 'm_data' has changed from 'int' to 'uint32_t', which
caused some "comparing signed and unsigned" warnings. Fix by
introducing private function: uint32_t BamRead::data_capacity(void)
const, and change signature on reserve.

Compiler complains if return value from sam_hdr_write is ignored. Fix
by pay attention to to it and trow if non-zero. Avoid repeating code
by introducing a third (private) open function taking the 'mode'.

Location:
trunk/yat/omic
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/yat/omic/BamFile.cc

    r3579 r3630  
    274274    if (!h.header_)
    275275      throw utility::runtime_error("OutBamFile::open with null header");
    276 #if YAT_HAVE_HTSLIB
    277     open_base(fn, "wb", NULL);
    278     sam_hdr_write(sf_, h.header_);
    279 #else
    280     open_base(fn, "wb", h.header_);
    281 #endif
     276    open(fn, std::string("wb"), h);
    282277  }
    283278
     
    298293    else
    299294      mode = "wu";
     295#else
     296    mode.push_back('0'+compression);
     297#endif
     298    open(fn, mode, h);
     299  }
     300
     301
     302  void OutBamFile::open(const std::string& fn, const std::string& mode,
     303                        const BamHeader& h)
     304  {
     305#if YAT_HAVE_HTSLIB
    300306    open_base(fn, mode, NULL);
    301     sam_hdr_write(sf_, h.header_);
    302 #else
    303     mode.push_back('0'+compression);
     307    if (sam_hdr_write(sf_, h.header_)) {
     308      std::ostringstream ss;
     309      ss << "failed open '" << fn << "'";
     310      throw utility::runtime_error(ss.str());
     311    }
     312#else
    304313    open_base(fn, mode, h.header_);
    305314#endif
  • trunk/yat/omic/BamFile.h

    r3550 r3630  
    318318
    319319  private:
     320    void open(const std::string& fn, const std::string& mode,
     321              const BamHeader& h);
     322
    320323  };
    321324
  • trunk/yat/omic/BamRead.cc

    r3584 r3630  
    262262    data_size() += offset;
    263263    core().n_cigar = c.size();
    264     assert(data_size() <= bam_->m_data);
     264    assert(static_cast<uint32_t>(data_size()) <= data_capacity());
    265265  }
    266266
     
    272272  bam1_core_t& BamRead::core(void)
    273273  { return bam_->core; }
     274
     275
     276  uint32_t BamRead::data_capacity(void) const
     277  {
     278    return bam_->m_data;
     279  }
    274280
    275281
     
    329335    memcpy(bam1_qname(bam_), n.c_str(), n.size()+1);
    330336    data_size() += offset;
    331     assert(data_size() <= bam_->m_data);
     337    assert(static_cast<uint32_t>(data_size()) <= data_capacity());
    332338  }
    333339
     
    341347
    342348
    343   void BamRead::reserve(int n)
    344   {
    345     assert(bam_);
    346     if (bam_->m_data >= n)
     349  void BamRead::reserve(uint32_t n)
     350  {
     351    assert(bam_);
     352    if (data_capacity() >= static_cast<uint32_t>(n))
    347353      return;
    348354    // at least double capacity
    349     bam_->m_data = std::max(bam_->m_data<<1, n);
     355    bam_->m_data = std::max(data_capacity()<<1, n);
    350356    bam_->data = (uint8_t*)realloc(bam_->data, bam_->m_data);
    351357    if (!bam_->data) {
  • trunk/yat/omic/BamRead.h

    r3596 r3630  
    329329  private:
    330330    // ensure capacity of data pointer is (at least) n
    331     void reserve(int n);
     331    void reserve(uint32_t n);
    332332
    333333    bam1_t* bam_;
     
    342342    int& data_size(void);
    343343    const int& data_size(void) const;
     344    uint32_t data_capacity(void) const;
    344345  };
    345346
Note: See TracChangeset for help on using the changeset viewer.