|
Teuchos - Trilinos Tools Package
Version of the Day
|
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 #ifndef TEUCHOS_ARRAY_VIEW_HPP 00043 #define TEUCHOS_ARRAY_VIEW_HPP 00044 00045 00046 #include "Teuchos_ArrayViewDecl.hpp" 00047 #include "Teuchos_ArrayRCP.hpp" 00048 #include "Teuchos_as.hpp" 00049 00050 00051 namespace Teuchos { 00052 00053 00054 // Constructors/Destructors 00055 00056 00057 template<class T> inline 00058 ArrayView<T>::ArrayView( ENull ) 00059 : ptr_(0), size_(0) 00060 { 00061 setUpIterators(); 00062 } 00063 00064 template<class T> inline 00065 ArrayView<const T>::ArrayView( ENull ) 00066 : ptr_(0), size_(0) 00067 { 00068 setUpIterators(); 00069 } 00070 00071 00072 00073 template<class T> inline 00074 ArrayView<T>::ArrayView( T* p, size_type size_in, const ERCPNodeLookup rcpNodeLookup ) 00075 :ptr_(p), size_(size_in) 00076 { 00077 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 00078 TEUCHOS_TEST_FOR_EXCEPT( p != 0 && size_in <= 0 ); 00079 TEUCHOS_TEST_FOR_EXCEPT( p == 0 && size_in != 0 ); 00080 // This only does something if HAVE_TEUCHOS_ARRAY_BOUNDSCHECK is defined. 00081 setUpIterators(rcpNodeLookup); 00082 #else 00083 (void) rcpNodeLookup; // Silence "unused variable" compiler warning. 00084 #endif // HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 00085 } 00086 00087 template<class T> inline 00088 ArrayView<const T>::ArrayView(const T* p, size_type size_in, const ERCPNodeLookup rcpNodeLookup ) 00089 : ptr_(p), size_(size_in) 00090 { 00091 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 00092 TEUCHOS_TEST_FOR_EXCEPT( p != 0 && size_in <= 0 ); 00093 TEUCHOS_TEST_FOR_EXCEPT( p == 0 && size_in != 0 ); 00094 // This only does something if HAVE_TEUCHOS_ARRAY_BOUNDSCHECK is defined. 00095 setUpIterators(rcpNodeLookup); 00096 #else 00097 (void) rcpNodeLookup; // Silence "unused variable" compiler warning. 00098 #endif // HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 00099 } 00100 00101 00102 template<class T> inline 00103 ArrayView<T>::ArrayView(const ArrayView<T>& array) 00104 :ptr_(array.ptr_), size_(array.size_) 00105 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 00106 ,arcp_(array.arcp_) 00107 #endif 00108 {} 00109 00110 template<class T> inline 00111 ArrayView<const T>::ArrayView(const ArrayView<const T>& array) 00112 :ptr_(array.ptr_), size_(array.size_) 00113 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 00114 ,arcp_(array.arcp_) 00115 #endif 00116 {} 00117 00118 00119 template<class T> inline 00120 ArrayView<T>::ArrayView( 00121 std::vector<typename ConstTypeTraits<T>::NonConstType>& vec 00122 ) 00123 : ptr_( vec.empty() ? 0 : &vec[0] ), size_(vec.size()) 00124 { 00125 setUpIterators(); 00126 } 00127 00128 template<class T> inline 00129 ArrayView<const T>::ArrayView( 00130 std::vector<typename ConstTypeTraits<T>::NonConstType>& vec 00131 ) 00132 : ptr_( vec.empty() ? 0 : &vec[0] ), size_(vec.size()) 00133 { 00134 setUpIterators(); 00135 } 00136 00137 00138 template<class T> inline 00139 ArrayView<T>::ArrayView( 00140 const std::vector<typename ConstTypeTraits<T>::NonConstType>& vec 00141 ) 00142 : ptr_( vec.empty() ? 0 : &vec[0] ), size_(vec.size()) 00143 { 00144 setUpIterators(); 00145 } 00146 00147 template<class T> inline 00148 ArrayView<const T>::ArrayView( 00149 const std::vector<typename ConstTypeTraits<T>::NonConstType>& vec 00150 ) 00151 : ptr_( vec.empty() ? 0 : &vec[0] ), size_(vec.size()) 00152 { 00153 setUpIterators(); 00154 } 00155 00156 00157 template<class T> inline 00158 ArrayView<T>& ArrayView<T>::operator=(const ArrayView<T>& array) 00159 { 00160 ptr_ = array.ptr_; 00161 size_ = array.size_; 00162 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 00163 arcp_ = array.arcp_; 00164 #endif 00165 return *this; 00166 } 00167 00168 template<class T> inline 00169 ArrayView<const T>& ArrayView<const T>::operator= (const ArrayView<const T>& array) 00170 { 00171 ptr_ = array.ptr_; 00172 size_ = array.size_; 00173 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 00174 arcp_ = array.arcp_; 00175 #endif 00176 return *this; 00177 } 00178 00179 00180 template<class T> inline 00181 ArrayView<T>::~ArrayView() 00182 {} 00183 00184 template<class T> inline 00185 ArrayView<const T>::~ArrayView() 00186 {} 00187 00188 00189 // General query functions 00190 00191 00192 template<class T> 00193 inline 00194 bool ArrayView<T>::is_null() const 00195 { 00196 return ptr_ == 0; 00197 } 00198 00199 template<class T> 00200 inline 00201 bool ArrayView<const T>::is_null() const 00202 { 00203 return ptr_ == 0; 00204 } 00205 00206 00207 template<class T> inline 00208 typename ArrayView<T>::size_type ArrayView<T>::size() const 00209 { 00210 debug_assert_valid_ptr(); 00211 return size_; 00212 } 00213 00214 template<class T> inline 00215 typename ArrayView<const T>::size_type ArrayView<const T>::size() const 00216 { 00217 debug_assert_valid_ptr(); 00218 return size_; 00219 } 00220 00221 00222 template<typename T> 00223 std::string ArrayView<T>::toString() const 00224 { 00225 using Teuchos::as; 00226 std::ostringstream ss; 00227 00228 debug_assert_valid_ptr(); 00229 00230 ss << "{"; 00231 for (size_type i = 0; i < size (); ++i) { 00232 // NOTE: This depends on std::ostream::operator<<(const T&). 00233 ss << operator[] (i); 00234 if (i + 1 < size ()) { 00235 ss << ", "; 00236 } 00237 } 00238 ss << "}"; 00239 return ss.str (); 00240 } 00241 00242 template<typename T> 00243 std::string ArrayView<const T>::toString() const 00244 { 00245 using Teuchos::as; 00246 std::ostringstream ss; 00247 00248 debug_assert_valid_ptr(); 00249 00250 ss << "{"; 00251 for (size_type i = 0; i < size (); ++i) { 00252 // NOTE: This depends on std::ostream::operator<<(const T&). 00253 ss << operator[] (i); 00254 if (i + 1 < size ()) { 00255 ss << ", "; 00256 } 00257 } 00258 ss << "}"; 00259 return ss.str (); 00260 } 00261 00262 00263 // Specialization for float. We use sufficient precision that no 00264 // digits are lost after writing to string and reading back in again. 00265 template<> 00266 TEUCHOSCORE_LIB_DLL_EXPORT std::string 00267 ArrayView<float>::toString() const; 00268 00269 // Specialization for (const) float. We use sufficient precision that no 00270 // digits are lost after writing to string and reading back in again. 00271 template<> 00272 TEUCHOSCORE_LIB_DLL_EXPORT std::string 00273 ArrayView<const float>::toString() const; 00274 00275 // Specialization for double. We use sufficient precision that no 00276 // digits are lost after writing to string and reading back in again. 00277 template<> 00278 TEUCHOSCORE_LIB_DLL_EXPORT std::string 00279 ArrayView<double>::toString() const; 00280 00281 // Specialization for (const) double. We use sufficient precision that no 00282 // digits are lost after writing to string and reading back in again. 00283 template<> 00284 TEUCHOSCORE_LIB_DLL_EXPORT std::string 00285 ArrayView<const double>::toString() const; 00286 00287 00288 // Element Access Functions 00289 00290 00291 template<class T> inline 00292 T* ArrayView<T>::getRawPtr() const 00293 { 00294 debug_assert_valid_ptr(); 00295 return ptr_; 00296 } 00297 00298 template<class T> inline 00299 const T* ArrayView<const T>::getRawPtr() const 00300 { 00301 debug_assert_valid_ptr(); 00302 return ptr_; 00303 } 00304 00305 00306 template<class T> inline 00307 T& ArrayView<T>::operator[](size_type i) const 00308 { 00309 debug_assert_valid_ptr(); 00310 debug_assert_in_range(i,1); 00311 return ptr_[i]; 00312 } 00313 00314 template<class T> inline 00315 const T& ArrayView<const T>::operator[](size_type i) const 00316 { 00317 debug_assert_valid_ptr(); 00318 debug_assert_in_range(i,1); 00319 return ptr_[i]; 00320 } 00321 00322 00323 template<class T> inline 00324 T& ArrayView<T>::front() const 00325 { 00326 debug_assert_not_null(); 00327 debug_assert_valid_ptr(); 00328 return *ptr_; 00329 } 00330 00331 template<class T> inline 00332 const T& ArrayView<const T>::front() const 00333 { 00334 debug_assert_not_null(); 00335 debug_assert_valid_ptr(); 00336 return *ptr_; 00337 } 00338 00339 template<class T> inline 00340 T& ArrayView<T>::back() const 00341 { 00342 debug_assert_not_null(); 00343 debug_assert_valid_ptr(); 00344 return *(ptr_+size_-1); 00345 } 00346 00347 template<class T> inline 00348 const T& ArrayView<const T>::back() const 00349 { 00350 debug_assert_not_null(); 00351 debug_assert_valid_ptr(); 00352 return *(ptr_+size_-1); 00353 } 00354 00355 00356 // Views 00357 00358 00359 template<class T> inline 00360 ArrayView<T> ArrayView<T>::view(size_type offset, size_type size_in) const 00361 { 00362 if (size_in == 0) { return null; } 00363 debug_assert_valid_ptr(); 00364 debug_assert_in_range(offset, size_in); 00365 return ArrayView<T>( 00366 ptr_+offset, size_in 00367 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 00368 ,arcp_.persistingView(offset, size_in) 00369 #endif 00370 ); 00371 // WARNING: The above code had better be correct since we are using raw 00372 // pointer arithmetic! 00373 } 00374 00375 template<class T> inline 00376 ArrayView<const T> ArrayView<const T>::view(size_type offset, size_type size_in) const 00377 { 00378 if (size_in == 0) { return null; } 00379 debug_assert_valid_ptr(); 00380 debug_assert_in_range(offset, size_in); 00381 return ArrayView<const T>( 00382 ptr_+offset, size_in 00383 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 00384 ,arcp_.persistingView(offset, size_in) 00385 #endif 00386 ); 00387 // WARNING: The above code had better be correct since we are using raw 00388 // pointer arithmetic! 00389 } 00390 00391 00392 template<class T> inline 00393 ArrayView<T> ArrayView<T>::operator()(size_type offset, size_type size_in) const 00394 { 00395 return view(offset, size_in); 00396 } 00397 00398 template<class T> inline 00399 ArrayView<const T> ArrayView<const T>::operator()(size_type offset, size_type size_in) const 00400 { 00401 return view(offset, size_in); 00402 } 00403 00404 00405 template<class T> inline 00406 const ArrayView<T>& ArrayView<T>::operator()() const 00407 { 00408 debug_assert_valid_ptr(); 00409 return *this; 00410 } 00411 00412 template<class T> inline 00413 const ArrayView<const T>& ArrayView<const T>::operator()() const 00414 { 00415 debug_assert_valid_ptr(); 00416 return *this; 00417 } 00418 00419 00420 template<class T> inline 00421 ArrayView<const T> ArrayView<T>::getConst() const 00422 { 00423 debug_assert_valid_ptr(); 00424 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 00425 return arcp_.getConst()(); 00426 #endif 00427 return ArrayView<const T>(ptr_, size_); 00428 } 00429 00430 template<class T> inline 00431 ArrayView<const T> ArrayView<const T>::getConst() const { 00432 return *this; 00433 } 00434 00435 00436 template<class T> inline 00437 ArrayView<T>::operator ArrayView<const T>() const 00438 { 00439 return getConst(); 00440 } 00441 00442 00443 // Assignment 00444 00445 00446 template<class T> 00447 void ArrayView<T>::assign(const ArrayView<const T>& array) const 00448 { 00449 debug_assert_valid_ptr(); 00450 debug_assert_not_null(); 00451 if (this->getRawPtr()==array.getRawPtr() && this->size()==array.size()) 00452 return; // Assignment to self 00453 debug_assert_in_range(0,array.size()); 00454 std::copy( array.begin(), array.end(), this->begin() ); 00455 // Note: Above, in debug mode, the iterators are range checked! In 00456 // optimized mode, these are raw pointers which should run very fast! 00457 } 00458 00459 00460 // Standard Container-Like Functions 00461 00462 00463 template<class T> 00464 typename ArrayView<T>::iterator ArrayView<T>::begin() const 00465 { 00466 debug_assert_valid_ptr(); 00467 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 00468 return arcp_.create_weak(); 00469 #else 00470 return ptr_; 00471 #endif 00472 } 00473 00474 template<class T> 00475 typename ArrayView<const T>::iterator ArrayView<const T>::begin() const 00476 { 00477 debug_assert_valid_ptr(); 00478 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 00479 return arcp_.create_weak(); 00480 #else 00481 return ptr_; 00482 #endif 00483 } 00484 00485 00486 template<class T> 00487 typename ArrayView<T>::iterator ArrayView<T>::end() const 00488 { 00489 debug_assert_valid_ptr(); 00490 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 00491 return arcp_.create_weak() + size_; 00492 #else 00493 return ptr_ + size_; 00494 #endif 00495 } 00496 00497 template<class T> 00498 typename ArrayView<const T>::iterator ArrayView<const T>::end() const 00499 { 00500 debug_assert_valid_ptr(); 00501 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 00502 return arcp_.create_weak() + size_; 00503 #else 00504 return ptr_ + size_; 00505 #endif 00506 } 00507 00508 00509 // Assertion Functions. 00510 00511 00512 template<class T> 00513 const ArrayView<T>& ArrayView<T>::assert_not_null() const 00514 { 00515 if(!ptr_) 00516 throw_null_ptr_error(typeName(*this)); 00517 return *this; 00518 } 00519 00520 template<class T> 00521 const ArrayView<const T>& ArrayView<const T>::assert_not_null() const 00522 { 00523 if(!ptr_) 00524 throw_null_ptr_error(typeName(*this)); 00525 return *this; 00526 } 00527 00528 00529 template<class T> 00530 const ArrayView<T>& 00531 ArrayView<T>::assert_in_range(size_type offset, size_type size_in) const 00532 { 00533 assert_not_null(); 00534 TEUCHOS_TEST_FOR_EXCEPTION( size_in == as<size_type>(0), RangeError, 00535 "Error, size=0 is not allowed!" ); 00536 TEUCHOS_TEST_FOR_EXCEPTION( 00537 !( 00538 ( 0 <= offset && offset+size_in <= this->size() ) 00539 && 00540 size_in >= 0 00541 ), 00542 RangeError, 00543 typeName(*this)<<"::assert_in_range():" 00544 " Error, [offset,offset+size) = ["<<offset<<","<<(offset+size_in)<<")" 00545 " does not lie in the range [0,"<<this->size()<<")!" 00546 ); 00547 return*this; 00548 } 00549 00550 template<class T> 00551 const ArrayView<const T>& 00552 ArrayView<const T>::assert_in_range(size_type offset, size_type size_in) const 00553 { 00554 assert_not_null(); 00555 TEUCHOS_TEST_FOR_EXCEPTION( size_in == as<size_type>(0), RangeError, 00556 "Error, size=0 is not allowed!" ); 00557 TEUCHOS_TEST_FOR_EXCEPTION( 00558 !( 00559 ( 0 <= offset && offset+size_in <= this->size() ) 00560 && 00561 size_in >= 0 00562 ), 00563 RangeError, 00564 typeName(*this)<<"::assert_in_range():" 00565 " Error, [offset,offset+size) = ["<<offset<<","<<(offset+size_in)<<")" 00566 " does not lie in the range [0,"<<this->size()<<")!" 00567 ); 00568 return*this; 00569 } 00570 00571 00572 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 00573 00574 template<class T> 00575 ArrayView<T>::ArrayView( const ArrayRCP<T> &arcp ) 00576 : ptr_(arcp.getRawPtr()), size_(arcp.size()), arcp_(arcp) 00577 {} 00578 00579 template<class T> 00580 ArrayView<const T>::ArrayView( const ArrayRCP<const T> &arcp ) 00581 : ptr_(arcp.getRawPtr()), size_(arcp.size()), arcp_(arcp) 00582 {} 00583 00584 00585 template<class T> 00586 ArrayView<T>::ArrayView(T* p, size_type size_in, const ArrayRCP<T> &arcp) 00587 : ptr_(p), size_(size_in), arcp_(arcp) 00588 {} 00589 00590 template<class T> 00591 ArrayView<const T>::ArrayView(const T* p, size_type size_in, const ArrayRCP<const T> &arcp) 00592 : ptr_(p), size_(size_in), arcp_(arcp) 00593 {} 00594 00595 00596 #endif // HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 00597 00598 00599 // private 00600 00601 00602 template<class T> 00603 void ArrayView<T>::setUpIterators(const ERCPNodeLookup rcpNodeLookup) 00604 { 00605 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 00606 if (ptr_ && arcp_.is_null()) { 00607 arcp_ = ArrayRCP<T>(ptr_, 0, size_, false, rcpNodeLookup); 00608 } 00609 #else 00610 (void) rcpNodeLookup; // Silence "unused variable" compiler warning. 00611 #endif // HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 00612 } 00613 00614 template<class T> 00615 void ArrayView<const T>::setUpIterators(const ERCPNodeLookup rcpNodeLookup) 00616 { 00617 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 00618 if (ptr_ && arcp_.is_null()) { 00619 arcp_ = ArrayRCP<const T>(ptr_, 0, size_, false, rcpNodeLookup); 00620 } 00621 #else 00622 (void) rcpNodeLookup; // Silence "unused variable" compiler warning. 00623 #endif // HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 00624 } 00625 00626 00627 } // namespace Teuchos 00628 00629 00630 // 00631 // Nonmember helper functions 00632 // 00633 00634 00635 template<class T> inline 00636 Teuchos::ArrayView<T> 00637 Teuchos::arrayView( T* p, typename ArrayView<T>::size_type size ) 00638 { 00639 if (size == 0) 00640 return null; 00641 return ArrayView<T>(p, size); 00642 } 00643 00644 00645 template<class T> inline 00646 Teuchos::ArrayView<T> Teuchos::arrayViewFromVector( std::vector<T>& vec ) 00647 { 00648 if (vec.size() == 0) 00649 return null; 00650 return ArrayView<T>(vec); 00651 } 00652 00653 00654 template<class T> inline 00655 Teuchos::ArrayView<const T> Teuchos::arrayViewFromVector( const std::vector<T>& vec ) 00656 { 00657 if (vec.size() == 0) 00658 return null; 00659 return ArrayView<const T>(vec); 00660 } 00661 00662 00663 #ifndef __sun 00664 00665 template<class T> inline 00666 std::vector<T> Teuchos::createVector( const ArrayView<T> &av ) 00667 { 00668 std::vector<T> v(av.begin(), av.end()); 00669 return v; 00670 } 00671 00672 #endif // __sun 00673 00674 00675 template<class T> inline 00676 std::vector<T> Teuchos::createVector( const ArrayView<const T> &av ) 00677 { 00678 std::vector<T> v(av.begin(), av.end()); 00679 return v; 00680 } 00681 00682 00683 template<class T> inline 00684 bool Teuchos::is_null( const ArrayView<T> &av ) 00685 { 00686 return av.is_null(); 00687 } 00688 00689 00690 template<class T> inline 00691 bool Teuchos::nonnull( const ArrayView<T> &av ) 00692 { 00693 return !av.is_null(); 00694 } 00695 00696 00697 template<class T> 00698 std::ostream& Teuchos::operator<<( std::ostream& out, const ArrayView<T>& p ) 00699 { 00700 return out << p.toString(); 00701 } 00702 00703 00704 template<class T2, class T1> 00705 REFCOUNTPTR_INLINE 00706 Teuchos::ArrayView<T2> 00707 Teuchos::av_const_cast(const ArrayView<T1>& p1) 00708 { 00709 T2 *ptr2 = const_cast<T2*>(p1.getRawPtr()); 00710 return ArrayView<T2>(ptr2, p1.size()); 00711 // Note: Above is just fine even if p1.get()==NULL! 00712 } 00713 00714 00715 template<class T2, class T1> 00716 REFCOUNTPTR_INLINE 00717 Teuchos::ArrayView<T2> 00718 Teuchos::av_reinterpret_cast(const ArrayView<T1>& p1) 00719 { 00720 typedef typename ArrayView<T1>::size_type size_type; 00721 const int sizeOfT1 = sizeof(T1); 00722 const int sizeOfT2 = sizeof(T2); 00723 size_type size2 = (p1.size()*sizeOfT1) / sizeOfT2; 00724 T2 *ptr2 = reinterpret_cast<T2*>(p1.getRawPtr()); 00725 return ArrayView<T2>( 00726 ptr2, size2 00727 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 00728 ,arcp_reinterpret_cast<T2>(p1.access_private_arcp()) 00729 #endif 00730 ); 00731 // Note: Above is just fine even if p1.get()==NULL! 00732 } 00733 00734 00735 #endif // TEUCHOS_ARRAY_VIEW_HPP
1.7.6.1