|
AbstractLinAlgPack: C++ Interfaces For Vectors, Matrices And Related Linear Algebra Objects Version of the Day
|
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 // This library is free software; you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as 00012 // published by the Free Software Foundation; either version 2.1 of the 00013 // License, or (at your option) any later version. 00014 // 00015 // This library is distributed in the hope that it will be useful, but 00016 // WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 // Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public 00021 // License along with this library; if not, write to the Free Software 00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00023 // USA 00024 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 00025 // 00026 // *********************************************************************** 00027 // @HEADER 00028 00029 #ifndef TRANS_SPARSE_COO_ELEMENT_VIEW_ITER_H 00030 #define TRANS_SPARSE_COO_ELEMENT_VIEW_ITER_H 00031 00032 #include <iterator> 00033 00034 #include "AbstractLinAlgPack_Types.hpp" 00035 00036 namespace AbstractLinAlgPack { 00037 00066 template <class T_Iter, class T_IterCat, class T_Indice, class T_ValRef, class T_Diff> 00067 class TransSparseCOOElementViewIter { 00068 public: 00071 00081 template <class TT_Iter, class TT_IterCat, class TT_Indice, class TT_ValRef, class TT_Diff> 00082 class ElementView { 00083 public: 00084 00085 // friends 00086 00087 friend 00088 class TransSparseCOOElementViewIter<TT_Iter,TT_IterCat,TT_Indice,TT_ValRef,TT_Diff>; 00089 00090 // typedefs 00091 00093 typedef TT_Indice indice_type; 00095 typedef TT_ValRef value_ref_type; 00096 00099 ElementView(const TT_Iter& iter) : encap_iter_(iter) 00100 {} 00101 00102 // access functions 00103 00105 value_ref_type value() const { 00106 return encap_iter_->value(); 00107 } 00108 00110 indice_type row_i() const { 00111 return encap_iter_->col_j(); 00112 } 00113 00115 indice_type col_j() const { 00116 return encap_iter_->row_i(); 00117 } 00118 00119 private: 00120 TT_Iter encap_iter_;// iterator that is manipulated by 00121 // the host iterator 00122 00123 // not defined and not to be called 00124 ElementView(); 00125 ElementView& operator=(const ElementView&); 00126 }; 00127 00128 // Local typedefs 00129 00131 typedef ElementView<T_Iter,T_IterCat,T_Indice 00132 ,T_ValRef,T_Diff> element_view_type; 00134 typedef T_Iter encap_iter_type; 00136 typedef TransSparseCOOElementViewIter<T_Iter,T_IterCat 00137 ,T_Indice,T_ValRef,T_Diff> iterator_type; 00138 00139 // Standard C+ library types for iterators 00140 00142 typedef T_IterCat iterator_category; 00144 typedef element_view_type value_type; 00146 typedef element_view_type& reference_type; 00148 typedef element_view_type* pointer_type; 00150 typedef T_Diff difference_type; 00152 typedef size_t distance_type; 00153 00154 // end Public Types 00156 00159 00166 TransSparseCOOElementViewIter(T_Iter itr) : element_view_(itr) 00167 {} 00168 00170 00173 00174 // Access 00175 reference_type operator*() const { 00176 return const_cast<element_view_type&>(element_view_); 00177 } 00178 pointer_type operator->() const { 00179 return const_cast<element_view_type*>(&element_view_); 00180 } 00181 value_type operator[](distance_type n) const { 00182 return element_view_type(element_view_.encap_iter_ + n); 00183 } 00184 // Incrementation 00185 // ++itr 00186 iterator_type& operator++() { 00187 element_view_.encap_iter_++; 00188 return *this; 00189 } 00190 // itr++ 00191 const iterator_type operator++(int) { 00192 iterator_type tmp = *this; 00193 ++*this; 00194 return tmp; 00195 } 00196 // --itr 00197 iterator_type& operator--() { 00198 element_view_.encap_iter_--; 00199 return *this; 00200 } 00201 // itr-- 00202 const iterator_type operator--(int) { 00203 iterator_type tmp = *this; 00204 --*this; 00205 return tmp; 00206 } 00207 // itr + n 00208 iterator_type operator+(distance_type n) { 00209 return iterator_type(element_view_.encap_iter_ + n); 00210 } 00211 const iterator_type operator+(distance_type n) const { 00212 return iterator_type(element_view_.encap_iter_ + n); 00213 } 00214 // itr += n 00215 iterator_type& operator+=(distance_type n) { 00216 element_view_.encap_iter_ += n; 00217 return *this; 00218 } 00219 // itr - n 00220 iterator_type operator-(distance_type n) { 00221 return iterator_type(element_view_.encap_iter_ - n); 00222 } 00223 const iterator_type operator-(distance_type n) const { 00224 return iterator_type(element_view_.encap_iter_ - n); 00225 } 00226 // itr -= n 00227 iterator_type& operator-=(distance_type n) { 00228 element_view_.encap_iter_ -= n; 00229 return *this; 00230 } 00231 // distance = itr1 - itr2 (distance between elements) 00232 distance_type operator-(const iterator_type& itr) const { 00233 return element_view_.encap_iter_ - itr.element_view_.encap_iter_; 00234 } 00235 00237 00241 00242 // < 00243 bool operator<(const iterator_type& itr) 00244 { 00245 return element_view_.encap_iter_ < itr.element_view_.encap_iter_; 00246 } 00247 // <= 00248 bool operator<=(const iterator_type& itr) 00249 { 00250 return element_view_.encap_iter_ <= itr.element_view_.encap_iter_; 00251 } 00252 // > 00253 bool operator>(const iterator_type& itr) 00254 { 00255 return element_view_.encap_iter_ > itr.element_view_.encap_iter_; 00256 } 00257 // >= 00258 bool operator>=(const iterator_type& itr) 00259 { 00260 return element_view_.encap_iter_ >= itr.element_view_.encap_iter_; 00261 } 00262 // == 00263 bool operator==(const iterator_type& itr) 00264 { 00265 return element_view_.encap_iter_ == itr.element_view_.encap_iter_; 00266 } 00267 // != 00268 bool operator!=(const iterator_type& itr) 00269 { 00270 return element_view_.encap_iter_ != itr.element_view_.encap_iter_; 00271 } 00272 00274 00275 private: 00276 element_view_type element_view_; 00277 00278 // not defined and not to be called 00279 TransSparseCOOElementViewIter(); 00280 00281 }; // end class TransSparseCOOElementViewIter 00282 00283 // /////////////////////////////////////////////////////////////////////////////////////// 00284 // Nonmember functions 00285 00286 // Allow distance_type as lhs argument in n + itr 00287 00288 //template <class Iter, class Cat, class Indice, class ValRef, class Diff> 00289 //inline TransSparseCOOElementViewIter<Iter,Cat,Indice,ValRef,Diff> 00290 //operator+(Diff n, TransSparseCOOElementViewIter<Iter,Cat,Indice,ValRef,Diff> itr) 00291 //{ 00292 // return itr + n; 00293 //} 00294 00295 template <class Iter, class Cat, class Indice, class ValRef, class Diff> 00296 inline TransSparseCOOElementViewIter<Iter,Cat,Indice,ValRef,Diff> 00297 operator+(Diff n, const TransSparseCOOElementViewIter<Iter,Cat,Indice,ValRef,Diff> itr) 00298 { 00299 return itr + n; 00300 } 00301 00302 } // end namespace AbstractLinAlgPack 00303 00304 #endif // TRANS_SPARSE_COO_ELEMENT_VIEW_ITER_H
1.7.4