42 #ifndef TEUCHOS_ARRAY_VIEW_HPP 43 #define TEUCHOS_ARRAY_VIEW_HPP 46 #include "Teuchos_ArrayViewDecl.hpp" 47 #include "Teuchos_ArrayRCP.hpp" 57 template<
class T>
inline 64 template<
class T>
inline 73 template<
class T>
inline 75 :ptr_(p), size_(size_in)
77 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 81 setUpIterators(rcpNodeLookup);
84 #endif // HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 87 template<
class T>
inline 89 : ptr_(p), size_(size_in)
91 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 95 setUpIterators(rcpNodeLookup);
98 #endif // HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 102 template<
class T>
inline 104 :ptr_(array.ptr_), size_(array.size_)
105 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
110 template<
class T>
inline 112 :ptr_(array.ptr_), size_(array.size_)
113 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
119 template<
class T>
inline 123 : ptr_( vec.empty() ? 0 : &vec[0] ), size_(vec.
size())
128 template<
class T>
inline 132 : ptr_( vec.empty() ? 0 : &vec[0] ), size_(vec.
size())
138 template<
class T>
inline 142 : ptr_( vec.empty() ? 0 : &vec[0] ), size_(vec.
size())
147 template<
class T>
inline 151 : ptr_( vec.empty() ? 0 : &vec[0] ), size_(vec.
size())
157 template<
class T>
inline 162 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 168 template<
class T>
inline 173 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 180 template<
class T>
inline 184 template<
class T>
inline 207 template<
class T>
inline 210 debug_assert_valid_ptr();
214 template<
class T>
inline 217 debug_assert_valid_ptr();
226 std::ostringstream ss;
228 debug_assert_valid_ptr();
233 ss << operator[] (i);
234 if (i + 1 <
size ()) {
246 std::ostringstream ss;
248 debug_assert_valid_ptr();
251 for (size_type i = 0; i <
size (); ++i) {
253 ss << operator[] (i);
254 if (i + 1 <
size ()) {
266 TEUCHOSCORE_LIB_DLL_EXPORT std::string
267 ArrayView<float>::toString()
const;
272 TEUCHOSCORE_LIB_DLL_EXPORT std::string
273 ArrayView<const float>::toString()
const;
278 TEUCHOSCORE_LIB_DLL_EXPORT std::string
279 ArrayView<double>::toString()
const;
284 TEUCHOSCORE_LIB_DLL_EXPORT std::string
285 ArrayView<const double>::toString()
const;
291 template<
class T>
inline 294 debug_assert_valid_ptr();
298 template<
class T>
inline 301 debug_assert_valid_ptr();
306 template<
class T>
inline 309 debug_assert_valid_ptr();
310 debug_assert_in_range(i,1);
314 template<
class T>
inline 317 debug_assert_valid_ptr();
318 debug_assert_in_range(i,1);
323 template<
class T>
inline 326 debug_assert_not_null();
327 debug_assert_valid_ptr();
331 template<
class T>
inline 334 debug_assert_not_null();
335 debug_assert_valid_ptr();
339 template<
class T>
inline 342 debug_assert_not_null();
343 debug_assert_valid_ptr();
344 return *(ptr_+size_-1);
347 template<
class T>
inline 350 debug_assert_not_null();
351 debug_assert_valid_ptr();
352 return *(ptr_+size_-1);
359 template<
class T>
inline 362 if (size_in == 0) {
return null; }
363 debug_assert_valid_ptr();
364 debug_assert_in_range(offset, size_in);
367 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 368 ,arcp_.persistingView(offset, size_in)
375 template<
class T>
inline 378 if (size_in == 0) {
return null; }
379 debug_assert_valid_ptr();
380 debug_assert_in_range(offset, size_in);
381 return ArrayView<const T>(
383 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 384 ,arcp_.persistingView(offset, size_in)
392 template<
class T>
inline 395 return view(offset, size_in);
398 template<
class T>
inline 401 return view(offset, size_in);
405 template<
class T>
inline 408 debug_assert_valid_ptr();
412 template<
class T>
inline 415 debug_assert_valid_ptr();
420 template<
class T>
inline 423 debug_assert_valid_ptr();
424 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 431 template<
class T>
inline 437 template<
class T>
inline 450 debug_assert_valid_ptr();
451 debug_assert_not_null();
452 if (this->getRawPtr()==array.getRawPtr() && this->
size()==array.size())
454 debug_assert_in_range(0,array.size());
455 std::copy( array.begin(), array.end(), this->begin() );
467 debug_assert_valid_ptr();
468 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 469 return arcp_.create_weak();
478 debug_assert_valid_ptr();
479 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 480 return arcp_.create_weak();
490 debug_assert_valid_ptr();
491 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 492 return arcp_.create_weak() + size_;
501 debug_assert_valid_ptr();
502 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 503 return arcp_.create_weak() + size_;
536 "Error, size=0 is not allowed!" );
539 ( 0 <= offset && offset+size_in <= this->
size() )
544 typeName(*
this)<<
"::assert_in_range():" 545 " Error, [offset,offset+size) = ["<<offset<<
","<<(offset+size_in)<<
")" 546 " does not lie in the range [0,"<<this->
size()<<
")!" 557 "Error, size=0 is not allowed!" );
560 ( 0 <= offset && offset+size_in <= this->
size() )
565 typeName(*
this)<<
"::assert_in_range():" 566 " Error, [offset,offset+size) = ["<<offset<<
","<<(offset+size_in)<<
")" 567 " does not lie in the range [0,"<<this->
size()<<
")!" 573 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 576 ArrayView<T>::ArrayView(
const ArrayRCP<T> &
arcp )
581 ArrayView<const T>::ArrayView(
const ArrayRCP<const T> &
arcp )
587 ArrayView<T>::ArrayView(T* p, size_type size_in,
const ArrayRCP<T> &
arcp)
588 : ptr_(p), size_(size_in), arcp_(
arcp)
592 ArrayView<const T>::ArrayView(
const T* p, size_type size_in,
const ArrayRCP<const T> &
arcp)
593 : ptr_(p), size_(size_in), arcp_(
arcp)
597 #endif // HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 604 void ArrayView<T>::setUpIterators(
const ERCPNodeLookup rcpNodeLookup)
606 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 607 if (ptr_ && arcp_.is_null()) {
608 arcp_ = ArrayRCP<T>(ptr_, 0, size_,
false, rcpNodeLookup);
611 (void) rcpNodeLookup;
612 #endif // HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 616 void ArrayView<const T>::setUpIterators(
const ERCPNodeLookup rcpNodeLookup)
618 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 619 if (ptr_ && arcp_.is_null()) {
620 arcp_ = ArrayRCP<const T>(ptr_, 0, size_,
false, rcpNodeLookup);
623 (void) rcpNodeLookup;
624 #endif // HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 636 template<
class T>
inline 638 Teuchos::arrayView( T* p,
typename ArrayView<T>::size_type
size )
642 return ArrayView<T>(p,
size);
646 template<
class T>
inline 651 return ArrayView<T>(vec);
655 template<
class T>
inline 660 return ArrayView<const T>(vec);
666 template<
class T>
inline 667 std::vector<T> Teuchos::createVector(
const ArrayView<T> &av )
669 std::vector<T> v(av.begin(), av.end());
676 template<
class T>
inline 677 std::vector<T> Teuchos::createVector(
const ArrayView<const T> &av )
679 std::vector<T> v(av.begin(), av.end());
684 template<
class T>
inline 691 template<
class T>
inline 694 return !av.is_null();
699 std::ostream& Teuchos::operator<<( std::ostream& out, const ArrayView<T>& p )
701 return out << p.toString();
705 template<
class T2,
class T1>
708 Teuchos::av_const_cast(
const ArrayView<T1>& p1)
710 T2 *ptr2 =
const_cast<T2*
>(p1.getRawPtr());
711 return ArrayView<T2>(ptr2, p1.size());
716 template<
class T2,
class T1>
719 Teuchos::av_reinterpret_cast(
const ArrayView<T1>& p1)
721 typedef typename ArrayView<T1>::size_type size_type;
722 const int sizeOfT1 =
sizeof(T1);
723 const int sizeOfT2 =
sizeof(T2);
724 size_type size2 = (p1.size()*sizeOfT1) / sizeOfT2;
725 T2 *ptr2 =
reinterpret_cast<T2*
>(p1.getRawPtr());
726 return ArrayView<T2>(
728 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 736 #endif // TEUCHOS_ARRAY_VIEW_HPP bool is_null(const boost::shared_ptr< T > &p)
Returns true if p.get()==NULL.
pointer iterator
Type of a nonconst iterator.
bool nonnull(const std::shared_ptr< T > &p)
Returns true if p.get()!=NULL.
bool is_null(const std::shared_ptr< T > &p)
Returns true if p.get()==NULL.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
UnConst< T >::Result NonConstType
Ordinal size_type
Type representing the number of elements in an ArrayRCP or view thereof.
ArrayRCP< T > arcp(const RCP< Array< T > > &v)
Wrap an RCP<Array<T> > object as an ArrayRCP<T> object.
ENull
Used to initialize a RCP object to NULL using an implicit conversion!
ArrayRCP< T2 > arcp_reinterpret_cast(const ArrayRCP< T1 > &p1)
Reinterpret cast of underlying ArrayRCP type from T1* to T2*.
int size(const Comm< Ordinal > &comm)
Get the number of processes in the communicator.
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos, as well as a number of utility routines.
ERCPNodeLookup
Used to determine if RCPNode lookup is performed or not.
ArrayView(ENull null_arg=null)
Constructor that initializes to NULL (implicitly or explicitly).
TypeTo as(const TypeFrom &t)
Convert from one value type to another.
TEUCHOSCORE_LIB_DLL_EXPORT void throw_null_ptr_error(const std::string &type_name)
Throw that a pointer passed into an RCP object is null.
Partial specialization of ArrayView for const T.
Range error exception class.
const T & getConst(T &t)
Return a constant reference to an object given a non-const reference.
Definition of Teuchos::as, for conversions between types.
#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...
std::string typeName(const T &t)
Template function for returning the concrete type name of a passed-in object.