Teuchos_ArrayConversions.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 #ifndef TEUCHOS_ARRAY_CONVERSIONS_H
00030 #define TEUCHOS_ARRAY_CONVERSIONS_H
00031 
00036 #include "Teuchos_Ptr.hpp"
00037 #include "Teuchos_RCP.hpp"
00038 #include "Teuchos_Array.hpp"
00039 #include "Teuchos_Assert.hpp"
00040 
00041 
00042 namespace Teuchos {
00043 
00044 
00049 template<class ArrayPtrT_in, class T_out>
00050 void arrayViewPtrConv( const ArrayPtrT_in &a_in,
00051   const ArrayView<Ptr<T_out> > &a_out )
00052 {
00053   using Teuchos::as;
00054 #ifdef TEUCHOS_DEBUG
00055   TEUCHOS_ASSERT_EQUALITY(as<Teuchos_Ordinal>(a_in.size()),
00056     as<Teuchos_Ordinal>(a_out.size()));
00057 #endif
00058   for (Teuchos_Ordinal i = 0; i < as<Teuchos_Ordinal>(a_in.size()); ++i) {
00059     a_out[i] = a_in[i].ptr();
00060   }
00061 }
00062 
00063 
00067 template<class ArrayPtrT_in, class T_out>
00068 void arrayViewRcpConv( const ArrayPtrT_in &a_in,
00069   const ArrayView<RCP<T_out> > &a_out )
00070 {
00071   using Teuchos::as;
00072 #ifdef TEUCHOS_DEBUG
00073   TEUCHOS_ASSERT_EQUALITY(as<Teuchos_Ordinal>(a_in.size()),
00074     as<Teuchos_Ordinal>(a_out.size()));
00075 #endif
00076   for (Teuchos_Ordinal i = 0; i < as<Teuchos_Ordinal>(a_in.size()); ++i) {
00077     a_out[i] = a_in[i];
00078   }
00079 }
00080 
00081 
00102 template<class T_out, class ArrayPtrT_in>
00103 Array<Ptr<T_out> > arrayPtrConv(const ArrayPtrT_in &a_in)
00104 {
00105   using Teuchos::as;
00106   Array<Ptr<T_out> > a_out(a_in.size());
00107   arrayViewPtrConv(a_in, a_out());
00108   return a_out;
00109 }
00110 
00111 
00118 template<class T_out, class ArrayPtrT_in>
00119 Array<RCP<T_out> > arrayRcpConv(const ArrayPtrT_in &a_in)
00120 {
00121   using Teuchos::as;
00122   Array<RCP<T_out> > a_out(a_in.size());
00123   arrayViewRcpConv(a_in, a_out());
00124   return a_out;
00125 }
00126 
00127 
00138 template<class T>
00139 ArrayView<const Ptr<const T> >
00140 arrayConstPtrConstCast(const ArrayView<const Ptr<T> > &a_in)
00141 {
00142   return av_reinterpret_cast<const Ptr<const T> >(a_in);
00143 }
00144 
00145 
00156 template<class T>
00157 ArrayView<const RCP<const T> >
00158 arrayConstRcpConstCast(const ArrayView<const RCP<T> > &a_in)
00159 {
00160   return av_reinterpret_cast<const RCP<const T> >(a_in);
00161 }
00162 
00163 
00164 } // namespace Teuchos
00165 
00166 
00167 #endif // TEUCHOS_ARRAY_CONVERSIONS_H
00168 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on Tue Oct 20 10:13:59 2009 for Teuchos Package Browser (Single Doxygen Collection) by  doxygen 1.6.1