42 #ifndef TEUCHOS_ARRAY_VIEW_HPP 43 #define TEUCHOS_ARRAY_VIEW_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 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 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 std::ostringstream ss;
274 if (i + 1 <
size ()) {
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 332 template<
class T>
inline 339 template<
class T>
inline 342 debug_assert_valid_ptr();
343 debug_assert_in_range(i,1);
347 template<
class T>
inline 356 template<
class T>
inline 359 debug_assert_not_null();
360 debug_assert_valid_ptr();
364 template<
class T>
inline 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 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; }
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 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();
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();
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_;
535 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 536 return arcp_.create_weak() +
size_;
550 throw_null_ptr_error(
typeName(*
this));
558 throw_null_ptr_error(
typeName(*
this));
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 610 : ptr_(arcp.
getRawPtr()), size_(arcp.size()), arcp_(arcp)
615 : ptr_(arcp.
getRawPtr()), size_(arcp.size()), arcp_(arcp)
621 : ptr_(p), size_(size_in), arcp_(arcp)
626 : ptr_(p), size_(size_in), arcp_(arcp)
630 #endif // HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 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 651 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 652 if (
ptr_ && arcp_.is_null()) {
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
void debug_assert_in_range(size_type offset, size_type size_in) const
void assign(const ArrayView< const T > &array) const
Copy the data from one array view object to this array view object.
void setUpIterators(const ERCPNodeLookup rcpNodeLookup=RCP_ENABLE_NODE_LOOKUP)
const T * getRawPtr() const
T & operator[](size_type i) const
Random object access.
const ArrayView< T > & assert_not_null() const
Throws NullReferenceError if this->get()==NULL, otherwise returns reference to *this.
std::string typeName(const T &t)
Template function for returning the concrete type name of a passed-in object.
pointer iterator
Type of a nonconst iterator.
Partial specialization of ArrayRCP for const T.
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.
RawPointerConversionTraits< Container >::Ptr_t getRawPtr(const Container &c)
const T & getConst(T &t)
Return a constant reference to an object given a non-const reference.
size_type size() const
The total number of items in the managed array.
#define REFCOUNTPTR_INLINE
ERCPNodeLookup
Used to determine if RCPNode lookup is performed or not.
T * data() const
Return a raw pointer to beginning of array.
ENull
Used to initialize a RCP object to NULL using an implicit conversion!
T & front() const
Get the first element.
T & back() const
Get the last element.
ArrayRCP< T2 > arcp_reinterpret_cast(const ArrayRCP< T1 > &p1)
Reinterpret cast of underlying ArrayRCP type from T1* to T2*.
iterator begin() const
Return an iterator to beginning of the array of data.
ArrayView< const T > getConst() const
Return a const view of a possibly nonconst view.
std::string toString() const
Convert an ArrayView<T> to an std::string
#define TEUCHOSCORE_LIB_DLL_EXPORT
void debug_assert_not_null() const
bool is_null() const
Returns true if the underlying pointer is null.
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.
T * getRawPtr() const
Return a raw pointer to beginning of array or NULL if unsized.
ArrayView(ENull null_arg=null)
Constructor that initializes to NULL (implicitly or explicitly).
const ArrayView< T > & assert_in_range(size_type offset, size_type size) const
Throws NullReferenceError if this->get()==NULL orthis->get()!=NULL, throws RangeError if (offset < 0 ...
Partial specialization of ArrayView for const T.
Range error exception class.
void debug_assert_valid_ptr() const
iterator end() const
Return an iterator to past the end of the array of data.
ArrayView< T > & operator=(const ArrayView< T > &array)
Shallow copy assignment operator.
ArrayView< T > view(size_type offset, size_type size) const
Return a view of a contiguous range of elements.
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...
const ArrayView< T > & operator()() const
Return *this (just for compatibility with Array and ArrayPtr).
Reference-counted smart pointer for managing arrays.