42#ifndef TEUCHOS_ARRAY_VIEW_HPP
43#define TEUCHOS_ARRAY_VIEW_HPP
57template<
class T>
inline
64template<
class T>
inline
73template<
class T>
inline
77#ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
97template<
class T>
inline
101#ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
122template<
class T>
inline
130template<
class T>
inline
139template<
class T>
inline
143 : ptr_( vec.empty() ? 0 : vec.data() ), size_(vec.size())
148template<
class T>
inline
152 : ptr_( vec.empty() ? 0 : vec.data() ), size_(vec.size())
158template<
class T>
inline
162 : ptr_( vec.empty() ? 0 : vec.data() ), size_(vec.size())
167template<
class T>
inline
171 : ptr_( vec.empty() ? 0 : vec.data() ), size_(vec.size())
177template<
class T>
inline
182#ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
188template<
class T>
inline
193#ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
200template<
class T>
inline
204template<
class T>
inline
227template<
class T>
inline
230 debug_assert_valid_ptr();
234template<
class T>
inline
237 debug_assert_valid_ptr();
246 std::ostringstream
ss;
248 debug_assert_valid_ptr();
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 ()) {
311template<
class T>
inline
314 debug_assert_valid_ptr();
318template<
class T>
inline
321 debug_assert_valid_ptr();
325template<
class T>
inline
328 debug_assert_valid_ptr();
332template<
class T>
inline
335 debug_assert_valid_ptr();
339template<
class T>
inline
342 debug_assert_valid_ptr();
343 debug_assert_in_range(
i,1);
347template<
class T>
inline
350 debug_assert_valid_ptr();
351 debug_assert_in_range(
i,1);
356template<
class T>
inline
359 debug_assert_not_null();
360 debug_assert_valid_ptr();
364template<
class T>
inline
367 debug_assert_not_null();
368 debug_assert_valid_ptr();
372template<
class T>
inline
375 debug_assert_not_null();
376 debug_assert_valid_ptr();
377 return *(ptr_+size_-1);
380template<
class T>
inline
383 debug_assert_not_null();
384 debug_assert_valid_ptr();
385 return *(ptr_+size_-1);
392template<
class T>
inline
396 debug_assert_valid_ptr();
408template<
class T>
inline
412 debug_assert_valid_ptr();
414 return ArrayView<const T>(
425template<
class T>
inline
431template<
class T>
inline
438template<
class T>
inline
441 debug_assert_valid_ptr();
445template<
class T>
inline
448 debug_assert_valid_ptr();
453template<
class T>
inline
456 debug_assert_valid_ptr();
457#ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
464template<
class T>
inline
470template<
class T>
inline
483 debug_assert_valid_ptr();
484 debug_assert_not_null();
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_;
550 throw_null_ptr_error(
typeName(*
this));
558 throw_null_ptr_error(
typeName(*
this));
569 "Error, size=0 is not allowed!" );
577 typeName(*
this)<<
"::assert_in_range():"
579 " does not lie in the range [0,"<<this->
size()<<
")!"
590 "Error, size=0 is not allowed!" );
598 typeName(*
this)<<
"::assert_in_range():"
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)
639#ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
640 if (ptr_ &&
arcp_.is_null()) {
651#ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
652 if (ptr_ &&
arcp_.is_null()) {
669template<
class T>
inline
671Teuchos::arrayView( T* p,
typename ArrayView<T>::size_type size )
675 return ArrayView<T>(p, size);
679template<
class T>
inline
684 return ArrayView<T>(vec);
688template<
class T>
inline
693 return ArrayView<const T>(vec);
699template<
class T>
inline
700std::vector<T> Teuchos::createVector(
const ArrayView<T> &av )
702 std::vector<T> v(av.begin(), av.end());
709template<
class T>
inline
710std::vector<T> Teuchos::createVector(
const ArrayView<const T> &av )
712 std::vector<T> v(av.begin(), av.end());
717template<
class T>
inline
724template<
class T>
inline
727 return !av.is_null();
734 return out << p.toString();
738template<
class T2,
class T1>
741Teuchos::av_const_cast(
const ArrayView<T1>& p1)
743 T2 *ptr2 =
const_cast<T2*
>(p1.getRawPtr());
744 return ArrayView<T2>(ptr2, p1.size());
749template<
class T2,
class T1>
752Teuchos::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
762 ,arcp_reinterpret_cast<T2>(p1.access_private_arcp())
#define TEUCHOSCORE_LIB_DLL_EXPORT
#define REFCOUNTPTR_INLINE
Definition of Teuchos::as, for conversions between types.
void setUpIterators(const ERCPNodeLookup rcpNodeLookup=RCP_ENABLE_NODE_LOOKUP)
bool is_null() const
Returns true if the underlying pointer is null.
iterator end() const
Return an iterator to past the end of the array of data.
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 ...
iterator begin() const
Return an iterator to beginning of the array of data.
ArrayView(ENull null_arg=null)
Constructor that initializes to NULL (implicitly or explicitly).
T & front() const
Get the first element.
ArrayView< T > & operator=(const ArrayView< T > &array)
Shallow copy assignment operator.
const ArrayView< T > & assert_not_null() const
Throws NullReferenceError if this->get()==NULL, otherwise returns reference to *this.
ArrayView< T > view(size_type offset, size_type size) const
Return a view of a contiguous range of elements.
T * data() const
Return a raw pointer to beginning of array.
ArrayView< const T > getConst() const
Return a const view of a possibly nonconst view.
const ArrayView< T > & operator()() const
Return *this (just for compatibility with Array and ArrayPtr).
pointer iterator
Type of a nonconst iterator.
size_type size() const
The total number of items in the managed array.
T & back() const
Get the last element.
void assign(const ArrayView< const T > &array) const
Copy the data from one array view object to this array view object.
std::string toString() const
Convert an ArrayView<T> to an std::string
T * getRawPtr() const
Return a raw pointer to beginning of array or NULL if unsized.
T & operator[](size_type i) const
Random object access.
Ordinal size_type
Type representing the number of elements in an ArrayRCP or view thereof.
int size(const Comm< Ordinal > &comm)
Get the number of processes in the communicator.
Range error exception class.
Concrete serial communicator subclass.
#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.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
bool is_null(const std::shared_ptr< T > &p)
Returns true if p.get()==NULL.
bool nonnull(const std::shared_ptr< T > &p)
Returns true if p.get()!=NULL.
TypeTo as(const TypeFrom &t)
Convert from one value type to another.
std::string typeName(const T &t)
Template function for returning the concrete type name of a passed-in object.
std::ostream & operator<<(std::ostream &os, BigUInt< n > a)
ERCPNodeLookup
Used to determine if RCPNode lookup is performed or not.
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.