50 <<
"\n*** Testing iterators and accessors for ptr = " << ptr
55 const int size = ptr.size();
60 out <<
"\nChecking ++itr and < ...\n";
61 ArrayRCP<T> itr =
ptr;
62 for(
int i = 0; itr < ptr+
size; ++i, ++itr )
67 out <<
"\nChecking itr++ and <= ...\n";
68 ArrayRCP<T> itr =
ptr;
69 for(
int i = 0; itr <= ptr+size-1; ++i, itr++ )
74 out <<
"\nChecking itr+=1 and != ...\n";
75 ArrayRCP<T> itr =
ptr;
76 for(
int i = 0; itr != ptr+
size; ++i, itr+=1 )
81 out <<
"\nChecking itr=itr+1 and == ...\n";
82 ArrayRCP<T> itr =
ptr;
83 for(
int i = 0; !( itr == ptr+
size ); ++i, itr=itr+1 )
90 out <<
"\nChecking --itr and >= ...\n";
91 ArrayRCP<T> itr = ptr+size-1;
92 for(
int i = size-1; itr >=
ptr; --i, --itr )
97 out <<
"\nChecking itr-- and > ...\n";
98 ArrayRCP<T> itr = ptr+size-1;
99 for(
int i = size-1; itr+1 >
ptr; i--, itr-- )
104 out <<
"\nChecking itr-=1 and != ...\n";
105 ArrayRCP<T> itr = ptr+size-1;
106 for(
int i = size-1; itr+1 !=
ptr; i--, itr-=1 )
111 out <<
"\nChecking itr=itr-1 and == ...\n";
112 ArrayRCP<T> itr = ptr+size-1;
113 for(
int i = size-1; !( itr+1 ==
ptr ); i--, itr=itr-1 )
120 out <<
"\nChecking ptr.end() - ptr.begin() == ptr.size() ...\n";
127 out <<
"\nChecking iterator ++itr and < ...\n";
128 typename ArrayRCP<T>::const_iterator itr = ptr.begin();
129 for(
int i = 0; itr < ptr.end(); ++i, ++itr )
134 out <<
"\nChecking iterator itr++ and <= ...\n";
135 typename ArrayRCP<T>::const_iterator itr = ptr.begin();
136 for(
int i = 0; itr <= ptr.end()-1; ++i, itr++ )
141 out <<
"\nChecking iterator itr+=1 and != ...\n";
142 typename ArrayRCP<T>::const_iterator itr = ptr.begin();
143 for(
int i = 0; itr != ptr.end(); ++i, itr+=1 )
148 out <<
"\nChecking iterator itr=itr+1 and == ...\n";
149 typename ArrayRCP<T>::const_iterator itr = ptr.begin();
150 for(
int i = 0; !( itr == ptr.end() ); ++i, itr=itr+1 )
157 out <<
"\nChecking iterator --itr and >= ...\n";
158 typename ArrayRCP<T>::const_iterator itr = ptr.begin()+size-1;
159 for(
int i = size-1; itr >= ptr.begin(); --i, --itr )
164 out <<
"\nChecking iterator itr-- and > ...\n";
165 typename ArrayRCP<T>::const_iterator itr = ptr.begin()+size-1;
166 for(
int i = size-1; itr+1 > ptr.begin(); i--, itr-- )
171 out <<
"\nChecking iterator itr-=1 and != ...\n";
172 typename ArrayRCP<T>::const_iterator itr = ptr.begin()+size-1;
173 for(
int i = size-1; itr+1 != ptr.begin(); i--, itr-=1 )
178 out <<
"\nChecking iterator itr=itr-1 and == ...\n";
179 typename ArrayRCP<T>::const_iterator itr = ptr.begin()+size-1;
180 for(
int i = size-1; !( itr+1 == ptr.begin() ); i--, itr=itr-1 )
204 using Teuchos::arcp_const_cast;
207 bool success =
true, result;
211 <<
"\n*** Testing ptr = " << ptr
216 const int n = ptr.size();
219 out <<
"\nInitializing data ...\n";
220 for(
int i = 0; i <
n; ++i )
228 if (!result) success =
false;
231 out <<
"\nTest const casting ...\n";
235 const ArrayRCP<const T> cptr2 =
ptr;
241 out <<
"\nTest views ...\n";
245 out <<
"\nTest full non-const subview ...\n";
246 const ArrayView<T> av2 =
ptr(0,n);
251 out <<
"\nTest full shorthand non-const subview ...\n";
252 const ArrayView<T> av2 =
ptr();
257 out <<
"\nTest full const subview ...\n";
258 const ArrayView<const T> cav2 = ptr.getConst()(0,
n);
263 out <<
"\nTest full non-const to const subview ...\n";
264 const ArrayView<const T> cav2 =
ptr(0,n);
269 out <<
"\nTest full short-hand const subview ...\n";
270 const ArrayView<const T> cav2 = ptr.getConst()();
275 out <<
"\nTest implicit conversion from ArrayRCP<T> to ArrayView<T> ...\n";
276 const ArrayView<T> av2 =
ptr();
281 out <<
"\nTest implicit conversion from ArrayRCP<const T> to ArrayView<const T> ...\n";
282 const ArrayView<const T> av2 = ptr.getConst()();
287 out <<
"\nTest almost implicit conversion from ArrayRCP<T> to ArrayView<const T> ...\n";
288 const ArrayView<const T> av2 =
ptr();
293 out <<
"\nTest implicit conversion from ArrayRCP<T> to ArrayRCP<const T> ...\n";
294 const ArrayRCP<const T> ptr2 =
ptr;
299 out <<
"\nTest clone of ArrayView<T> to ArrayRCP<T> ...\n";
300 const ArrayRCP<T> ptr2 = Teuchos::arcpClone<T>(
ptr());
305 out <<
"\nTest clone of ArrayPtr<const T> to ArrayRCP<T> ...\n";
306 const ArrayRCP<T> ptr2 = Teuchos::arcpClone<T>(ptr.getConst()());
310 out <<
"\nTest extra data ...\n";
311 ArrayRCP<T> ptr2 = arcp<T>(
n);
312 Teuchos::set_extra_data( as<int>(1),
"int", Teuchos::inOutArg(ptr2) );
326 int main(
int argc,
char* argv[] )
337 using Teuchos::arcp_reinterpret_cast;
339 bool success =
true, result;
348 int num_doubles = 10;
349 CommandLineProcessor clp(
false);
350 clp.setOption(
"num-ints", &num_ints,
"Number of ints to allocate space for" );
351 clp.setOption(
"num-doubles", &num_doubles,
"Number of doubles to allocate space for" );
352 CommandLineProcessor::EParseCommandLineReturn parse_return = clp.parse(argc,argv);
353 if( parse_return != CommandLineProcessor::PARSE_SUCCESSFUL ) {
354 *out <<
"\nEnd Result: TEST FAILED" << std::endl;
358 const int sizeOfDouble =
sizeof(double);
359 const int sizeOfInt =
sizeof(int);
361 const int total_bytes = num_doubles*sizeOfDouble + num_ints*sizeOfInt;
365 *out <<
"\nTesting basic ArrayRCP functionality ...\n";
368 char_ptr1 = arcp<char>(total_bytes);
370 *out <<
"\nchar_ptr1 = " << char_ptr1 <<
"\n";
379 if (!result) success =
false;
384 *out <<
"\nchar_ptr2 = " << char_ptr2 <<
"\n";
393 char_ptr2b(char_ptr1);
395 *out <<
"\nchar_ptr2b = " << char_ptr2b <<
"\n";
404 if (!result) success =
false;
414 char_ptr3 = char_ptr1.persistingView(total_bytes/2,total_bytes/2);
421 if (!result) success =
false;
423 *out <<
"\nchar_ptr3 = " << char_ptr3 <<
"\n";
425 *out <<
"\nBreak up char_ptr1 into views of double and int data\n";
430 char_ptr1.persistingView(offset,sizeOfDouble*num_doubles)
433 *out <<
"\ndouble_ptr1 = " << double_ptr1 <<
"\n";
440 if (!result) success =
false;
442 offset += sizeOfDouble*num_doubles;
445 char_ptr1.persistingView(offset,sizeOfInt*num_ints)
448 *out <<
"\nint_ptr1 = " << int_ptr1 <<
"\n";
455 if (!result) success =
false;
457 *out <<
"\nCreating a constant view of double_ptr1\n";
459 ArrayRCP<const double>
460 double_ptr2 = double_ptr1.
getConst();
463 if (!result) success =
false;
465 #ifdef SHOW_COMPILE_FAILURE_1
469 for(
int i = 0; i < double_ptr2.size(); ++i ) {
470 double_ptr2[i] = 1.0;
474 *out <<
"\nCreating an array of RCP objects!\n";
476 ArrayRCP<RCP<double> >
477 rcp_ptr1 = arcp<RCP<double> >(num_doubles);
479 for(
int i = 0; i < num_doubles; ++i )
480 rcp_ptr1[i] =
rcp(
new double(i));
483 if (!result) success =
false;
485 *out <<
"\nCreating a const view of rcp_ptr1\n";
487 ArrayRCP<const RCP<double> >
491 if (!result) success =
false;
493 *out <<
"\nCreating an ARCP<double*> object doubleptr_ptr1 and dynamically allocation each element\n";
496 doubleptr_ptr1 = arcp<double*>(total_bytes);
498 for(
int i = 0; i < doubleptr_ptr1.size(); ++i )
499 doubleptr_ptr1[i] =
new double(i);
502 if (!result) success =
false;
504 *out <<
"\nCreating an ARCP<double*const> view of a doubleptr_ptr1\n";
506 ArrayRCP<double*const>
507 doubleptr_ptr2 = doubleptr_ptr1.
getConst();
510 if (!result) success =
false;
512 #ifdef SHOW_COMPILE_FAILURE_2
516 for(
int i = 0; i < doubleptr_ptr2.size(); ++i ) {
517 *doubleptr_ptr2[i] = 1.0;
518 doubleptr_ptr2[i] = NULL;
522 *out <<
"\nCreating an ARCP<const double * const> view of a doubleptr_ptr1\n";
524 ArrayRCP<const double*const>
525 doubleptr_ptr3 = Teuchos::arcp_implicit_cast<
const double*
const>(doubleptr_ptr1);
528 if (!result) success =
false;
530 #ifdef SHOW_COMPILE_FAILURE_3
534 for(
int i = 0; i < doubleptr_ptr3.size(); ++i ) {
535 *doubleptr_ptr3[i] = 1.0;
536 doubleptr_ptr3[i] = NULL;
540 for(
int i = 0; i < doubleptr_ptr1.size(); ++i )
541 delete doubleptr_ptr1[i];
543 *out <<
"\nWrapping RCP<std::vector<T> > objects as ArrayRCP objects ...\n";
548 vchar_ptr1 =
arcp(
rcp(
new std::vector<char>(total_bytes)));
550 *out <<
"\nvchar_ptr1 = " << vchar_ptr1 <<
"\n";
553 if (!result) success =
false;
555 ArrayRCP<const char> vchar_ptr2 = vchar_ptr1;
557 *out <<
"\nvchar_ptr2 = " << vchar_ptr2 <<
"\n";
560 if (!result) success =
false;
573 *out <<
"\nWrapping RCP<ARray<T> > objects as ArrayRCP objects ...\n";
580 *out <<
"\nvchar_ptr1 = " << vchar_ptr1 <<
"\n";
583 if (!result) success =
false;
598 *out <<
"\nAll tests for ArrayRCP seem to check out!\n";
604 *out <<
"\nEnd Result: TEST PASSED" << std::endl;
606 return ( success ? 0 : 1 );
bool test_ArrayRCP(const Teuchos::ArrayRCP< T > &ptr, Teuchos::FancyOStream &out)
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...
RCP< const T > getConst() const
Return an RCP<const T> version of *this.
ArrayRCP< T > arcp(const RCP< Array< T > > &v)
Wrap an RCP<Array<T> > object as an ArrayRCP<T> object.
Tabbing class for helping to create formated, indented output for a basic_FancyOStream object...
Initialize, finalize, and query the global MPI session.
ArrayRCP< T2 > arcp_reinterpret_cast(const ArrayRCP< T1 > &p1)
Reinterpret cast of underlying ArrayRCP type from T1* to T2*.
TEUCHOS_ORDINAL_TYPE Teuchos_Ordinal
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
Utilities to make writing tests easier.
std::ostream subclass that performs the magic of indenting data sent to an std::ostream object among ...
#define TEUCHOS_STANDARD_CATCH_STATEMENTS(VERBOSE, ERR_STREAM, SUCCESS_FLAG)
Simple macro that catches and reports standard exceptions and other exceptions.
static RCP< FancyOStream > getDefaultOStream()
Get the default output stream object.
#define TEST_EQUALITY_CONST(v1, v2)
Assert the equality of v1 and constant v2.
std::string Teuchos_Version()
int size(const Comm< Ordinal > &comm)
Get the number of processes in the communicator.
TypeTo as(const TypeFrom &t)
Convert from one value type to another.
Ptr< T > ptr(T *p)
Create a pointer to an object from a raw pointer.
int main(int argc, char *argv[])
Templated array class derived from the STL std::vector.
#define TEST_COMPARE_ARRAYS(a1, a2)
Assert that a1.size()==a2.size() and a[i]==b[i], i=0....
A MPI utilities class, providing methods for initializing, finalizing, and querying the global MPI se...
Basic command line parser for input from (argc,argv[])
ArrayRCP< T2 > arcp_const_cast(const ArrayRCP< T1 > &p1)
Const cast of underlying ArrayRCP type from const T* to T*.
Smart reference counting pointer class for automatic garbage collection.
#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 ...
RCP< basic_FancyOStream< CharT, Traits > > tab(const RCP< basic_FancyOStream< CharT, Traits > > &out, const int tabs=1, const std::basic_string< CharT, Traits > linePrefix="")
Create a tab for an RCP-wrapped basic_FancyOStream object to cause the indentation of all output auto...
bool test_ArrayRCP_iterators(const Teuchos::ArrayRCP< T > &ptr, Teuchos::FancyOStream &out)
Class that helps parse command line input arguments from (argc,argv[]) and set options.
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
This macro is designed to be a short version of TEUCHOS_TEST_FOR_EXCEPTION() that is easier to call...
Reference-counted smart pointer for managing arrays.