26 using Teuchos::arrayView;
27 using Teuchos::av_const_cast;
28 using Teuchos::av_reinterpret_cast;
46 Array<int> a = generateArray<int>(
n);
47 ArrayView<int> av = a;
54 ArrayView<const int> av_int1 =
null;
62 ArrayRCP<const int> arcp_int = arcp<int>(
n);
63 ArrayView<const int> av_int1 = arcp_int();
75 ArrayView<char> av_char =
null;
84 const int sizeOfInt =
sizeof(int);
85 const int sizeOfChar =
sizeof(char);
86 const int num_ints =
n;
87 const int num_chars = (num_ints*sizeOfInt)/sizeOfChar;
88 out <<
"num_ints = " << num_ints <<
"\n";
89 out <<
"num_chars = " << num_chars <<
"\n";
91 ArrayRCP<char> arcp_char = arcp<char>(num_chars);
95 implicit_ptr_cast<void>(&arcp_char[0]));
96 TEST_EQUALITY(implicit_ptr_cast<void>((&av_int[num_ints-1])+1),
97 implicit_ptr_cast<void>((&arcp_char[num_chars-1])+1));
105 const int sizeOfInt =
sizeof(int);
106 const int sizeOfChar =
sizeof(char);
107 const int num_ints =
n;
108 const int num_chars = (num_ints*sizeOfInt)/sizeOfChar;
109 out <<
"num_ints = " << num_ints <<
"\n";
110 out <<
"num_chars = " << num_chars <<
"\n";
112 ArrayRCP<int> arcp_int = arcp<int>(num_ints);
116 implicit_ptr_cast<void>(&av_char[0]));
117 TEST_EQUALITY(implicit_ptr_cast<void>((&arcp_int[num_ints-1])+1),
118 implicit_ptr_cast<void>((&av_char[num_chars-1])+1));
119 TEST_EQUALITY(implicit_ptr_cast<void>((&arcp_int[num_ints-1])+1),
120 implicit_ptr_cast<void>((&av_char[num_chars-1])+1));
128 const ArrayView<T> av =
arrayView(a.getRawPtr(), a.size());
137 Array<T> a = generateArray<T>(
n);
138 const ArrayView<T> av =
arrayView(&a[0], a.size());
145 const ArrayView<T> av_0;
146 const ArrayView<T> av = av_0(0, 0);
153 const ArrayView<T> av_0;
154 const ArrayView<T> av = av_0.view(0, 0);
162 ArrayView<T> view(data, 10);
167 ArrayView<const T> cview = view.getConst();
168 TEST_EQUALITY(cview.getRawPtr(),
const_cast<const T*
>(data));
171 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
172 ArrayRCP<const T> cview_arcp = cview.access_private_arcp();
173 TEST_EQUALITY(cview_arcp.getRawPtr(),
const_cast<const T*
>(data));
182 T
const * data =
new T[10];
183 ArrayView<const T> view(data, 10);
188 ArrayView<const T> cview = view.getConst();
192 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
193 ArrayRCP<const T> cview_arcp = cview.access_private_arcp();
206 if (view_inout.
size() == 0 && size == 0) {
return; }
207 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
208 const T &next_to_last = view_inout[offset+size-1];
211 view_inout = arrayView<T>(&view_inout[offset],
size);
218 ArrayView<T> view(data, 10);
219 resizeRawView(view, 0, 5);
231 Array<T> a = generateArray<T>(
n);
261 typedef typename ArrayView<T>::iterator iter_t;
263 ECHO(Array<T> a = generateArray<T>(
n));
264 ECHO(ArrayView<T> av = a);
265 ECHO(
const iter_t av_begin = av.begin());
266 ECHO(
const iter_t av_end = av.end());
270 ECHO(std::fill(av_begin, av_end, ST::random()));
271 ECHO(Array<T> a2 = generateArray<T>(
n));
272 ECHO(ArrayView<T> av2 = a2);
273 ECHO(std::copy(av.begin(), av.end(), av2.begin()));
285 ArrayView<const T> av1 = arrayView<T>(&t[0], nsize);
314 ArrayRCP<T> ap =
arcp(
rcp(
new std::vector<T>(
n)));
318 TEST_THROW(av.getRawPtr(), DanglingReferenceError);
319 TEST_THROW(av.data(), DanglingReferenceError);
326 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
329 #endif // HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
338 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
340 # define DEBUG_UNIT_TEST_GROUP( T )
342 #else // HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
344 # define DEBUG_UNIT_TEST_GROUP( T )
346 #endif // HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
349 #define UNIT_TEST_GROUP( T ) \
350 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayView, arrayView_construct_zero_size, T ) \
351 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayView, arrayView, T ) \
352 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayView, null_zero_ArrayView_operator, T ) \
353 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayView, null_zero_ArrayView_func, T ) \
354 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayView, raw_ptr_self_view, T ) \
355 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayView, raw_ptr_self_view_const, T ) \
356 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayView, resize_raw_ptr_self_view, T ) \
357 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayView, assignmentOperator, T ) \
358 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayView, iterators, T ) \
359 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayView, arrayView_convertToConst, T ) \
360 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayView, danglingView_std_vector, T ) \
361 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayView, danglingView_rcp_std_vector, T ) \
362 DEBUG_UNIT_TEST_GROUP( T )
Dangling reference error exception class.
RCP< T > rcp(const boost::shared_ptr< T > &sptr)
Conversion function that takes in a boost::shared_ptr object and spits out a Teuchos::RCP object...
ArrayView< T > arrayView(T *p, typename ArrayView< T >::size_type size)
Construct a const or non-const view to const or non-const data.
#define TEST_ASSERT(v1)
Assert the given statement is true.
#define UNIT_TEST_GROUP(T)
#define ECHO(statement)
Echo the given statement before it is executed.
#define TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL(TEST_GROUP, TEST_NAME, TYPE)
Macro for defining a templated unit test with one template parameter.
size_type size() const
The total number of items in the managed array.
#define TEST_EQUALITY(v1, v2)
Assert the equality of v1 and v2.
#define TEST_THROW(code, ExceptType)
Assert that the statement 'code' throws the exception 'ExceptType' (otherwise the test fails)...
ArrayRCP< T > arcp(const RCP< Array< T > > &v)
Wrap an RCP<Array<T> > object as an ArrayRCP<T> object.
#define TEUCHOS_UNIT_TEST(TEST_GROUP, TEST_NAME)
Macro for defining a (non-templated) unit test.
bool is_null(const ArrayRCP< T > &p)
Returns true if p.get()==NULL.
This structure defines some basic traits for a scalar field type.
ArrayView< T2 > av_reinterpret_cast(const ArrayView< T1 > &p1)
Reinterpret cast of underlying ArrayView type from T1* to T2*.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
ArrayView< T2 > av_const_cast(const ArrayView< T1 > &p1)
Const cast of underlying ArrayView type from const T* to T*.
#define TEST_EQUALITY_CONST(v1, v2)
Assert the equality of v1 and constant v2.
TypeTo * implicit_ptr_cast(TypeFrom *t)
Perform an implicit cast of pointer types with a pointer being returned.
int size(const Comm< Ordinal > &comm)
Get the number of processes in the communicator.
Teuchos::Array< T > generateArray(const int n_in)
TypeTo as(const TypeFrom &t)
Convert from one value type to another.
#define TEST_COMPARE_ARRAYS(a1, a2)
Assert that a1.size()==a2.size() and a[i]==b[i], i=0....
Smart reference counting pointer class for automatic garbage collection.
bool nonnull(const ArrayRCP< T > &p)
Returns true if p.get()!=NULL.
Reference-counted smart pointer for managing arrays.
Replacement for std::vector that is compatible with the Teuchos Memory Management classes...