Teuchos Package Browser (Single Doxygen Collection) Version of the Day
ArrayConversions_UnitTest_helpers.hpp
Go to the documentation of this file.
00001 /*
00002 // @HEADER
00003 // ***********************************************************************
00004 //
00005 //                    Teuchos: Common Tools Package
00006 //                 Copyright (2004) Sandia Corporation
00007 //
00008 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00009 // license for use of this work by or on behalf of the U.S. Government.
00010 //
00011 // This library is free software; you can redistribute it and/or modify
00012 // it under the terms of the GNU Lesser General Public License as
00013 // published by the Free Software Foundation; either version 2.1 of the
00014 // License, or (at your option) any later version.
00015 //
00016 // This library is distributed in the hope that it will be useful, but
00017 // WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019 // Lesser General Public License for more details.
00020 //
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License along with this library; if not, write to the Free Software
00023 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00024 // USA
00025 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
00026 //
00027 // ***********************************************************************
00028 // @HEADER
00029 */
00030 
00031 
00032 #ifndef ARRAY_CONVERSIONS_UNIT_TEST_HELPERS
00033 #define ARRAY_CONVERSIONS_UNIT_TEST_HELPERS
00034 
00035 
00036 namespace ArrayConversionsUnitTestHelpers {
00037 
00038 
00039 using Teuchos::RCP;
00040 using Teuchos::rcp;
00041 using Teuchos::Ptr;
00042 using Teuchos::Array;
00043 using Teuchos::ArrayView;
00044 using Teuchos::as;
00045 
00046 extern Teuchos_Ordinal n;
00047 
00048 
00049 template<class T>
00050 Array<RCP<T> > generateArrayRcp(const Teuchos_Ordinal n_in)
00051 {
00052   Array<RCP<T> > a(n_in);
00053   for (Teuchos_Ordinal i=0 ; i<n_in ; ++i) {
00054     RCP<T> data = rcp(new T(as<T>(i)));
00055     a[i] = data;
00056   }
00057   return a;
00058 }
00059 
00060 
00061 template<class T>
00062 Array<RCP<T> > generateArrayRcpGen(const Teuchos_Ordinal n_in)
00063 {
00064   Array<RCP<T> > a;
00065   for (Teuchos_Ordinal i=0 ; i<n_in ; ++i) {
00066     a.push_back(rcp(new T));
00067   }
00068   return a;
00069 }
00070 
00071 
00072 template<class T>
00073 T testArrayViewInput(const ArrayView<const Ptr<const T> >& a_in)
00074 {
00075   typedef Teuchos::ScalarTraits<T> ST;
00076   T a = ST::zero();
00077   for (Teuchos_Ordinal i=0; i<a_in.size(); ++i) {
00078     a += *a_in[i];
00079   }
00080   return a;
00081 }
00082 
00083 
00084 template<class T>
00085 void testArrayViewOutput(const ArrayView<const Ptr<T> >& a_out)
00086 {
00087   typedef Teuchos::ScalarTraits<T> ST;
00088   for (Teuchos_Ordinal i=0 ; i<a_out.size() ; ++i) {
00089     *a_out[i] = as<T>(i);
00090   }
00091 }
00092 
00093 
00094 } // namespace ArrayConversionsUnitTestHelpers 
00095 
00096 
00097 #endif // ARRAY_CONVERSIONS_UNIT_TEST_HELPERS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines