MOOCHO (Single Doxygen Collection) Version of the Day
AbstractLinAlgPack_MatrixCOORTmplItfc.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 SLAP_MATRIX_COOR_TMPL_ITFC_H
00043 #define SLAP_MATRIX_COOR_TMPL_ITFC_H
00044 
00045 #include <stdexcept>
00046 
00047 #include "AbstractLinAlgPack_Types.hpp"
00048 #include "Teuchos_Assert.hpp"
00049 
00050 namespace AbstractLinAlgPack {
00051 
00052 template<class T_Scalar, class T_Index>
00053 class MatrixCOORTmplItfcItrEleView;
00054 
00055 template<class T_Scalar, class T_Index>
00056 class MatrixCOORTmplItfcItr;
00057 
00061 template<class T_Scalar, class T_Index>
00062 class MatrixCOORTmplItfc {
00063 public:
00064   typedef T_Index                                          size_type;
00065   typedef ptrdiff_t                                        difference_type;
00066   typedef MatrixCOORTmplItfcItrEleView<T_Scalar,T_Index>   element_type;
00067   typedef T_Scalar                                         value_type;
00068   typedef T_Index                                          index_type;
00069   typedef MatrixCOORTmplItfcItr<T_Scalar,T_Index>          const_iterator;
00070   MatrixCOORTmplItfc(
00071     size_type rows, size_type cols, size_type nz
00072     ,difference_type row_offset, difference_type col_offset
00073     ,const T_Scalar *values, const T_Index* row_i, const T_Index* col_j
00074     )
00075     :rows_(rows), cols_(cols), nz_(nz), row_offset_(row_offset), col_offset_(col_offset)
00076     ,values_(values), row_i_(row_i), col_j_(col_j)
00077   {}
00078   size_type       rows()       const { return rows_;       }
00079   size_type       cols()       const { return cols_;       }
00080   size_type       nz()         const { return nz_;         }
00081   difference_type row_offset() const { return row_offset_; }  
00082   difference_type col_offset() const { return col_offset_; }
00083   const_iterator  begin() const;
00084   const_iterator  end() const;
00085 private:
00086   size_type        rows_;
00087     size_type        cols_;
00088   size_type        nz_;
00089   difference_type  row_offset_;
00090   difference_type  col_offset_;
00091   const T_Scalar   *values_;
00092   const T_Index    *row_i_;
00093   const T_Index    *col_j_;
00094   // Not defined and not to be called
00095   MatrixCOORTmplItfc();
00096 }; // end class MatrixCOORTmplItfc
00097 
00098 
00099 // ///////////////////////////////////////////////
00100 // Implementatioins, not of the user to look at!
00101 
00105 template<class T_Scalar, class T_Index>
00106 class MatrixCOORTmplItfcItrEleView {
00107 public:
00108   typedef T_Scalar   value_type;
00109   typedef T_Index    index_type;
00110   MatrixCOORTmplItfcItrEleView(
00111     const T_Scalar* value, const T_Index* row_i, const T_Index* col_j
00112     )
00113     : value_(value), row_i_(row_i), col_j_(col_j)
00114   {}
00115   void increment()       { ++value_; ++row_i_; ++col_j_; }
00116   bool operator!=(const MatrixCOORTmplItfcItrEleView<T_Scalar,T_Index>& ele) const
00117   {   return value_ != ele.value_ || row_i_ != ele.row_i_ || col_j_ != ele.col_j_; }
00118   T_Scalar value() const { return *value_;  }
00119   T_Index  row_i() const { return *row_i_;  }
00120   T_Index  col_j() const { return *col_j_;  }
00121 private:
00122   const T_Scalar  *value_;
00123   const T_Index   *row_i_;
00124   const T_Index   *col_j_;
00125   // Not defined and not to be called
00126   MatrixCOORTmplItfcItrEleView();
00127 }; // end class MatrixCOORTmplItfcItrEleView
00128 
00132 template<class T_Scalar, class T_Index>
00133 class MatrixCOORTmplItfcItr {
00134 public:
00135   MatrixCOORTmplItfcItr( const T_Scalar* value, const T_Index* row_i, const T_Index* col_j, T_Index nz )
00136     : ele_(value,row_i,col_j)
00137 #ifdef TEUCHOS_DEBUG
00138     , nz_left_(nz)
00139 #endif
00140   {}
00141   void operator++() {
00142 #ifdef TEUCHOS_DEBUG
00143     --nz_left_;
00144 #endif
00145     ele_.increment();
00146   }
00147   bool operator!=(const MatrixCOORTmplItfcItr<T_Scalar,T_Index>& itr) const
00148   {   return ele_ != itr.ele_; }
00149   const MatrixCOORTmplItfcItrEleView<T_Scalar,T_Index>* operator->() const
00150   { assert_nz(); return &ele_; }
00151 private:
00152   MatrixCOORTmplItfcItrEleView<T_Scalar,T_Index>  ele_;
00153 #ifdef TEUCHOS_DEBUG
00154   T_Index   nz_left_;
00155   void assert_nz() const
00156   {
00157     TEUCHOS_TEST_FOR_EXCEPTION(
00158       nz_left_ <= 0, std::logic_error
00159       ,"MatrixCOORTmplItfcItr<>::assert_nz: Error, trying to access past storage!" );
00160   }
00161 #else
00162   void assert_nz() const {}
00163 #endif
00164   // Not defined and not to be called
00165   MatrixCOORTmplItfcItr();
00166 }; // end class MatrixCOORTmplItfcItr
00167 
00168 // ///////////////////////////
00169 // Inline members
00170 
00171 // MatrixCOORTmplItfc
00172 
00173 template<class T_Scalar, class T_Index>
00174 inline
00175 typename MatrixCOORTmplItfc<T_Scalar,T_Index>::const_iterator
00176 MatrixCOORTmplItfc<T_Scalar,T_Index>::begin() const
00177 {
00178   return MatrixCOORTmplItfcItr<T_Scalar,T_Index>(values_,row_i_,col_j_,nz_);
00179 }
00180 
00181 template<class T_Scalar, class T_Index>
00182 inline
00183 typename MatrixCOORTmplItfc<T_Scalar,T_Index>::const_iterator
00184 MatrixCOORTmplItfc<T_Scalar,T_Index>::end() const
00185 {
00186   return MatrixCOORTmplItfcItr<T_Scalar,T_Index>(values_+nz_,row_i_+nz_,col_j_+nz_,0);
00187 }
00188 
00189 } // end namespace AbstractLinAlgPack
00190 
00191 #endif // SLAP_MATRIX_COOR_TMPL_ITFC_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines