Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:44:51

0001 #ifndef GENERS_CP_COLUMN_ITERATOR_HH_
0002 #define GENERS_CP_COLUMN_ITERATOR_HH_
0003 
0004 #include <climits>
0005 #include <iterator>
0006 #include "Alignment/Geners/interface/IOException.hh"
0007 
0008 #include "Alignment/Geners/interface/IOReferredType.hh"
0009 
0010 namespace gs {
0011     //
0012     // The following works as a simple forward iterator for ColumnPacker
0013     // (cycles over the contents of a single column). It is effectively
0014     // const, as it can not modify the underlying packer data.
0015     //
0016     template<unsigned long N, typename Packer, typename StoragePtr>
0017     class CP_column_iterator
0018     {
0019     public:
0020         typedef typename IOReferredType<StoragePtr>::type value_type;
0021         typedef value_type* pointer;
0022         typedef value_type& reference;
0023         typedef std::ptrdiff_t difference_type;
0024         typedef std::forward_iterator_tag iterator_category;
0025 
0026         inline CP_column_iterator(const Packer& packer, StoragePtr s,
0027                                   const unsigned long row)
0028             : packer_(packer), s_(s), row_(row)
0029         {
0030             if (row_ > packer_.nRows())
0031                 row_ = packer_.nRows();
0032         }
0033 
0034         inline reference operator*() const
0035         {
0036             packer_.template fetchItem<N>(row_, s_);
0037             return *s_;
0038         }
0039 
0040         inline pointer operator->() const
0041         {
0042             packer_.template fetchItem<N>(row_, s_);
0043             return &*s_;
0044         }
0045 
0046         inline CP_column_iterator& operator++()
0047             {++row_; return *this;}
0048 
0049         inline CP_column_iterator operator++(int)
0050             {CP_column_iterator tmp(*this); ++row_; return tmp;}
0051 
0052         inline bool operator==(const CP_column_iterator& r) const
0053             {return row_ == r.row_;}
0054 
0055         inline bool operator!=(const CP_column_iterator& r) const
0056             {return row_ != r.row_;}
0057 
0058         inline bool operator<(const CP_column_iterator& r) const
0059             {return row_ < r.row_;}
0060 
0061     private:
0062         const Packer& packer_;
0063         StoragePtr s_;
0064         unsigned long row_;
0065     };
0066 
0067     template<unsigned long N, typename Packer, typename StoragePtr>
0068     inline CP_column_iterator<N, Packer, StoragePtr>
0069     CP_column_begin(const Packer& packer, StoragePtr s,
0070                     const unsigned long row=0UL)
0071     {
0072         return CP_column_iterator<N, Packer, StoragePtr>(packer, s, row);
0073     }
0074 
0075     template<unsigned long N, typename Packer, typename StoragePtr>
0076     inline CP_column_iterator<N, Packer, StoragePtr>
0077     CP_column_end(const Packer& packer, StoragePtr s)
0078     {
0079         return CP_column_iterator<N, Packer, StoragePtr>(packer, s, ULONG_MAX);
0080     }
0081 }
0082 
0083 #endif // GENERS_CP_COLUMN_ITERATOR_HH_
0084