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_(size_in == 0 ? nullptr : p), size_(size_in)
77 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 91 setUpIterators(rcpNodeLookup);
94 #endif // HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 97 template<
class T>
inline 99 : ptr_(size_in == 0 ? nullptr : p), size_(size_in)
101 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 115 setUpIterators(rcpNodeLookup);
117 (void) rcpNodeLookup;
118 #endif // HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 122 template<
class T>
inline 124 :ptr_(array.ptr_), size_(array.size_)
125 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
130 template<
class T>
inline 132 :ptr_(array.ptr_), size_(array.size_)
133 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
139 template<
class T>
inline 143 : ptr_( vec.empty() ? 0 : vec.data() ), size_(vec.
size())
148 template<
class T>
inline 152 : ptr_( vec.empty() ? 0 : vec.data() ), size_(vec.
size())
158 template<
class T>
inline 162 : ptr_( vec.empty() ? 0 : vec.data() ), size_(vec.
size())
167 template<
class T>
inline 171 : ptr_( vec.empty() ? 0 : vec.data() ), size_(vec.
size())
177 template<
class T>
inline 182 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 188 template<
class T>
inline 193 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 200 template<
class T>
inline 204 template<
class T>
inline 227 template<
class T>
inline 230 debug_assert_valid_ptr();
234 template<
class T>
inline 237 debug_assert_valid_ptr();
246 std::ostringstream ss;
248 debug_assert_valid_ptr();
253 ss << operator[] (i);
254 if (i + 1 <
size ()) {
266 std::ostringstream ss;
268 debug_assert_valid_ptr();
271 for (size_type i = 0; i <
size (); ++i) {
273 ss << operator[] (i);
274 if (i + 1 <
size ()) {
286 TEUCHOSCORE_LIB_DLL_EXPORT std::string
287 ArrayView<float>::toString()
const;
292 TEUCHOSCORE_LIB_DLL_EXPORT std::string
293 ArrayView<const float>::toString()
const;
298 TEUCHOSCORE_LIB_DLL_EXPORT std::string
299 ArrayView<double>::toString()
const;
304 TEUCHOSCORE_LIB_DLL_EXPORT std::string
305 ArrayView<const double>::toString()
const;
311 template<
class T>
inline 314 debug_assert_valid_ptr();
318 template<
class T>
inline 321 debug_assert_valid_ptr();
325 template<
class T>
inline 328 debug_assert_valid_ptr();
332 template<
class T>
inline 333 const T* ArrayView<const T>::data()
const 335 debug_assert_valid_ptr();
339 template<
class T>
inline 342 debug_assert_valid_ptr();
343 debug_assert_in_range(i,1);
347 template<
class T>
inline 350 debug_assert_valid_ptr();
351 debug_assert_in_range(i,1);
356 template<
class T>
inline 359 debug_assert_not_null();
360 debug_assert_valid_ptr();
364 template<
class T>
inline 367 debug_assert_not_null();
368 debug_assert_valid_ptr();
372 template<
class T>
inline 375 debug_assert_not_null();
376 debug_assert_valid_ptr();
377 return *(ptr_+size_-1);
380 template<
class T>
inline 383 debug_assert_not_null();
384 debug_assert_valid_ptr();
385 return *(ptr_+size_-1);
392 template<
class T>
inline 395 if (size_in == 0) {
return null; }
396 debug_assert_valid_ptr();
397 debug_assert_in_range(offset, size_in);
400 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 401 ,arcp_.persistingView(offset, size_in)
408 template<
class T>
inline 411 if (size_in == 0) {
return null; }
412 debug_assert_valid_ptr();
413 debug_assert_in_range(offset, size_in);
414 return ArrayView<const T>(
416 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 417 ,arcp_.persistingView(offset, size_in)
425 template<
class T>
inline 428 return view(offset, size_in);
431 template<
class T>
inline 434 return view(offset, size_in);
438 template<
class T>
inline 441 debug_assert_valid_ptr();
445 template<
class T>
inline 448 debug_assert_valid_ptr();
453 template<
class T>
inline 456 debug_assert_valid_ptr();
457 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 464 template<
class T>
inline 470 template<
class T>
inline 483 debug_assert_valid_ptr();
484 debug_assert_not_null();
485 if (this->getRawPtr()==array.getRawPtr() && this->
size()==array.size())
487 debug_assert_in_range(0,array.size());
488 std::copy( array.begin(), array.end(), this->begin() );
500 debug_assert_valid_ptr();
501 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 502 return arcp_.create_weak();
511 debug_assert_valid_ptr();
512 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 513 return arcp_.create_weak();
523 debug_assert_valid_ptr();
524 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 525 return arcp_.create_weak() + size_;
534 debug_assert_valid_ptr();
535 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 536 return arcp_.create_weak() + size_;
569 "Error, size=0 is not allowed!" );
572 ( 0 <= offset && offset+size_in <= this->
size() )
577 typeName(*
this)<<
"::assert_in_range():" 578 " Error, [offset,offset+size) = ["<<offset<<
","<<(offset+size_in)<<
")" 579 " does not lie in the range [0,"<<this->
size()<<
")!" 590 "Error, size=0 is not allowed!" );
593 ( 0 <= offset && offset+size_in <= this->
size() )
598 typeName(*
this)<<
"::assert_in_range():" 599 " Error, [offset,offset+size) = ["<<offset<<
","<<(offset+size_in)<<
")" 600 " does not lie in the range [0,"<<this->
size()<<
")!" 606 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 609 ArrayView<T>::ArrayView(
const ArrayRCP<T> &
arcp )
614 ArrayView<const T>::ArrayView(
const ArrayRCP<const T> &
arcp )
620 ArrayView<T>::ArrayView(T* p, size_type size_in,
const ArrayRCP<T> &
arcp)
621 : ptr_(p), size_(size_in), arcp_(
arcp)
625 ArrayView<const T>::ArrayView(
const T* p, size_type size_in,
const ArrayRCP<const T> &
arcp)
626 : ptr_(p), size_(size_in), arcp_(
arcp)
630 #endif // HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 637 void ArrayView<T>::setUpIterators(
const ERCPNodeLookup rcpNodeLookup)
639 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 640 if (ptr_ && arcp_.is_null()) {
641 arcp_ = ArrayRCP<T>(ptr_, 0, size_,
false, rcpNodeLookup);
644 (void) rcpNodeLookup;
645 #endif // HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 649 void ArrayView<const T>::setUpIterators(
const ERCPNodeLookup rcpNodeLookup)
651 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 652 if (ptr_ && arcp_.is_null()) {
653 arcp_ = ArrayRCP<const T>(ptr_, 0, size_,
false, rcpNodeLookup);
656 (void) rcpNodeLookup;
657 #endif // HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 669 template<
class T>
inline 671 Teuchos::arrayView( T* p,
typename ArrayView<T>::size_type
size )
675 return ArrayView<T>(p,
size);
679 template<
class T>
inline 684 return ArrayView<T>(vec);
688 template<
class T>
inline 693 return ArrayView<const T>(vec);
699 template<
class T>
inline 700 std::vector<T> Teuchos::createVector(
const ArrayView<T> &av )
702 std::vector<T> v(av.begin(), av.end());
709 template<
class T>
inline 710 std::vector<T> Teuchos::createVector(
const ArrayView<const T> &av )
712 std::vector<T> v(av.begin(), av.end());
717 template<
class T>
inline 724 template<
class T>
inline 727 return !av.is_null();
732 std::ostream& Teuchos::operator<<( std::ostream& out, const ArrayView<T>& p )
734 return out << p.toString();
738 template<
class T2,
class T1>
741 Teuchos::av_const_cast(
const ArrayView<T1>& p1)
743 T2 *ptr2 =
const_cast<T2*
>(p1.getRawPtr());
744 return ArrayView<T2>(ptr2, p1.size());
749 template<
class T2,
class T1>
752 Teuchos::av_reinterpret_cast(
const ArrayView<T1>& p1)
754 typedef typename ArrayView<T1>::size_type size_type;
755 const int sizeOfT1 =
sizeof(T1);
756 const int sizeOfT2 =
sizeof(T2);
757 size_type size2 = (p1.size()*sizeOfT1) / sizeOfT2;
758 T2 *ptr2 =
reinterpret_cast<T2*
>(p1.getRawPtr());
759 return ArrayView<T2>(
761 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 769 #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.