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_(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 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 226 std::ostringstream ss;
228 debug_assert_valid_ptr();
231 for (
size_type i = 0; i < size (); ++i) {
233 ss << operator[] (i);
234 if (i + 1 < size ()) {
246 std::ostringstream ss;
254 if (i + 1 <
size ()) {
291 template<
class T>
inline 294 debug_assert_valid_ptr();
298 template<
class T>
inline 306 template<
class T>
inline 309 debug_assert_valid_ptr();
310 debug_assert_in_range(i,1);
314 template<
class T>
inline 323 template<
class T>
inline 326 debug_assert_not_null();
327 debug_assert_valid_ptr();
331 template<
class T>
inline 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 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; }
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 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();
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();
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_;
502 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 503 return arcp_.create_weak() +
size_;
517 throw_null_ptr_error(
typeName(*
this));
525 throw_null_ptr_error(
typeName(*
this));
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 577 : ptr_(arcp.
getRawPtr()), size_(arcp.size()), arcp_(arcp)
582 : ptr_(arcp.
getRawPtr()), size_(arcp.size()), arcp_(arcp)
588 : ptr_(p), size_(size_in), arcp_(arcp)
593 : ptr_(p), size_(size_in), arcp_(arcp)
597 #endif // HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 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 618 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 619 if (
ptr_ && arcp_.is_null()) {
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
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.
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.