Teuchos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ArrayConversions_UnitTest_helpers.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Teuchos: Common Tools Package
4 //
5 // Copyright 2004 NTESS and the Teuchos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 
11 #ifndef ARRAY_CONVERSIONS_UNIT_TEST_HELPERS
12 #define ARRAY_CONVERSIONS_UNIT_TEST_HELPERS
13 
14 
15 namespace ArrayConversionsUnitTestHelpers {
16 
17 
18 using Teuchos::RCP;
19 using Teuchos::rcp;
20 using Teuchos::Ptr;
21 using Teuchos::Array;
22 using Teuchos::ArrayView;
23 using Teuchos::as;
24 
25 extern Teuchos_Ordinal n;
26 
27 
28 template<class T>
30 {
31  Array<RCP<T> > a(n_in);
32  for (Teuchos_Ordinal i=0 ; i<n_in ; ++i) {
33  RCP<T> data = rcp(new T(as<T>(i)));
34  a[i] = data;
35  }
36  return a;
37 }
38 
39 
40 template<class T>
42 {
43  Array<RCP<T> > a;
44  for (Teuchos_Ordinal i=0 ; i<n_in ; ++i) {
45  a.push_back(rcp(new T));
46  }
47  return a;
48 }
49 
50 
51 template<class T>
53 {
54  typedef Teuchos::ScalarTraits<T> ST;
55  T a = ST::zero();
56  for (Teuchos_Ordinal i=0; i<a_in.size(); ++i) {
57  a += *a_in[i];
58  }
59  return a;
60 }
61 
62 
63 template<class T>
64 void testArrayViewOutput(const ArrayView<const Ptr<T> >& a_out)
65 {
66  for (Teuchos_Ordinal i=0 ; i<a_out.size() ; ++i) {
67  *a_out[i] = as<T>(i);
68  }
69 }
70 
71 
72 } // namespace ArrayConversionsUnitTestHelpers
73 
74 
75 #endif // ARRAY_CONVERSIONS_UNIT_TEST_HELPERS
T testArrayViewInput(const ArrayView< const Ptr< const T > > &a_in)
This structure defines some basic traits for a scalar field type.
TEUCHOS_ORDINAL_TYPE Teuchos_Ordinal
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
TypeTo as(const TypeFrom &t)
Convert from one value type to another.
void testArrayViewOutput(const ArrayView< const Ptr< T > > &a_out)
void push_back(const value_type &x)
Nonowning array view.
Array< RCP< T > > generateArrayRcp(const Teuchos_Ordinal n_in)
Smart reference counting pointer class for automatic garbage collection.
Simple wrapper class for raw pointers to single objects where no persisting relationship exists...
Array< RCP< T > > generateArrayRcpGen(const Teuchos_Ordinal n_in)
Replacement for std::vector that is compatible with the Teuchos Memory Management classes...