MOOCHO (Single Doxygen Collection) Version of the Day
AbstractLinAlgPack_TransSparseCOOElementViewIter.hpp
Go to the documentation of this file.
00001 // @HEADER
00002 // ***********************************************************************
00003 // 
00004 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization
00005 //                  Copyright (2003) Sandia Corporation
00006 // 
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 // 
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 
00038 // 
00039 // ***********************************************************************
00040 // @HEADER
00041 
00042 #ifndef TRANS_SPARSE_COO_ELEMENT_VIEW_ITER_H
00043 #define TRANS_SPARSE_COO_ELEMENT_VIEW_ITER_H
00044 
00045 #include <iterator>
00046 
00047 #include "AbstractLinAlgPack_Types.hpp"
00048 
00049 namespace AbstractLinAlgPack {
00050 
00079 template <class T_Iter, class T_IterCat, class T_Indice, class T_ValRef, class T_Diff>
00080 class TransSparseCOOElementViewIter {
00081 public:
00084 
00094   template <class TT_Iter, class TT_IterCat, class TT_Indice, class TT_ValRef, class TT_Diff>
00095   class ElementView {
00096   public:
00097 
00098     // friends
00099 
00100     friend
00101     class TransSparseCOOElementViewIter<TT_Iter,TT_IterCat,TT_Indice,TT_ValRef,TT_Diff>;
00102 
00103     // typedefs
00104 
00106     typedef TT_Indice           indice_type;
00108     typedef TT_ValRef           value_ref_type;
00109 
00112     ElementView(const TT_Iter& iter) : encap_iter_(iter)
00113     {}
00114 
00115     // access functions
00116 
00118     value_ref_type value() const {
00119       return encap_iter_->value();
00120     }
00121 
00123     indice_type row_i() const {
00124       return encap_iter_->col_j();
00125     }
00126 
00128     indice_type col_j() const {
00129       return encap_iter_->row_i();
00130     }
00131 
00132   private:
00133     TT_Iter encap_iter_;// iterator that is manipulated by
00134               // the host iterator
00135 
00136     // not defined and not to be called
00137     ElementView();
00138     ElementView& operator=(const ElementView&);
00139   };
00140 
00141   // Local typedefs
00142 
00144   typedef ElementView<T_Iter,T_IterCat,T_Indice
00145               ,T_ValRef,T_Diff>       element_view_type;
00147   typedef T_Iter                      encap_iter_type;
00149   typedef TransSparseCOOElementViewIter<T_Iter,T_IterCat
00150                 ,T_Indice,T_ValRef,T_Diff>  iterator_type;
00151 
00152   // Standard C+ library types for iterators
00153 
00155   typedef T_IterCat                   iterator_category;
00157   typedef element_view_type               value_type;
00159   typedef element_view_type&                reference_type;
00161   typedef element_view_type*                pointer_type;
00163   typedef T_Diff                      difference_type;
00165   typedef size_t                      distance_type;
00166 
00167   //  end Public Types
00169 
00172 
00179   TransSparseCOOElementViewIter(T_Iter itr) : element_view_(itr)
00180   {}
00181 
00183 
00186 
00187   // Access
00188   reference_type    operator*() const {
00189     return const_cast<element_view_type&>(element_view_);
00190   }
00191   pointer_type    operator->() const {
00192     return const_cast<element_view_type*>(&element_view_);
00193   }
00194   value_type      operator[](distance_type n) const {
00195     return element_view_type(element_view_.encap_iter_ + n);
00196   }
00197   // Incrementation
00198   // ++itr
00199   iterator_type&    operator++() {
00200     element_view_.encap_iter_++;
00201     return *this;
00202   }
00203   // itr++
00204   const iterator_type operator++(int) {
00205     iterator_type tmp = *this;
00206     ++*this;
00207     return tmp;
00208   }
00209   // --itr
00210   iterator_type&    operator--() {
00211     element_view_.encap_iter_--;
00212     return *this;
00213   }
00214   // itr--
00215   const iterator_type operator--(int) {
00216     iterator_type tmp = *this;
00217     --*this;
00218     return tmp;
00219   }
00220   // itr + n 
00221   iterator_type     operator+(distance_type n) {
00222     return iterator_type(element_view_.encap_iter_ + n);
00223   }
00224   const iterator_type   operator+(distance_type n) const {
00225     return iterator_type(element_view_.encap_iter_ + n);
00226   }
00227   // itr += n
00228   iterator_type&    operator+=(distance_type n) {
00229     element_view_.encap_iter_ += n;
00230     return *this;
00231   }
00232   // itr - n
00233   iterator_type     operator-(distance_type n) {
00234     return iterator_type(element_view_.encap_iter_ - n);
00235   }
00236   const iterator_type operator-(distance_type n) const {
00237     return iterator_type(element_view_.encap_iter_ - n);
00238   }
00239   // itr -= n
00240   iterator_type&    operator-=(distance_type n) {
00241     element_view_.encap_iter_ -= n;
00242     return *this;
00243   }
00244   // distance = itr1 - itr2 (distance between elements)
00245   distance_type   operator-(const iterator_type& itr) const {
00246     return element_view_.encap_iter_ - itr.element_view_.encap_iter_;
00247   }
00248 
00250 
00254 
00255   // <
00256   bool operator<(const iterator_type& itr)
00257   { 
00258     return element_view_.encap_iter_ < itr.element_view_.encap_iter_;
00259   }
00260   // <=
00261   bool operator<=(const iterator_type& itr)
00262   { 
00263     return element_view_.encap_iter_ <= itr.element_view_.encap_iter_;
00264   }
00265   // >
00266   bool operator>(const iterator_type& itr)
00267   { 
00268     return element_view_.encap_iter_ > itr.element_view_.encap_iter_;
00269   }
00270   // >=
00271   bool operator>=(const iterator_type& itr)
00272   { 
00273     return element_view_.encap_iter_ >= itr.element_view_.encap_iter_;
00274   }
00275   // ==
00276   bool operator==(const iterator_type& itr)
00277   { 
00278     return element_view_.encap_iter_ == itr.element_view_.encap_iter_;
00279   }
00280   // !=
00281   bool operator!=(const iterator_type& itr)
00282   { 
00283     return element_view_.encap_iter_ != itr.element_view_.encap_iter_;
00284   }
00285 
00287 
00288 private:
00289   element_view_type element_view_;
00290   
00291   // not defined and not to be called
00292   TransSparseCOOElementViewIter();
00293 
00294 };  // end class TransSparseCOOElementViewIter
00295 
00296 // ///////////////////////////////////////////////////////////////////////////////////////
00297 // Nonmember functions
00298 
00299 // Allow distance_type as lhs argument in n + itr
00300 
00301 //template <class Iter, class Cat, class Indice, class ValRef, class Diff>
00302 //inline TransSparseCOOElementViewIter<Iter,Cat,Indice,ValRef,Diff>
00303 //operator+(Diff n, TransSparseCOOElementViewIter<Iter,Cat,Indice,ValRef,Diff> itr)
00304 //{
00305 //  return itr + n;
00306 //}
00307 
00308 template <class Iter, class Cat, class Indice, class ValRef, class Diff>
00309 inline TransSparseCOOElementViewIter<Iter,Cat,Indice,ValRef,Diff>
00310 operator+(Diff n, const TransSparseCOOElementViewIter<Iter,Cat,Indice,ValRef,Diff> itr)
00311 {
00312   return itr + n;
00313 }
00314 
00315 } // end namespace AbstractLinAlgPack 
00316 
00317 #endif // TRANS_SPARSE_COO_ELEMENT_VIEW_ITER_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines