DenseLinAlgPack_IVector.hpp

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 IVECTOR_H
00030 #define IVECTOR_H
00031 
00032 #include <assert.h>
00033 
00034 #include <valarray>
00035 
00036 #include "DenseLinAlgPack_Types.hpp"
00037 #include "Teuchos_TestForException.hpp"
00038 
00039 namespace DenseLinAlgPack {
00041 /* * Fortran compatable integer vector for holding the  pivot information for
00042  * the elements of a vector, or the rows or columns of a matrix.
00043  */
00044 class IVector : public std::valarray<DenseLinAlgPack::size_type> {
00045 public:
00046 
00047   // STL typedefs
00048   typedef DenseLinAlgPack::index_type   value_type;
00049   typedef DenseLinAlgPack::size_type    size_type;
00050   typedef value_type&         reference;
00051   typedef const value_type&     const_reference;
00052   typedef value_type*         iterator;
00053   typedef const value_type*     const_iterator;
00054   typedef std::valarray<size_type>  valarray;
00055 
00056   // constructors
00057 
00059   IVector();
00061   IVector(size_type n);
00063   IVector(const value_type& val, size_type n);
00065   IVector(const value_type* p, size_type n);
00066 
00068   IVector& operator=(const IVector&);
00069 
00071   reference operator()(size_type i);
00073   const_reference operator()(size_type i) const;
00074 
00076   iterator begin();
00078   const_iterator begin() const;
00080   iterator end();
00082   const_iterator end() const;
00083 
00084 }; // end class IVector
00085 
00086 // Inline definitions
00087 
00088 inline IVector::IVector() : std::valarray<size_type>()
00089 {}
00090 
00091 inline IVector::IVector(size_type n) : std::valarray<size_type>(n)
00092 {}
00093 
00094 inline IVector::IVector(const value_type& val, size_type n) : std::valarray<size_type>(val,n)
00095 {}
00096 
00097 inline IVector::IVector(const value_type* p, size_type n) : std::valarray<size_type>(p,n)
00098 {}
00099 
00100 inline IVector& IVector::operator=(const IVector& iv)
00101 {
00102   this->resize(iv.size());
00103   std::valarray<DenseLinAlgPack::size_type>::operator=(iv);
00104   return *this;
00105 }
00106 
00107 inline IVector::reference IVector::operator()(size_type i)
00108 {
00109 #ifdef TEUCHOS_DEBUG
00110   TEST_FOR_EXCEPT( !(  1 <= i && i <= static_cast<size_type>(size())  ) );
00111 #endif
00112   return operator[](i-1);
00113 }
00114 
00115 inline IVector::const_reference IVector::operator()(size_type i) const
00116 {
00117 #ifdef TEUCHOS_DEBUG
00118   TEST_FOR_EXCEPT( !(  1 <= i && i <= static_cast<size_type>(size())  ) );
00119 #endif
00120   return const_cast<IVector*>(this)->operator[](i-1);
00121 }
00122 
00123 inline IVector::iterator IVector::begin()
00124 { return &operator[](0); }
00125 
00126 inline IVector::const_iterator IVector::begin() const
00127 { return &(const_cast<IVector*>(this)->operator[](0)); }
00128 
00129 inline IVector::iterator IVector::end()
00130 { return begin() + size(); }
00131 
00132 inline IVector::const_iterator IVector::end() const
00133 { return begin() + size(); }
00134 
00135 } // end namespace DenseLinAlgPack
00136 
00137 #endif // IVECTOR_H

Generated on Wed May 12 21:31:33 2010 for DenseLinAlgPack: Concreate C++ Classes for Dense Blas-Compatible Linear Algebra by  doxygen 1.4.7