Teuchos - Trilinos Tools Package  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Teuchos_ArrayConversions.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 #ifndef TEUCHOS_ARRAY_CONVERSIONS_H
11 #define TEUCHOS_ARRAY_CONVERSIONS_H
12 
17 #include "Teuchos_Ptr.hpp"
18 #include "Teuchos_RCP.hpp"
19 #include "Teuchos_Array.hpp"
20 #include "Teuchos_Assert.hpp"
21 
22 
23 namespace Teuchos {
24 
25 
30 template<class ArrayPtrT_in, class T_out>
31 void arrayViewPtrConv( const ArrayPtrT_in &a_in,
32  const ArrayView<Ptr<T_out> > &a_out )
33 {
34  using Teuchos::as;
35 #ifdef TEUCHOS_DEBUG
36  TEUCHOS_ASSERT_EQUALITY(as<Teuchos_Ordinal>(a_in.size()),
37  as<Teuchos_Ordinal>(a_out.size()));
38 #endif
39  for (Teuchos_Ordinal i = 0; i < as<Teuchos_Ordinal>(a_in.size()); ++i) {
40  a_out[i] = a_in[i].ptr();
41  }
42 }
43 
44 
48 template<class ArrayPtrT_in, class T_out>
49 void arrayViewRcpConv( const ArrayPtrT_in &a_in,
50  const ArrayView<RCP<T_out> > &a_out )
51 {
52  using Teuchos::as;
53 #ifdef TEUCHOS_DEBUG
54  TEUCHOS_ASSERT_EQUALITY(as<Teuchos_Ordinal>(a_in.size()),
55  as<Teuchos_Ordinal>(a_out.size()));
56 #endif
57  for (Teuchos_Ordinal i = 0; i < as<Teuchos_Ordinal>(a_in.size()); ++i) {
58  a_out[i] = a_in[i];
59  }
60 }
61 
62 
83 template<class T_out, class ArrayPtrT_in>
84 Array<Ptr<T_out> > arrayPtrConv(const ArrayPtrT_in &a_in)
85 {
86  using Teuchos::as;
87  Array<Ptr<T_out> > a_out(a_in.size());
88  arrayViewPtrConv(a_in, a_out());
89  return a_out;
90 }
91 
92 
99 template<class T_out, class ArrayPtrT_in>
100 Array<RCP<T_out> > arrayRcpConv(const ArrayPtrT_in &a_in)
101 {
102  using Teuchos::as;
103  Array<RCP<T_out> > a_out(a_in.size());
104  arrayViewRcpConv(a_in, a_out());
105  return a_out;
106 }
107 
108 
119 template<class T>
120 ArrayView<const Ptr<const T> >
122 {
123  return av_reinterpret_cast<const Ptr<const T> >(a_in);
124 }
125 
126 
137 template<class T>
138 ArrayView<const RCP<const T> >
140 {
141  return av_reinterpret_cast<const RCP<const T> >(a_in);
142 }
143 
144 
145 } // namespace Teuchos
146 
147 
148 #endif // TEUCHOS_ARRAY_CONVERSIONS_H
149 
Array< RCP< T_out > > arrayRcpConv(const ArrayPtrT_in &a_in)
Utility function to convert any Array[View,RCP]&lt;[const] RCP&lt;T_in&gt; &gt; object to an Array&lt;RCP&lt;T_out&gt; &gt; o...
void arrayViewPtrConv(const ArrayPtrT_in &a_in, const ArrayView< Ptr< T_out > > &a_out)
Utility function to convert from an an input Array[View,RCP]&lt;[const] PTR&lt;T_in&gt; &gt; object to an output ...
void arrayViewRcpConv(const ArrayPtrT_in &a_in, const ArrayView< RCP< T_out > > &a_out)
Utility function to convert from an input Array[View,RCP]&lt;[const] RCP&lt;T_in&gt; &gt; object to an output Arr...
ArrayView< const RCP< const T > > arrayConstRcpConstCast(const ArrayView< const RCP< T > > &a_in)
Utility function that does a reinterpret case to convert an ArrayView&lt;const RCP&lt;T&gt; &gt; object to an Arr...
Templated array class derived from the STL std::vector.
Nonowning array view.
Array< Ptr< T_out > > arrayPtrConv(const ArrayPtrT_in &a_in)
Utility function to convert an Array[View,RCP]&lt;[const] PTR&lt;T_in&gt; &gt; object to an Array&lt;Ptr&lt;T_out&gt; &gt; ob...
TypeTo as(const TypeFrom &t)
Convert from one value type to another.
Smart reference counting pointer class for automatic garbage collection.
ArrayView< const Ptr< const T > > arrayConstPtrConstCast(const ArrayView< const Ptr< T > > &a_in)
Utility function that does a reinterpret case to convert an ArrayView&lt;const Ptr&lt;T&gt; &gt; object to an Arr...
#define TEUCHOS_ASSERT_EQUALITY(val1, val2)
This macro is checks that to numbers are equal and if not then throws an exception with a good error ...
Reference-counted pointer class and non-member templated function implementations.
Simple wrapper class for raw pointers to single objects where no persisting relationship exists...
Replacement for std::vector that is compatible with the Teuchos Memory Management classes...