Teuchos Package Browser (Single Doxygen Collection) Version of the Day
ArrayRCP_test.cpp
Go to the documentation of this file.
00001 // @HEADER
00002 // ***********************************************************************
00003 //
00004 //                    Teuchos: Common Tools Package
00005 //                 Copyright (2004) Sandia Corporation
00006 //
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 //
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
00038 //
00039 // ***********************************************************************
00040 // @HEADER
00041 
00042 #include "Teuchos_ArrayRCP.hpp"
00043 #include "Teuchos_Array.hpp"
00044 #include "Teuchos_CommandLineProcessor.hpp"
00045 #include "Teuchos_GlobalMPISession.hpp"
00046 #include "Teuchos_VerboseObject.hpp"
00047 #include "Teuchos_StandardCatchMacros.hpp"
00048 #include "Teuchos_Version.hpp"
00049 #include "Teuchos_Assert.hpp"
00050 #include "Teuchos_LocalTestingHelpers.hpp"
00051 
00052 
00053 // Temporarily uncomment any or all of these macros to see compilation
00054 // failures for code that is rightfully not supposed to compile (which is a
00055 // wonderful thing)! The fact that this code does not compile show that the
00056 // design of the Teuchos::ArrayRCP class supports full support of
00057 // const projection in all of its forms when dealing with arrays of objects.
00058 //#define SHOW_COMPILE_FAILURE_1
00059 //#define SHOW_COMPILE_FAILURE_2
00060 //#define SHOW_COMPILE_FAILURE_3
00061 
00062 
00063 //
00064 // Iterator testing function
00065 //
00066 
00067 template<class T>
00068 bool test_ArrayRCP_iterators(
00069   const Teuchos::ArrayRCP<T> &ptr,
00070   Teuchos::FancyOStream &out
00071   )
00072 {
00073 
00074   using Teuchos::ArrayRCP;
00075   using Teuchos::null;
00076   using Teuchos::arcp;
00077 
00078   bool success = true;
00079 
00080   out
00081     << "\n***"
00082     << "\n*** Testing iterators and accessors for ptr = " << ptr
00083     << "\n***\n";
00084 
00085   Teuchos::OSTab tab(out);
00086 
00087   const int size = ptr.size();
00088 
00089   // Pointer ++
00090  
00091   {
00092     out << "\nChecking ++itr and < ...\n";
00093     ArrayRCP<T> itr = ptr;
00094     for( int i = 0; itr < ptr+size; ++i, ++itr )
00095       TEUCHOS_TEST_FOR_EXCEPT( !(*itr == ptr[i]) );
00096   }
00097  
00098   {
00099     out << "\nChecking itr++ and <= ...\n";
00100     ArrayRCP<T> itr = ptr;
00101     for( int i = 0; itr <= ptr+size-1; ++i, itr++ )
00102       TEUCHOS_TEST_FOR_EXCEPT( !(*itr == ptr[i]) );
00103   }
00104  
00105   {
00106     out << "\nChecking itr+=1 and != ...\n";
00107     ArrayRCP<T> itr = ptr;
00108     for( int i = 0; itr != ptr+size; ++i, itr+=1 )
00109       TEUCHOS_TEST_FOR_EXCEPT( !(*itr == ptr[i]) );
00110   }
00111  
00112   {
00113     out << "\nChecking itr=itr+1 and == ...\n";
00114     ArrayRCP<T> itr = ptr;
00115     for( int i = 0; !( itr == ptr+size ); ++i, itr=itr+1 )
00116       TEUCHOS_TEST_FOR_EXCEPT( !(*itr == ptr[i]) );
00117   }
00118 
00119   // Pointer --
00120  
00121   {
00122     out << "\nChecking --itr and >= ...\n";
00123     ArrayRCP<T> itr = ptr+size-1;
00124     for( int i = size-1; itr >= ptr; --i, --itr )
00125       TEUCHOS_TEST_FOR_EXCEPT( !(*itr == ptr[i]) );
00126   }
00127  
00128   {
00129     out << "\nChecking itr-- and > ...\n";
00130     ArrayRCP<T> itr = ptr+size-1;
00131     for( int i = size-1; itr+1 > ptr; i--, itr-- )
00132       TEUCHOS_TEST_FOR_EXCEPT( !(*itr == ptr[i]) );
00133   }
00134  
00135   {
00136     out << "\nChecking itr-=1 and != ...\n";
00137     ArrayRCP<T> itr = ptr+size-1;
00138     for( int i = size-1; itr+1 != ptr; i--, itr-=1 )
00139       TEUCHOS_TEST_FOR_EXCEPT( !(*itr == ptr[i]) );
00140   }
00141  
00142   {
00143     out << "\nChecking itr=itr-1 and == ...\n";
00144     ArrayRCP<T> itr = ptr+size-1;
00145     for( int i = size-1; !( itr+1 == ptr ); i--, itr=itr-1 )
00146       TEUCHOS_TEST_FOR_EXCEPT( !(*itr == ptr[i]) );
00147   }
00148 
00149   // Iterator - Iterator
00150  
00151   {
00152     out << "\nChecking ptr.end() - ptr.begin() == ptr.size() ...\n";
00153     TEUCHOS_ASSERT_EQUALITY( ptr.end() - ptr.begin(), ptr.size() );
00154   }
00155 
00156   // Iterator ++
00157  
00158   {
00159     out << "\nChecking iterator ++itr and < ...\n";
00160     typename ArrayRCP<T>::const_iterator itr = ptr.begin();
00161     for( int i = 0; itr < ptr.end(); ++i, ++itr )
00162       TEUCHOS_TEST_FOR_EXCEPT( !(*itr == ptr[i]) );
00163   }
00164  
00165   {
00166     out << "\nChecking iterator itr++ and <= ...\n";
00167     typename ArrayRCP<T>::const_iterator itr = ptr.begin();
00168     for( int i = 0; itr <= ptr.end()-1; ++i, itr++ )
00169       TEUCHOS_TEST_FOR_EXCEPT( !(*itr == ptr[i]) );
00170   }
00171  
00172   {
00173     out << "\nChecking iterator itr+=1 and != ...\n";
00174     typename ArrayRCP<T>::const_iterator itr = ptr.begin();
00175     for( int i = 0; itr != ptr.end(); ++i, itr+=1 )
00176       TEUCHOS_TEST_FOR_EXCEPT( !(*itr == ptr[i]) );
00177   }
00178  
00179   {
00180     out << "\nChecking iterator itr=itr+1 and == ...\n";
00181     typename ArrayRCP<T>::const_iterator itr = ptr.begin();
00182     for( int i = 0; !( itr == ptr.end() ); ++i, itr=itr+1 )
00183       TEUCHOS_TEST_FOR_EXCEPT( !(*itr == ptr[i]) );
00184   }
00185 
00186   // Iterator --
00187  
00188   {
00189     out << "\nChecking iterator --itr and >= ...\n";
00190     typename ArrayRCP<T>::const_iterator itr = ptr.begin()+size-1;
00191     for( int i = size-1; itr >= ptr.begin(); --i, --itr )
00192       TEUCHOS_TEST_FOR_EXCEPT( !(*itr == ptr[i]) );
00193   }
00194  
00195   {
00196     out << "\nChecking iterator itr-- and > ...\n";
00197     typename ArrayRCP<T>::const_iterator itr = ptr.begin()+size-1;
00198     for( int i = size-1; itr+1 > ptr.begin(); i--, itr-- )
00199       TEUCHOS_TEST_FOR_EXCEPT( !(*itr == ptr[i]) );
00200   }
00201  
00202   {
00203     out << "\nChecking iterator itr-=1 and != ...\n";
00204     typename ArrayRCP<T>::const_iterator itr = ptr.begin()+size-1;
00205     for( int i = size-1; itr+1 != ptr.begin(); i--, itr-=1 )
00206       TEUCHOS_TEST_FOR_EXCEPT( !(*itr == ptr[i]) );
00207   }
00208  
00209   {
00210     out << "\nChecking iterator itr=itr-1 and == ...\n";
00211     typename ArrayRCP<T>::const_iterator itr = ptr.begin()+size-1;
00212     for( int i = size-1; !( itr+1 == ptr.begin() ); i--, itr=itr-1 )
00213       TEUCHOS_TEST_FOR_EXCEPT( !(*itr == ptr[i]) );
00214   }
00215 
00216   return success;
00217 
00218 }
00219 
00220 
00221 //
00222 // Main testing function for a specific ArrayRCP
00223 //
00224 
00225 
00226 template<class T>
00227 bool test_ArrayRCP(
00228   const Teuchos::ArrayRCP<T> &ptr,
00229   Teuchos::FancyOStream &out
00230   )
00231 {
00232 
00233   using Teuchos::ArrayView;
00234   using Teuchos::ArrayRCP;
00235   using Teuchos::arcp;
00236   using Teuchos::arcp_const_cast;
00237   using Teuchos::as;
00238 
00239   bool success = true, result;
00240  
00241   out
00242     << "\n***"
00243     << "\n*** Testing ptr = " << ptr
00244     << "\n***\n";
00245 
00246   Teuchos::OSTab tab(out);
00247 
00248   const int n = ptr.size();
00249  
00250   {
00251     out << "\nInitializing data ...\n";
00252     for( int i = 0; i < n; ++i )
00253       ptr[i] = i;
00254   }
00255 
00256   TEUCHOS_TEST_FOR_EXCEPT( !(&*ptr == ptr.get()) );
00257   TEUCHOS_TEST_FOR_EXCEPT( !(&*ptr == ptr.getRawPtr()) );
00258 
00259   result = test_ArrayRCP_iterators(ptr,out);
00260   if (!result) success = false;
00261 
00262   //
00263   out << "\nTest const casting ...\n";
00264   //
00265 
00266   {
00267     const ArrayRCP<const T> cptr2 = ptr;
00268     const ArrayRCP<T> ptr3 = arcp_const_cast<T>(cptr2);
00269     TEST_COMPARE_ARRAYS( ptr3, ptr );
00270   }
00271 
00272   //
00273   out << "\nTest views ...\n";
00274   //
00275 
00276   {
00277     out << "\nTest full non-const subview ...\n";
00278     const ArrayView<T> av2 = ptr(0,n);
00279     TEST_COMPARE_ARRAYS( av2, ptr );
00280   }
00281 
00282   {
00283     out << "\nTest full shorthand non-const subview ...\n";
00284     const ArrayView<T> av2 = ptr();
00285     TEST_COMPARE_ARRAYS( av2, ptr );
00286   }
00287 
00288   {
00289     out << "\nTest full const subview ...\n";
00290     const ArrayView<const T> cav2 = ptr.getConst()(0,n);
00291     TEST_COMPARE_ARRAYS( cav2, ptr );
00292   }
00293 
00294   {
00295     out << "\nTest full non-const to const subview ...\n";
00296     const ArrayView<const T> cav2 = ptr(0,n);
00297     TEST_COMPARE_ARRAYS( cav2, ptr );
00298   }
00299 
00300   {
00301     out << "\nTest full short-hand const subview ...\n";
00302     const ArrayView<const T> cav2 = ptr.getConst()();
00303     TEST_COMPARE_ARRAYS( cav2, ptr );
00304   }
00305 
00306   {
00307     out << "\nTest implicit conversion from ArrayRCP<T> to ArrayView<T> ...\n";
00308     const ArrayView<T> av2 = ptr();
00309     TEST_COMPARE_ARRAYS( av2, ptr );
00310   }
00311 
00312   {
00313     out << "\nTest implicit conversion from ArrayRCP<const T> to ArrayView<const T> ...\n";
00314     const ArrayView<const T> av2 = ptr.getConst()();
00315     TEST_COMPARE_ARRAYS( av2, ptr );
00316   }
00317 
00318   {
00319     out << "\nTest almost implicit conversion from ArrayRCP<T> to ArrayView<const T> ...\n";
00320     const ArrayView<const T> av2 = ptr();
00321     TEST_COMPARE_ARRAYS( av2, ptr );
00322   }
00323 
00324   {
00325     out << "\nTest implicit conversion from ArrayRCP<T> to ArrayRCP<const T> ...\n";
00326     const ArrayRCP<const T> ptr2 = ptr;
00327     TEST_COMPARE_ARRAYS( ptr2, ptr );
00328   }
00329 
00330   {
00331     out << "\nTest clone of ArrayView<T> to ArrayRCP<T> ...\n";
00332     const ArrayRCP<T> ptr2 = Teuchos::arcpClone<T>(ptr());
00333     TEST_COMPARE_ARRAYS( ptr2, ptr );
00334   }
00335 
00336   {
00337     out << "\nTest clone of ArrayPtr<const T> to ArrayRCP<T> ...\n";
00338     const ArrayRCP<T> ptr2 = Teuchos::arcpClone<T>(ptr.getConst()());
00339     TEST_COMPARE_ARRAYS( ptr2, ptr );
00340   }
00341   {
00342     out << "\nTest extra data ...\n";
00343     ArrayRCP<T> ptr2 = arcp<T>(n);
00344     Teuchos::set_extra_data( as<int>(1), "int", Teuchos::inOutArg(ptr2) );
00345     TEST_EQUALITY_CONST( Teuchos::get_extra_data<int>(ptr2, "int"), 1);
00346   }
00347 
00348   return success;
00349 
00350 }
00351 
00352 
00353 //
00354 // Main driver program
00355 //
00356 
00357 
00358 int main( int argc, char* argv[] )
00359 {
00360 
00361   Teuchos::GlobalMPISession mpiSession(&argc, &argv);
00362 
00363   using Teuchos::CommandLineProcessor;
00364   using Teuchos::null;
00365   using Teuchos::RCP;
00366   using Teuchos::rcp;
00367   using Teuchos::ArrayRCP;
00368   using Teuchos::arcp;
00369   using Teuchos::arcp_reinterpret_cast;
00370   
00371   bool success = true, result;
00372  
00373   Teuchos::RCP<Teuchos::FancyOStream>
00374     out = Teuchos::VerboseObjectBase::getDefaultOStream();
00375  
00376   try {
00377 
00378     // Read options from the commandline
00379     int num_ints = 10;
00380     int num_doubles = 10;
00381     CommandLineProcessor clp(false); // Don't throw exceptions
00382     clp.setOption( "num-ints", &num_ints, "Number of ints to allocate space for" );
00383     clp.setOption( "num-doubles", &num_doubles, "Number of doubles to allocate space for" );
00384     CommandLineProcessor::EParseCommandLineReturn parse_return = clp.parse(argc,argv);
00385     if( parse_return != CommandLineProcessor::PARSE_SUCCESSFUL ) {
00386       *out << "\nEnd Result: TEST FAILED" << std::endl;
00387       return parse_return;
00388     }
00389 
00390     const int sizeOfDouble = sizeof(double);
00391     const int sizeOfInt = sizeof(int);
00392 
00393     const int total_bytes = num_doubles*sizeOfDouble + num_ints*sizeOfInt;
00394 
00395     *out << std::endl << Teuchos::Teuchos_Version() << std::endl;
00396  
00397     *out << "\nTesting basic ArrayRCP functionality ...\n";
00398 
00399     ArrayRCP<char>
00400       char_ptr1 = arcp<char>(total_bytes);
00401 
00402     *out << "\nchar_ptr1 = " << char_ptr1 << "\n";
00403 
00404     TEUCHOS_TEST_FOR_EXCEPT( !(char_ptr1.size() == total_bytes) );
00405     TEUCHOS_TEST_FOR_EXCEPT( !(char_ptr1.lowerOffset() == 0) );
00406     TEUCHOS_TEST_FOR_EXCEPT( !(char_ptr1.upperOffset() == total_bytes-1) );
00407     TEUCHOS_TEST_FOR_EXCEPT( !(char_ptr1.strong_count() == 1) );
00408     TEUCHOS_TEST_FOR_EXCEPT( !(char_ptr1.weak_count() == 0) );
00409     TEUCHOS_TEST_FOR_EXCEPT( !(char_ptr1.total_count() == 1) );
00410     result = test_ArrayRCP(char_ptr1,*out);
00411     if (!result) success = false;
00412 
00413     ArrayRCP<char>
00414       char_ptr2 = null;
00415 
00416     *out << "\nchar_ptr2 = " << char_ptr2 << "\n";
00417 
00418     TEUCHOS_TEST_FOR_EXCEPT( !(char_ptr2.size() == 0) );
00419     TEUCHOS_TEST_FOR_EXCEPT( !(char_ptr2.get() == NULL) );
00420     TEUCHOS_TEST_FOR_EXCEPT( !(char_ptr2.strong_count() == 0) );
00421     TEUCHOS_TEST_FOR_EXCEPT( !(char_ptr2.weak_count() == 0) );
00422     TEUCHOS_TEST_FOR_EXCEPT( !(char_ptr2.total_count() == 0) );
00423 
00424     ArrayRCP<char>
00425       char_ptr2b(char_ptr1); // excplicitly test copy constructor
00426 
00427     *out << "\nchar_ptr2b = " << char_ptr2b << "\n";
00428 
00429     TEUCHOS_TEST_FOR_EXCEPT( !(char_ptr2b.size() == total_bytes) );
00430     TEUCHOS_TEST_FOR_EXCEPT( !(char_ptr2b.lowerOffset() == 0) );
00431     TEUCHOS_TEST_FOR_EXCEPT( !(char_ptr2b.upperOffset() == total_bytes-1) );
00432     TEUCHOS_TEST_FOR_EXCEPT( !(char_ptr2b.strong_count() == 2) );
00433     TEUCHOS_TEST_FOR_EXCEPT( !(char_ptr2b.weak_count() == 0) );
00434     TEUCHOS_TEST_FOR_EXCEPT( !(char_ptr2b.total_count() == 2) );
00435     result = test_ArrayRCP(char_ptr2b,*out);
00436     if (!result) success = false;
00437 
00438     char_ptr2b = null;
00439 
00440     TEUCHOS_TEST_FOR_EXCEPT( !(char_ptr2b.size() == 0) );
00441     TEUCHOS_TEST_FOR_EXCEPT( !(char_ptr2.get() == NULL) );
00442     TEUCHOS_TEST_FOR_EXCEPT( !(char_ptr2b.strong_count() == 0) );
00443     TEUCHOS_TEST_FOR_EXCEPT( !(char_ptr1.strong_count() == 1) );
00444 
00445     ArrayRCP<char>
00446       char_ptr3 = char_ptr1.persistingView(total_bytes/2,total_bytes/2);
00447 
00448     TEUCHOS_TEST_FOR_EXCEPT( !(char_ptr1.strong_count() == 2) );
00449     TEUCHOS_TEST_FOR_EXCEPT( !(char_ptr3.strong_count() == 2) );
00450     TEUCHOS_TEST_FOR_EXCEPT( !(char_ptr3.lowerOffset() == 0) );
00451     TEUCHOS_TEST_FOR_EXCEPT( !(char_ptr3.upperOffset() == total_bytes/2-1) );
00452     result = test_ArrayRCP(char_ptr3,*out);
00453     if (!result) success = false;
00454 
00455     *out << "\nchar_ptr3 = " << char_ptr3 << "\n";
00456 
00457     *out << "\nBreak up char_ptr1 into views of double and int data\n";
00458 
00459     int offset = 0;
00460  
00461     ArrayRCP<double> double_ptr1 = arcp_reinterpret_cast<double>(
00462       char_ptr1.persistingView(offset,sizeOfDouble*num_doubles)
00463       );
00464 
00465     *out << "\ndouble_ptr1 = " << double_ptr1 << "\n";
00466 
00467     TEUCHOS_TEST_FOR_EXCEPT( !(char_ptr1.strong_count() == 3) );
00468     TEUCHOS_TEST_FOR_EXCEPT( !(double_ptr1.strong_count() == 3) );
00469     TEUCHOS_TEST_FOR_EXCEPT( !(double_ptr1.size() == num_doubles) );
00470 
00471     result = test_ArrayRCP(double_ptr1,*out);
00472     if (!result) success = false;
00473  
00474     offset += sizeOfDouble*num_doubles;
00475 
00476     ArrayRCP<int> int_ptr1 = arcp_reinterpret_cast<int>(
00477       char_ptr1.persistingView(offset,sizeOfInt*num_ints)
00478       );
00479 
00480     *out << "\nint_ptr1 = " << int_ptr1 << "\n";
00481 
00482     TEUCHOS_TEST_FOR_EXCEPT( !(char_ptr1.strong_count() == 4) );
00483     TEUCHOS_TEST_FOR_EXCEPT( !(int_ptr1.strong_count() == 4) );
00484     TEUCHOS_TEST_FOR_EXCEPT( !(int_ptr1.size() == num_ints) );
00485 
00486     result = test_ArrayRCP(int_ptr1,*out);
00487     if (!result) success = false;
00488 
00489     *out << "\nCreating a constant view of double_ptr1\n";
00490  
00491     ArrayRCP<const double>
00492       double_ptr2 = double_ptr1.getConst();
00493 
00494     result = test_ArrayRCP_iterators(double_ptr2,*out);
00495     if (!result) success = false;
00496 
00497 #ifdef SHOW_COMPILE_FAILURE_1
00498     // This will not compile since this function tries to use operator[] to
00499     // change data but it can't since it returns a reference to a const
00500     // double!
00501     for( int i = 0; i < double_ptr2.size(); ++i ) {
00502       double_ptr2[i] = 1.0; // Error, you can change the value!
00503     }
00504 #endif
00505 
00506     *out << "\nCreating an array of RCP objects!\n";
00507 
00508     ArrayRCP<RCP<double> >
00509       rcp_ptr1 = arcp<RCP<double> >(num_doubles);
00510 
00511     for( int i = 0; i < num_doubles; ++i )
00512       rcp_ptr1[i] = rcp(new double(i));
00513 
00514     result = test_ArrayRCP_iterators(rcp_ptr1,*out);
00515     if (!result) success = false;
00516 
00517     *out << "\nCreating a const view of rcp_ptr1\n";
00518 
00519     ArrayRCP<const RCP<double> >
00520       rcp_ptr2 = rcp_ptr1.getConst();
00521 
00522     result = test_ArrayRCP_iterators(rcp_ptr2,*out);
00523     if (!result) success = false;
00524 
00525     *out << "\nCreating an ARCP<double*> object doubleptr_ptr1 and dynamically allocation each element\n";
00526 
00527     ArrayRCP<double*>
00528       doubleptr_ptr1 = arcp<double*>(total_bytes);
00529 
00530     for( int i = 0; i < doubleptr_ptr1.size(); ++i )
00531       doubleptr_ptr1[i] = new double(i);
00532 
00533     result = test_ArrayRCP_iterators(doubleptr_ptr1,*out);
00534     if (!result) success = false;
00535 
00536     *out << "\nCreating an ARCP<double*const> view of a doubleptr_ptr1\n";
00537  
00538     ArrayRCP<double*const>
00539       doubleptr_ptr2 = doubleptr_ptr1.getConst();
00540 
00541     result = test_ArrayRCP_iterators(doubleptr_ptr2,*out);
00542     if (!result) success = false;
00543 
00544 #ifdef SHOW_COMPILE_FAILURE_2
00545     // This will not compile since this function tries to use operator[] to
00546     // change data but it can't since it returns a reference to a double*const
00547     // object!
00548     for( int i = 0; i < doubleptr_ptr2.size(); ++i ) {
00549       *doubleptr_ptr2[i] = 1.0; // Fine, you can change the value that is being pointed to for this entry!
00550       doubleptr_ptr2[i] = NULL; // Error, you can't change the pointer entry!
00551     }
00552 #endif
00553 
00554     *out << "\nCreating an ARCP<const double * const> view of a doubleptr_ptr1\n";
00555  
00556     ArrayRCP<const double*const>
00557       doubleptr_ptr3 = Teuchos::arcp_implicit_cast<const double*const>(doubleptr_ptr1);
00558 
00559     result = test_ArrayRCP_iterators(doubleptr_ptr3,*out);
00560     if (!result) success = false;
00561 
00562 #ifdef SHOW_COMPILE_FAILURE_3
00563     // This will not compile since this function tries to use operator[] to
00564     // change data but it can't since it returns a reference to a double*const
00565     // object!
00566     for( int i = 0; i < doubleptr_ptr3.size(); ++i ) {
00567       *doubleptr_ptr3[i] = 1.0; // Error, you can't change the value that is being pointed to!
00568       doubleptr_ptr3[i] = NULL; // Error, you can't change the pointer either!
00569     }
00570 #endif
00571 
00572     for( int i = 0; i < doubleptr_ptr1.size(); ++i )
00573       delete doubleptr_ptr1[i];
00574 
00575     *out << "\nWrapping RCP<std::vector<T> > objects as ArrayRCP objects ...\n";
00576 
00577     {
00578 
00579       ArrayRCP<char>
00580         vchar_ptr1 = arcp(rcp(new std::vector<char>(total_bytes)));
00581       
00582       *out << "\nvchar_ptr1 = " << vchar_ptr1 << "\n";
00583       
00584       result = test_ArrayRCP(vchar_ptr1,*out);
00585       if (!result) success = false;
00586       
00587       ArrayRCP<const char> vchar_ptr2 = vchar_ptr1;
00588  
00589       *out << "\nvchar_ptr2 = " << vchar_ptr2 << "\n";
00590       
00591       result = test_ArrayRCP_iterators(vchar_ptr2, *out);
00592       if (!result) success = false;
00593       
00594 #ifndef __sun
00595       // RAB: 2006/07/12: The sun compiler declares this call to
00596       // get_std_vector(...) to be ambiguous (which is nonsense based on
00597       // everything I know about C++)!
00598       TEUCHOS_TEST_FOR_EXCEPT( Teuchos::get_std_vector(vchar_ptr1)->size() != static_cast<size_t>(total_bytes) );
00599 #endif
00600       TEUCHOS_TEST_FOR_EXCEPT( vchar_ptr1.size() != static_cast<Teuchos_Ordinal>(total_bytes) );
00601       TEUCHOS_TEST_FOR_EXCEPT( vchar_ptr2.size() != static_cast<Teuchos_Ordinal>(total_bytes) );
00602       
00603     }
00604 
00605     *out << "\nWrapping RCP<ARray<T> > objects as ArrayRCP objects ...\n";
00606 
00607     {
00608 
00609       ArrayRCP<char>
00610         vchar_ptr1 = arcp(rcp(new Teuchos::Array<char>(total_bytes)));
00611       
00612       *out << "\nvchar_ptr1 = " << vchar_ptr1 << "\n";
00613       
00614       result = test_ArrayRCP(vchar_ptr1,*out);
00615       if (!result) success = false;
00616 
00617 /*      
00618       ArrayRCP<const char> vchar_ptr2 =
00619         arcp(
00620           Teuchos::rcp_implicit_cast<const std::vector<char> >(
00621             Teuchos::get_std_vector(vchar_ptr1)
00622             )
00623           );
00624 */
00625 
00626     }
00627  
00628     // ToDo: Fill in the rest of the tests!
00629  
00630     *out << "\nAll tests for ArrayRCP seem to check out!\n";
00631  
00632   }
00633   TEUCHOS_STANDARD_CATCH_STATEMENTS(true,std::cerr,success);
00634  
00635   if(success)
00636     *out << "\nEnd Result: TEST PASSED" << std::endl; 
00637  
00638   return ( success ? 0 : 1 );
00639  
00640 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines