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();
234 if (i + 1 < size ()) {
246 std::ostringstream ss;
248 debug_assert_valid_ptr();
254 if (i + 1 < size ()) {
266 TEUCHOSCORE_LIB_DLL_EXPORT std::string
272 TEUCHOSCORE_LIB_DLL_EXPORT std::string
278 TEUCHOSCORE_LIB_DLL_EXPORT std::string
284 TEUCHOSCORE_LIB_DLL_EXPORT std::string
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);
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 425 return arcp_.getConst()();
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_;
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 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 646 template<
class T>
inline 655 template<
class T>
inline 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 679 std::vector<T> v(av.begin(), av.end());
684 template<
class T>
inline 691 template<
class T>
inline 699 std::ostream& Teuchos::operator<<( std::ostream& out, const ArrayView<T>& p )
701 return out << p.toString();
705 template<
class T2,
class T1>
710 T2 *ptr2 =
const_cast<T2*
>(p1.
getRawPtr());
716 template<
class T2,
class T1>
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());
728 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK 729 ,arcp_reinterpret_cast<T2>(p1.access_private_arcp())
736 #endif // TEUCHOS_ARRAY_VIEW_HPP std::string toString() const
Convert an ArrayView<T> to an std::string
T & front() const
Get the first element.
pointer iterator
Type of a nonconst iterator.
bool is_null() const
Returns true if the underlying pointer is null.
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 ArrayRCP for const T.
iterator begin() const
Return an iterator to beginning of the array of data.
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
T * getRawPtr() const
Get the raw C++ pointer to the underlying object.
Ordinal size_type
Type representing the number of elements in an ArrayRCP or view thereof.
size_type size() const
The total number of items in the managed array.
size_type size() const
The total number of entries in the array.
void assign(const ArrayView< const T > &array) const
Copy the data from one array view object to this array view object.
T * getRawPtr() const
Return a raw pointer to beginning of array or NULL if unsized.
const ArrayView< T > & assert_not_null() const
Throws NullReferenceError if this->get()==NULL, otherwise returns reference to *this.
const ArrayView< T > & operator()() const
Return *this (just for compatibility with Array and ArrayPtr).
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).
iterator end() const
Return an iterator to past the end of the array of data.
TypeTo as(const TypeFrom &t)
Convert from one value type to another.
ArrayView< T > view(size_type offset, size_type size) const
Return a view of a contiguous range of elements.
Partial specialization of ArrayView for const T.
Range error exception class.
T & operator[](size_type i) const
Random object access.
ArrayView< T > & operator=(const ArrayView< T > &array)
Shallow copy assignment operator.
Definition of Teuchos::as, for conversions between types.
ArrayView< const T > getConst() const
Return a const view of a possibly nonconst view.
T & back() const
Get the last element.
#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.
Reference-counted smart pointer for managing arrays.