60 using Teuchos::arrayView;
61 using Teuchos::av_const_cast;
62 using Teuchos::av_reinterpret_cast;
80 Array<int> a = generateArray<int>(
n);
81 ArrayView<int> av = a;
88 ArrayView<const int> av_int1 =
null;
96 ArrayRCP<const int> arcp_int = arcp<int>(
n);
97 ArrayView<const int> av_int1 = arcp_int();
107 ArrayView<char> av_char =
null;
116 const int sizeOfInt =
sizeof(int);
117 const int sizeOfChar =
sizeof(char);
118 const int num_ints =
n;
119 const int num_chars = (num_ints*sizeOfInt)/sizeOfChar;
120 out <<
"num_ints = " << num_ints <<
"\n";
121 out <<
"num_chars = " << num_chars <<
"\n";
123 ArrayRCP<char> arcp_char = arcp<char>(num_chars);
127 implicit_ptr_cast<void>(&arcp_char[0]));
128 TEST_EQUALITY(implicit_ptr_cast<void>((&av_int[num_ints-1])+1),
129 implicit_ptr_cast<void>((&arcp_char[num_chars-1])+1));
137 const int sizeOfInt =
sizeof(int);
138 const int sizeOfChar =
sizeof(char);
139 const int num_ints =
n;
140 const int num_chars = (num_ints*sizeOfInt)/sizeOfChar;
141 out <<
"num_ints = " << num_ints <<
"\n";
142 out <<
"num_chars = " << num_chars <<
"\n";
144 ArrayRCP<int> arcp_int = arcp<int>(num_ints);
148 implicit_ptr_cast<void>(&av_char[0]));
149 TEST_EQUALITY(implicit_ptr_cast<void>((&arcp_int[num_ints-1])+1),
150 implicit_ptr_cast<void>((&av_char[num_chars-1])+1));
151 TEST_EQUALITY(implicit_ptr_cast<void>((&arcp_int[num_ints-1])+1),
152 implicit_ptr_cast<void>((&av_char[num_chars-1])+1));
160 const ArrayView<T> av =
arrayView(a.getRawPtr(), a.size());
169 Array<T> a = generateArray<T>(
n);
170 const ArrayView<T> av =
arrayView(&a[0], a.size());
177 const ArrayView<T> av_0;
178 const ArrayView<T> av = av_0(0, 0);
185 const ArrayView<T> av_0;
186 const ArrayView<T> av = av_0.view(0, 0);
194 ArrayView<T> view(data, 10);
198 ArrayView<const T> cview = view.getConst();
199 TEST_EQUALITY(cview.getRawPtr(),
const_cast<const T*
>(data));
201 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 202 ArrayRCP<const T> cview_arcp = cview.access_private_arcp();
203 TEST_EQUALITY(cview_arcp.getRawPtr(),
const_cast<const T*
>(data));
212 T
const * data =
new T[10];
213 ArrayView<const T> view(data, 10);
217 ArrayView<const T> cview = view.getConst();
220 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 221 ArrayRCP<const T> cview_arcp = cview.access_private_arcp();
234 if (view_inout.
size() == 0 &&
size == 0) {
return; }
235 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 236 const T &next_to_last = view_inout[offset+
size-1];
239 view_inout = arrayView<T>(&view_inout[offset],
size);
246 ArrayView<T> view(data, 10);
247 resizeRawView(view, 0, 5);
258 Array<T> a = generateArray<T>(
n);
280 typedef typename ArrayView<T>::iterator iter_t;
282 ECHO(Array<T> a = generateArray<T>(
n));
283 ECHO(ArrayView<T> av = a);
284 ECHO(
const iter_t av_begin = av.begin());
285 ECHO(
const iter_t av_end = av.end());
289 ECHO(std::fill(av_begin, av_end, ST::random()));
290 ECHO(Array<T> a2 = generateArray<T>(
n));
291 ECHO(ArrayView<T> av2 = a2);
292 ECHO(std::copy(av.begin(), av.end(), av2.begin()));
304 ArrayView<const T> av1 = arrayView<T>(&t[0], nsize);
332 ArrayRCP<T> ap =
arcp(
rcp(
new std::vector<T>(
n)));
336 TEST_THROW(av.getRawPtr(), DanglingReferenceError);
343 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 346 #endif // HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 355 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 357 # define DEBUG_UNIT_TEST_GROUP( T ) 359 #else // HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 361 # define DEBUG_UNIT_TEST_GROUP( T ) 363 #endif // HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 366 #define UNIT_TEST_GROUP( T ) \ 367 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayView, arrayView_construct_zero_size, T ) \ 368 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayView, arrayView, T ) \ 369 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayView, null_zero_ArrayView_operator, T ) \ 370 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayView, null_zero_ArrayView_func, T ) \ 371 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayView, raw_ptr_self_view, T ) \ 372 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayView, raw_ptr_self_view_const, T ) \ 373 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayView, resize_raw_ptr_self_view, T ) \ 374 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayView, assignmentOperator, T ) \ 375 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayView, iterators, T ) \ 376 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayView, arrayView_convertToConst, T ) \ 377 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayView, danglingView_std_vector, T ) \ 378 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayView, danglingView_rcp_std_vector, T ) \ 379 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.
#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)...
size_type size() const
The total number of items in the managed array.
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...