Home | Doxygen Documentation | Tutorials | Developer Tools (restricted)

operator/subMatrixIterator.hh
Go to the documentation of this file.
00001 /* iterator for sub matrices
00002  */
00003 
00004 #ifndef submatrixiterator_hh
00005 #define submatrixiterator_hh
00006 
00007 #include "matrixIterator.hh"
00008 #include "space/spaceSet.hh"
00009 
00010 namespace concepts {
00011 
00012   template<class F>
00013   class SubMatrixN;
00014 
00015   // *************************************************** _SubMatrix_iterator **
00016 
00025   template <class F, class _Ref, class _Ptr>
00026   class _SubMatrix_iterator : 
00027     public _Matrix_iterator_base<typename F::type, _Ref, _Ptr> {
00028   public:
00029 
00030     template<class F_, class _Ref_, class _Ptr_>
00031     struct MatrixType;
00032 
00033     typedef std::forward_iterator_tag                      iterator_category;
00034     typedef typename F::type                               value_type;
00035     typedef _Ptr                                           pointer;
00036     typedef _Ref                                           reference;
00037     typedef size_t                                         size_type;
00038     typedef ptrdiff_t                                      difference_type;
00039     typedef _SubMatrix_iterator                            _Self;
00040     typedef _Matrix_iterator_base<value_type, _Ref, _Ptr>  _Base;
00041     typedef typename MatrixType<F, _Ref, _Ptr>::type       matrix_type;
00042     typedef typename _Base::return_type                    return_type;
00043 
00044     typedef 
00045     _SubMatrix_iterator<F, value_type&, value_type*>            iterator;
00046     typedef 
00047     _SubMatrix_iterator<F, const value_type&,const value_type*> const_iterator;
00048 
00054     _SubMatrix_iterator(matrix_type& m, uint r = 0);
00056     _SubMatrix_iterator();
00058     template<class _RefR, class _PtrR>
00059     _SubMatrix_iterator(const _SubMatrix_iterator<F, _RefR, _PtrR>& __x)
00060       : _Base(__x), i_(0), iend_(0), iI_(0), lastI_(0), m_(__x.m()) {
00061       if (__x.i())
00062         i_.reset(new typename MatrixType<F, _Ref, _Ptr>::iterator(*__x.i()));
00063       if (__x.iend())
00064         iend_.reset
00065           (new typename MatrixType<F, _Ref, _Ptr>::iterator(*__x.iend()));
00066       if (__x.iI())
00067         iI_.reset(new Set<IndexRange>::index_iterator(*__x.iI()));
00068       if (__x.lastI())
00069         lastI_.reset(new Set<IndexRange>::index_iterator(*__x.lastI()));
00070     }
00071 
00073     return_type operator*() const {
00074       conceptsAssert(i_.get(), Assertion());
00075       return **i_;
00076     }
00078     pointer operator->() const {
00079       conceptsAssert(i_.get(), Assertion());
00080       return securePointer(**i_, m_);
00081     }
00082 
00084     template<class _RefR, class _PtrR>
00085     _Self& operator=(const _SubMatrix_iterator<F, _RefR, _PtrR>& __x) {
00086       _Base::operator=(__x);
00087       if (__x.i())
00088         i_.reset(new typename MatrixType<F, _Ref, _Ptr>::iterator(*__x.i()));
00089       else i_.reset(0);
00090       if (__x.iend())
00091         iend_.reset
00092           (new typename MatrixType<F, _Ref, _Ptr>::iterator(*__x.iend()));
00093       else iend_.reset(0);
00094       iI_ = __x.iI(); lastI_ = __x.lastI();
00095       m_ = __x.m();
00096       return *this;
00097     }
00098 
00100     _Self& operator++();
00101     _Self operator++(int) {
00102       _Self __tmp = *this;
00103       ++*this;
00104       return __tmp;
00105     }
00106 
00107     inline typename MatrixType<F, _Ref, _Ptr>::iterator* i() const {
00108       return i_.get();
00109     }
00110     inline const typename MatrixType<F, _Ref, _Ptr>::iterator* iend() const { 
00111       return iend_.get();
00112     }
00113     inline Set<IndexRange>::index_iterator* iI() const { return iI_.get(); }
00114     const Set<IndexRange>::index_iterator* lastI() const { 
00115       return lastI_.get();
00116     }
00117     inline matrix_type* m() const { return m_; }
00118   protected:
00119     virtual std::ostream& info(std::ostream& os) const;
00120   private:
00122     std::auto_ptr<typename MatrixType<F, _Ref, _Ptr>::iterator> i_;
00124     std::auto_ptr<const typename MatrixType<F, _Ref, _Ptr>::iterator> iend_;
00126     std::auto_ptr<Set<IndexRange>::index_iterator> iI_;
00128     std::auto_ptr<const Set<IndexRange>::index_iterator> lastI_;
00130     matrix_type* m_;
00131 
00135     _Self& next_();
00136   };
00137 
00139   template <class F, class _Ref, class _Ptr>
00140   template<class F_, class _Ref_, class _Ptr_>
00141   struct _SubMatrix_iterator<F, _Ref, _Ptr>::MatrixType {
00142     typedef SubMatrixN<F_> type;
00143     typedef typename F_::iterator iterator;
00144   };
00145 
00147   template <class F, class _Ref, class _Ptr>
00148   template<class F_>
00149   struct _SubMatrix_iterator<F, _Ref, _Ptr>::
00150     MatrixType<F_, const typename F::type&, const typename F::type*>
00151   {
00152     typedef const SubMatrixN<F_> type;
00153     typedef typename F_::const_iterator iterator;
00154   };
00155 
00156 } // namespace concepts
00157 
00158 #endif // submatrixiterator_hh

Home | Doxygen Documentation | Tutorials | Developer Tools (restricted)