Teuchos_SerialDenseVector.hpp

Go to the documentation of this file.
00001 // @HEADER
00002 // ***********************************************************************
00003 // 
00004 //                    Teuchos: Common Tools Package
00005 //                 Copyright (2004) 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 Michael A. Heroux (maherou@sandia.gov) 
00025 // 
00026 // ***********************************************************************
00027 // @HEADER
00028 
00029 
00030 #ifndef _TEUCHOS_SERIALDENSEVECTOR_HPP_
00031 #define _TEUCHOS_SERIALDENSEVECTOR_HPP_
00032 
00037 #include "Teuchos_ConfigDefs.hpp"
00038 #include "Teuchos_Object.hpp" 
00039 #include "Teuchos_SerialDenseMatrix.hpp"
00040 
00044 namespace Teuchos {
00045 
00046   template<typename OrdinalType, typename ScalarType>
00047   class SerialDenseVector : public SerialDenseMatrix<OrdinalType,ScalarType> {
00048     
00049   public:
00051 
00053 
00055     SerialDenseVector();
00056 
00058 
00063     SerialDenseVector(int length);
00064 
00066 
00071     SerialDenseVector(DataAccess CV, ScalarType* values, int length);
00072 
00074     SerialDenseVector(const SerialDenseVector<OrdinalType,ScalarType>& Source);
00075 
00077     virtual ~SerialDenseVector ();
00079 
00081 
00083 
00090     int size(int length) {return(SerialDenseMatrix<OrdinalType, ScalarType>::shape(length, 1));};
00091 
00093 
00099     int resize(int length) {return(SerialDenseMatrix<OrdinalType,ScalarType>::reshape(length, 1));};
00101 
00103 
00104 
00106     bool operator == (const SerialDenseVector<OrdinalType, ScalarType> &Operand);
00107 
00109 
00111     bool operator != (const SerialDenseVector<OrdinalType, ScalarType> &Operand);
00113 
00115 
00117 
00123     SerialDenseVector<OrdinalType,ScalarType>& operator = (const SerialDenseVector<OrdinalType,ScalarType>& Source);
00125 
00127 
00128 
00132     ScalarType& operator () (int index);
00133     
00135 
00139     const ScalarType& operator () (int index) const;
00140 
00142 
00146     ScalarType& operator [] (int index);
00147 
00149 
00153     const ScalarType& operator [] (int index) const;
00154 
00156 
00158 
00159     int length() const {return(this->numRows_);};
00161 
00163 
00164     virtual void print(ostream& os) const;
00166 };
00167 
00168   template<typename OrdinalType, typename ScalarType>
00169   SerialDenseVector<OrdinalType, ScalarType>::SerialDenseVector() : SerialDenseMatrix<OrdinalType,ScalarType>() {}
00170 
00171   template<typename OrdinalType, typename ScalarType>
00172   SerialDenseVector<OrdinalType, ScalarType>::SerialDenseVector( int length ) : SerialDenseMatrix<OrdinalType,ScalarType>( length, 1 ) {}
00173 
00174   template<typename OrdinalType, typename ScalarType>
00175   SerialDenseVector<OrdinalType, ScalarType>::SerialDenseVector(DataAccess CV, ScalarType* values, int length) : 
00176     SerialDenseMatrix<OrdinalType,ScalarType>( CV, values, length, length, 1 ) {}
00177 
00178   template<typename OrdinalType, typename ScalarType>
00179   SerialDenseVector<OrdinalType, ScalarType>::SerialDenseVector(const SerialDenseVector<OrdinalType, ScalarType> &Source) :
00180     SerialDenseMatrix<OrdinalType,ScalarType>( Source ) {}
00181 
00182   template<typename OrdinalType, typename ScalarType>
00183   SerialDenseVector<OrdinalType, ScalarType>::~SerialDenseVector() {}
00184   
00185   template<typename OrdinalType, typename ScalarType>
00186   SerialDenseVector<OrdinalType, ScalarType>& SerialDenseVector<OrdinalType,ScalarType>::operator = (const SerialDenseVector<OrdinalType, ScalarType>& Source) 
00187   {
00188     SerialDenseMatrix<OrdinalType,ScalarType>::operator=(Source); 
00189     return(*this);
00190   }
00191 
00192   template<typename OrdinalType, typename ScalarType>
00193   bool SerialDenseVector<OrdinalType, ScalarType>::operator == (const SerialDenseVector<OrdinalType, ScalarType> &Operand) 
00194   {
00195     bool result = 1;
00196     if(this->numRows_ != Operand.numRows_)
00197       {
00198   result = 0;
00199       }
00200     else
00201       {
00202   int i;
00203   for(i = 0; i < this->numRows_; i++) {
00204     if((*this)(i) != Operand(i))
00205       {
00206         return 0;
00207       }
00208   }
00209       }
00210     return result;
00211   }
00212 
00213   template<typename OrdinalType, typename ScalarType>
00214   bool SerialDenseVector<OrdinalType, ScalarType>::operator != (const SerialDenseVector<OrdinalType, ScalarType> &Operand)
00215   {
00216     return !((*this)==Operand);
00217   }
00218 
00219   template<typename OrdinalType, typename ScalarType>
00220   void SerialDenseVector<OrdinalType, ScalarType>::print(ostream& os) const
00221   {
00222     os << endl;
00223     if(this->valuesCopied_)
00224       os << "Values_copied : yes" << endl;
00225     else
00226       os << "Values_copied : no" << endl;
00227       os << "Length : " << this->numRows_ << endl;
00228     if(this->numRows_ == 0) {
00229       os << "(vector is empty, no values to display)" << endl;
00230     } else {
00231       for(int i = 0; i < this->numRows_; i++) {
00232     os << (*this)(i) << " ";
00233       }
00234       os << endl;
00235     }
00236   }
00237 
00238   //----------------------------------------------------------------------------------------------------
00239   //   Accessor methods 
00240   //----------------------------------------------------------------------------------------------------
00241 
00242   template<typename OrdinalType, typename ScalarType>
00243   inline ScalarType& SerialDenseVector<OrdinalType, ScalarType>::operator () (int index)
00244   {
00245 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
00246     this->checkIndex( index );
00247 #endif
00248     return(this->values_[index]);
00249   }
00250   
00251   template<typename OrdinalType, typename ScalarType>
00252   inline const ScalarType& SerialDenseVector<OrdinalType, ScalarType>::operator () (int index) const
00253   {
00254 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
00255     this->checkIndex( index );
00256 #endif
00257     return(this->values_[index]);
00258   }
00259   
00260   template<typename OrdinalType, typename ScalarType>
00261   inline const ScalarType& SerialDenseVector<OrdinalType, ScalarType>::operator [] (int index) const
00262   {
00263 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
00264     this->checkIndex( index );
00265 #endif
00266     return(this->values_[index]);
00267   }
00268   
00269   template<typename OrdinalType, typename ScalarType>
00270   inline ScalarType& SerialDenseVector<OrdinalType, ScalarType>::operator [] (int index)
00271   {
00272 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
00273     this->checkIndex( index );
00274 #endif
00275     return(this->values_[index]);
00276   }
00277 
00278 } // namespace Teuchos
00279 
00280 #endif /* _TEUCHOS_SERIALDENSEVECTOR_HPP_ */

Generated on Thu Sep 18 12:41:17 2008 for Teuchos - Trilinos Tools Package by doxygen 1.3.9.1