Changeset 4011


Ignore:
Timestamp:
Oct 22, 2020, 2:35:34 AM (12 months ago)
Author:
Peter
Message:

Use std smart pointers instead of boost. Prefer initialisation of
member variables. Move implementation of class BamIndexDestroyer? to
source file. Since the actor classes are never copied, use an
std::unique_ptr (rather than a shared_ptr).

closes #966

Location:
trunk/yat/omic
Files:
2 edited

Legend:

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

    r3883 r4011  
    2828#include "yat/utility/Exception.h"
    2929
     30#include <cassert>
    3031#include <cstddef>
    3132#include <sstream>
     
    3637
    3738  BamReadIterator::BamReadIterator(void)
     39    : actor_(new AllActor)
    3840  {
    39     actor_ = boost::shared_ptr<Actor>(new AllActor);
     41    assert(actor_);
    4042  }
    4143
    4244
    4345  BamReadIterator::BamReadIterator(InBamFile& in)
     46    : actor_(new AllActor(in))
    4447  {
    45     actor_ = boost::shared_ptr<Actor>(new AllActor(in));
     48    assert(actor_);
    4649    increment();
    4750  }
     
    5053  BamReadIterator::BamReadIterator(InBamFile& bf, int32_t tid, int32_t start,
    5154                                   int32_t end)
     55    : actor_(new IndexActor(bf, tid, start, end))
    5256  {
    53     actor_ = boost::shared_ptr<Actor>(new IndexActor(bf, tid, start, end));
    5457    assert(actor_);
    5558    increment();
     
    5861
    5962  BamReadIterator::BamReadIterator(InBamFile& bf, int32_t tid, int32_t start)
     63    : actor_(new IndexActor(bf, tid, start, bf.header().target_length(tid)))
    6064  {
    61     actor_ =
    62       boost::shared_ptr<Actor>(new IndexActor(bf, tid, start,
    63                                               bf.header().target_length(tid)));
    6465    assert(actor_);
    6566    increment();
     
    8384    actor_->increment();
    8485  }
     86
     87
     88  void BamReadIterator::IndexDestroyer::operator()(hts_itr_t* i) const
     89  {
     90    bam_itr_destroy(i);
     91  }
     92
    8593
    8694
     
    120128  BamReadIterator::IndexActor::IndexActor(InBamFile& bf, int32_t tid,
    121129                                          int32_t begin,int32_t end)
    122     : Actor(&bf)
     130    : Actor(&bf),
     131      iter_(sam_itr_queryi(bf.index(), tid, begin, end), IndexDestroyer())
    123132  {
    124     using boost::shared_ptr;
    125     iter_ = shared_ptr<hts_itr_t>(sam_itr_queryi(bf.index(), tid, begin, end),
    126                                   IndexDestroyer());
    127133    if (!iter_.get()) {
    128134      std::stringstream ss;
  • trunk/yat/omic/BamReadIterator.h

    r3999 r4011  
    2929
    3030#include <boost/iterator/iterator_facade.hpp>
    31 #include <boost/shared_ptr.hpp>
    3231
    3332#include <iterator>
     33#include <memory>
    3434
    3535namespace theplu {
     
    118118    void increment(void);
    119119
     120
    120121    /*
    121122       Interface class for the actor that handles difference between
     
    142143    };
    143144
     145    // functor calling bam_itr_destroy
     146    struct IndexDestroyer
     147    {
     148      void operator()(hts_itr_t* i) const;
     149    };
     150
    144151    // class used when iterating over a sub-region of the bam file
    145152    class IndexActor : public Actor
     
    149156      void increment(void);
    150157    private:
    151       boost::shared_ptr<hts_itr_t> iter_;
     158      std::unique_ptr<hts_itr_t, IndexDestroyer> iter_;
    152159    };
    153160
    154     boost::shared_ptr<Actor> actor_;
     161    std::shared_ptr<Actor> actor_;
    155162
    156     struct IndexDestroyer
    157     {
    158       void operator()(hts_itr_t* i) const
    159       {
    160         bam_itr_destroy(i);
    161       }
    162     };
    163163  };
    164164}}}
Note: See TracChangeset for help on using the changeset viewer.