Changeset 3176


Ignore:
Timestamp:
Mar 15, 2014, 10:10:37 AM (8 years ago)
Author:
Peter
Message:

closes #784. New class BamPairProxy? to finalize implementation of BamPairIterator?.

Location:
trunk/yat/omic
Files:
3 edited

Legend:

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

    r3175 r3176  
    2323
    2424#include "BamPair.h"
     25
     26#include <cassert>
    2527
    2628namespace theplu {
     
    6062  }
    6163
     64  ///////////// BamPairProxy ////////////////////
     65
     66  BamPairProxy::BamPairProxy(void)
     67    : first_(NULL), second_(NULL) {}
     68
     69  BamPairProxy::BamPairProxy(const BamRead* first, const BamRead* second)
     70    : first_(first), second_(second) {}
     71
     72  const BamRead& BamPairProxy::first(void) const
     73  {
     74    assert(first_);
     75    return *first_;
     76  }
     77
     78
     79  const BamRead& BamPairProxy::second(void) const
     80  {
     81    assert(second_);
     82    return *second_;
     83  }
     84
     85
     86  BamPairProxy::operator BamPair() const
     87  {
     88    return BamPair(*first_, *second_);
     89  }
     90
    6291}}}
  • trunk/yat/omic/BamPair.h

    r3175 r3176  
    7272  };
    7373
     74
     75  /**
     76     A proxy class that behaves like a const BamPair&.
     77
     78     The class is used in BamPairIterator. The class allows to create
     79     an object that looks like a const reference of BamPair from two
     80     BamRead pointers without copying the BamRead objects. As the
     81     class is aimed at looking like a const BamPair&, implicit
     82     conversion to BamPair is allowed to mimic: BamPair = const BamPair&.
     83   */
     84  class BamPairProxy
     85  {
     86  public:
     87    /**
     88       \brief Default constructor
     89    */
     90    BamPairProxy(void);
     91
     92    /**
     93       Create a proxy from \a first and \a second.
     94
     95       \note if the objects pointed to by \a first and \a second goes
     96       out of scope, this class becomes invalid and behaviour is
     97       undefined.
     98     */
     99    BamPairProxy(const BamRead* first, const BamRead* second);
     100
     101    /**
     102       \return const reference to first BamRead
     103     */
     104    const BamRead& first(void) const;
     105
     106    /**
     107       \return const reference to second BamRead
     108    */
     109    const BamRead& second(void) const;
     110
     111    /**
     112       Implicit conversion from BamPairProxy to BamPair.
     113     */
     114    operator BamPair() const;
     115  private:
     116    const BamRead* first_;
     117    const BamRead* second_;
     118  };
     119
    74120}}}
    75121#endif
  • trunk/yat/omic/BamPairIterator.h

    r3175 r3176  
    6060  class BamPairIterator
    6161    : public boost::iterator_facade<
    62     BamPairIterator<Base>, const BamPair, std::input_iterator_tag
     62    BamPairIterator<Base>, const BamPair, std::input_iterator_tag,
     63    const BamPairProxy
    6364    >
    6465  {
     
    8182    Base iter_;
    8283    Base end_;
    83     BamPair x_;
     84    const BamRead* mate_;
    8485    boost::shared_ptr<std::map<std::string, BamRead> > siam_reads_;
    8586    typedef std::pair<int32_t, int32_t> Position;
     
    8788    friend class boost::iterator_core_access;
    8889
    89     const BamPair& dereference(void) const;
     90    const BamPairProxy dereference(void) const;
    9091    bool equal(const BamPairIterator& other) const;
    9192    void increment(void);
     
    143144
    144145  template<typename Base>
    145   const BamPair&
     146  const BamPairProxy
    146147  BamPairIterator<Base>::dereference(void) const
    147148  {
    148     return x_;
     149    return BamPairProxy(mate_, &*iter_);
    149150  }
    150151
     
    189190        for (; lower!=reads_->end() && lower->first == position; ++lower)
    190191          if (same_query_name(lower->second, *iter_)) {
    191             x_.first() = lower->second;
    192             x_.second() = *iter_;
     192            mate_ = &lower->second;
    193193            return;
    194194          }
     
    199199          mate = siam_reads_->lower_bound(iter_->name());
    200200        if (mate!=siam_reads_->end() && same_query_name(mate->second, *iter_)) {
    201           x_.first() = mate->second;
    202           x_.second() = *iter_;
     201          mate_ = &mate->second;
    203202          return;
    204203        }
Note: See TracChangeset for help on using the changeset viewer.