Teuchos Package Browser (Single Doxygen Collection) Version of the Day
Public Member Functions | Private Member Functions | Private Attributes | Related Functions
Teuchos::ArrayView< T > Class Template Reference

Array view class. More...

#include <Teuchos_ArrayViewDecl.hpp>

Inheritance diagram for Teuchos::ArrayView< T >:
Inheritance graph
[legend]

List of all members.

Public Member Functions

T * access_private_ptr () const

Private Member Functions

void setUpIterators (const ERCPNodeLookup rcpNodeLookup=RCP_ENABLE_NODE_LOOKUP)
void debug_assert_not_null () const
void debug_assert_in_range (size_type offset, size_type size_in) const
void debug_assert_valid_ptr () const

Private Attributes

T * ptr_
int size_

Related Functions

(Note that these are not member functions.)

template<class T >
ArrayView< T > arrayView (T *p, typename ArrayView< T >::size_type size)
 Construct a const or non-const view to const or non-const data.
template<class T >
ArrayView< T > arrayViewFromVector (std::vector< T > &vec)
 Construct a non-const view of an std::vector.
template<class T >
ArrayView< const T > arrayViewFromVector (const std::vector< T > &vec)
 Construct a const view of an std::vector.
template<class T >
std::vector< T > createVector (const ArrayView< T > &av)
 Get a new std::vector<T> object out of an ArrayView<T> object.
template<class T >
std::vector< T > createVector (const ArrayView< const T > &av)
 Get a new std::vector<T> object out of an ArrayView<const T> object.
template<class T >
bool is_null (const ArrayView< T > &av)
 Returns true if av.is_null()==true.
template<class T >
bool nonnull (const ArrayView< T > &av)
 Returns true if av.get()!=NULL.
template<class T >
std::ostream & operator<< (std::ostream &out, const ArrayView< T > &av)
 Output stream inserter.
template<class T2 , class T1 >
ArrayView< T2 > av_const_cast (const ArrayView< T1 > &p1)
 Const cast of underlying ArrayView type from const T* to T*.
template<class T2 , class T1 >
ArrayView< T2 > av_reinterpret_cast (const ArrayView< T1 > &p1)
 Reinterpret cast of underlying ArrayView type from T1* to T2*.

std::vector typedefs

typedef Teuchos_Ordinal Ordinal
 
typedef Ordinal size_type
 
typedef Ordinal difference_type
 
typedef T value_type
 
typedef T * pointer
 
typedef const T * const_pointer
 
typedef T & reference
 
typedef const T & const_reference
 
typedef pointer iterator
 
typedef const_pointer const_iterator
 

Constructors/Destructors

 ArrayView (ENull null_arg=null)
 Initialize to NULL (implicitly or explicitly).
 ArrayView (T *p, size_type size, const ERCPNodeLookup rcpNodeLookup=RCP_ENABLE_NODE_LOOKUP)
 Initialize view from raw memory.
 ArrayView (const ArrayView< T > &array)
 Initialize from another ArrayView<T> object.
 ArrayView (std::vector< typename ConstTypeTraits< T >::NonConstType > &vec)
 Non-const view of an std::vector<T> .
 ArrayView (const std::vector< typename ConstTypeTraits< T >::NonConstType > &vec)
 Const view of an std::vector<T> .
ArrayView< T > & operator= (const ArrayView< T > &array)
 Shallow copy assignment operator.
 ~ArrayView ()
 Destroy the array view object.

General query functions

bool is_null () const
 Returns true if the underlying pointer is null.
size_type size () const
 The total number of items in the managed array.
std::string toString () const
 Convert an ArrayView<T> to an std::string

Element Access Functions

T * getRawPtr () const
 Return a raw pointer to beginning of array or NULL if unsized.
T & operator[] (size_type i) const
 Random object access.
T & front () const
 Get the first element.
T & back () const
 Get the last element.

Views

ArrayView< T > view (size_type offset, size_type size) const
 Return a view of a contiguous range of elements.
ArrayView< T > operator() (size_type offset, size_type size) const
 Return a view of a contiguous range of elements (calls view(offset, size)).
const ArrayView< T > & operator() () const
 Return a *this (just for compatibility with Array and ArrayPtr)
ArrayView< const T > getConst () const
 Return an ArrayView<const T> of an ArrayView<T> object.
 operator ArrayView< const T > () const
 Impliict conversion from ArrayView<T> to ArrayView<const T>.

Assignment

void assign (const ArrayView< const T > &array) const
 Copy the data from one array view object to this array view object.

Standard Container-Like Functions

iterator begin () const
 Return an iterator to beginning of the array of data.
iterator end () const
 Return an iterator to past the end of the array of data.

Assertion Functions.

const ArrayView< T > & assert_not_null () const
 Throws NullReferenceError if this->get()==NULL, otherwise returns reference to *this.
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 || this->size() < offset+size, otherwise returns reference to *this

Detailed Description

template<class T>
class Teuchos::ArrayView< T >

Array view class.

This class is designed to be used as a substitute for array arguments to functions. It aggregates a pointer to a contiguous array of data and the size of that array. In debug mode, it will perform runtime checks of all usage.

The ArrayView class has the same shallow copy semantics of the # Ptr class. ArrayView is to ArrayRCP as Ptr is to RCP.

Design Discussion

This class is setup to allow derived classes that can only be allocated on the stack.

Definition at line 77 of file Teuchos_ArrayViewDecl.hpp.


Member Typedef Documentation

template<class T>
typedef Teuchos_Ordinal Teuchos::ArrayView< T >::Ordinal

Definition at line 84 of file Teuchos_ArrayViewDecl.hpp.

template<class T>
typedef Ordinal Teuchos::ArrayView< T >::size_type

Definition at line 87 of file Teuchos_ArrayViewDecl.hpp.

template<class T>
typedef Ordinal Teuchos::ArrayView< T >::difference_type

Definition at line 89 of file Teuchos_ArrayViewDecl.hpp.

template<class T>
typedef T Teuchos::ArrayView< T >::value_type

Definition at line 91 of file Teuchos_ArrayViewDecl.hpp.

template<class T>
typedef T* Teuchos::ArrayView< T >::pointer

Definition at line 93 of file Teuchos_ArrayViewDecl.hpp.

template<class T>
typedef const T* Teuchos::ArrayView< T >::const_pointer

Definition at line 95 of file Teuchos_ArrayViewDecl.hpp.

template<class T>
typedef T& Teuchos::ArrayView< T >::reference

Definition at line 97 of file Teuchos_ArrayViewDecl.hpp.

template<class T>
typedef const T& Teuchos::ArrayView< T >::const_reference

Definition at line 99 of file Teuchos_ArrayViewDecl.hpp.

template<class T>
typedef pointer Teuchos::ArrayView< T >::iterator

Definition at line 108 of file Teuchos_ArrayViewDecl.hpp.

template<class T>
typedef const_pointer Teuchos::ArrayView< T >::const_iterator

Definition at line 110 of file Teuchos_ArrayViewDecl.hpp.


Constructor & Destructor Documentation

template<class T >
Teuchos::ArrayView< T >::ArrayView ( ENull  null_arg = null) [inline]

Initialize to NULL (implicitly or explicitly).

Definition at line 58 of file Teuchos_ArrayView.hpp.

template<class T>
Teuchos::ArrayView< T >::ArrayView ( T *  p,
size_type  size,
const ERCPNodeLookup  rcpNodeLookup = RCP_ENABLE_NODE_LOOKUP 
) [inline]

Initialize view from raw memory.

Parameters:
p[in] Pointer to array of typed memory of size size. If p==0, then *this is a null view. Note that the memory pointed to by p can not go away until this view object is destoryed!
size[in] The size of the array that *this will represent pointer to by p. If p==0 then size must be 0!

Preconditions:

  • [p!=0] size > 0
  • [p==0] size == 0

Postconditions:

  • ???

Definition at line 66 of file Teuchos_ArrayView.hpp.

template<class T>
Teuchos::ArrayView< T >::ArrayView ( const ArrayView< T > &  array) [inline]

Initialize from another ArrayView<T> object.

After construction, this and array will reference the same array.

This form of the copy constructor is required even though the below more general templated version is sufficient since some compilers will generate this function automatically which will give an incorrect implementation.

Postconditions:

  • ???

Definition at line 78 of file Teuchos_ArrayView.hpp.

template<class T>
Teuchos::ArrayView< T >::ArrayView ( std::vector< typename ConstTypeTraits< T >::NonConstType > &  vec) [inline]

Non-const view of an std::vector<T> .

Definition at line 87 of file Teuchos_ArrayView.hpp.

template<class T>
Teuchos::ArrayView< T >::ArrayView ( const std::vector< typename ConstTypeTraits< T >::NonConstType > &  vec) [inline]

Const view of an std::vector<T> .

Definition at line 97 of file Teuchos_ArrayView.hpp.

template<class T >
Teuchos::ArrayView< T >::~ArrayView ( ) [inline]

Destroy the array view object.

Definition at line 119 of file Teuchos_ArrayView.hpp.


Member Function Documentation

template<class T>
ArrayView< T > & Teuchos::ArrayView< T >::operator= ( const ArrayView< T > &  array) [inline]

Shallow copy assignment operator.

Definition at line 107 of file Teuchos_ArrayView.hpp.

template<class T >
bool Teuchos::ArrayView< T >::is_null ( ) const [inline]

Returns true if the underlying pointer is null.

Definition at line 128 of file Teuchos_ArrayView.hpp.

template<class T >
ArrayView< T >::size_type Teuchos::ArrayView< T >::size ( ) const [inline]

The total number of items in the managed array.

Definition at line 135 of file Teuchos_ArrayView.hpp.

template<typename T >
std::string Teuchos::ArrayView< T >::toString ( ) const

Convert an ArrayView<T> to an std::string

Definition at line 143 of file Teuchos_ArrayView.hpp.

template<class T >
T * Teuchos::ArrayView< T >::getRawPtr ( ) const [inline]

Return a raw pointer to beginning of array or NULL if unsized.

Definition at line 169 of file Teuchos_ArrayView.hpp.

template<class T >
T & Teuchos::ArrayView< T >::operator[] ( size_type  i) const [inline]

Random object access.

Preconditions:

Definition at line 177 of file Teuchos_ArrayView.hpp.

template<class T >
T & Teuchos::ArrayView< T >::front ( ) const [inline]

Get the first element.

Definition at line 186 of file Teuchos_ArrayView.hpp.

template<class T >
T & Teuchos::ArrayView< T >::back ( ) const [inline]

Get the last element.

Definition at line 195 of file Teuchos_ArrayView.hpp.

template<class T >
ArrayView< T > Teuchos::ArrayView< T >::view ( size_type  offset,
size_type  size 
) const [inline]

Return a view of a contiguous range of elements.

Preconditions:

  • this->get() != NULL
  • 0 <= offset && offset + size <= this->size()

Postconditions:

  • returnVal.size() == size

NOTE: A size==0 view of even a null ArrayView is allowed and returns a null view.

Definition at line 207 of file Teuchos_ArrayView.hpp.

template<class T >
ArrayView< T > Teuchos::ArrayView< T >::operator() ( size_type  offset,
size_type  size 
) const [inline]

Return a view of a contiguous range of elements (calls view(offset, size)).

Definition at line 224 of file Teuchos_ArrayView.hpp.

template<class T >
const ArrayView< T > & Teuchos::ArrayView< T >::operator() ( ) const [inline]

Return a *this (just for compatibility with Array and ArrayPtr)

Definition at line 231 of file Teuchos_ArrayView.hpp.

template<class T >
ArrayView< const T > Teuchos::ArrayView< T >::getConst ( ) const [inline]

Return an ArrayView<const T> of an ArrayView<T> object.

WARNING! If T is already const (e.g. const double) then do not try to instantiate this function since it will not compile!

Definition at line 239 of file Teuchos_ArrayView.hpp.

template<class T >
Teuchos::ArrayView< T >::operator ArrayView< const T > ( ) const [inline]

Impliict conversion from ArrayView<T> to ArrayView<const T>.

WARNING! If T is already const (e.g. const double) then do not try to instantiate this function since it will not compile!

Definition at line 250 of file Teuchos_ArrayView.hpp.

template<class T>
void Teuchos::ArrayView< T >::assign ( const ArrayView< const T > &  array) const

Copy the data from one array view object to this array view object.

Preconditions:

  • this->size() == array.size()

WARNING! If T is a const type (e.g. const double) then do not try to instantiate this function since it will not compile!

NOTE: This function is really like an operator=() function except that it is declared const. This is the correct behavior since a const ArrayView simply means that we can not change what *this points to. The type of the template argument always determines if the underlyihng data is const or not.

Definition at line 260 of file Teuchos_ArrayView.hpp.

template<class T >
ArrayView< T >::iterator Teuchos::ArrayView< T >::begin ( ) const

Return an iterator to beginning of the array of data.

If HAVE_TEUCHOS_ARRAY_BOUNDSCHECK is defined then the iterator returned is an ArrayRCP<T> object and all operations are checked at runtime. When HAVE_TEUCHOS_ARRAY_BOUNDSCHECK is not defined, the a raw pointer T* is returned for fast execution.

Postconditions:

  • [this->get()!=NULL] &*return == this->get()
  • [this->get()==NULL] return == (null or NULL)

Definition at line 277 of file Teuchos_ArrayView.hpp.

template<class T >
ArrayView< T >::iterator Teuchos::ArrayView< T >::end ( ) const

Return an iterator to past the end of the array of data.

If HAVE_TEUCHOS_ARRAY_BOUNDSCHECK is defined then the iterator returned is an ArrayView<T> object and all operations are checked at runtime. When HAVE_TEUCHOS_ARRAY_BOUNDSCHECK is not defined, the a raw pointer T* is returned for fast execution.

Postconditions:

  • [this->get()!=NULL] &*end == this->get()+(this->upperOffset()+1)
  • [this->get()==NULL] return == (null or NULL)

Definition at line 289 of file Teuchos_ArrayView.hpp.

template<class T >
const ArrayView< T > & Teuchos::ArrayView< T >::assert_not_null ( ) const

Throws NullReferenceError if this->get()==NULL, otherwise returns reference to *this.

Definition at line 304 of file Teuchos_ArrayView.hpp.

template<class T >
const ArrayView< T > & Teuchos::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 || this->size() < offset+size, otherwise returns reference to *this

Definition at line 314 of file Teuchos_ArrayView.hpp.

template<class T >
void Teuchos::ArrayView< T >::setUpIterators ( const ERCPNodeLookup  rcpNodeLookup = RCP_ENABLE_NODE_LOOKUP) [private]

Definition at line 355 of file Teuchos_ArrayView.hpp.

template<class T>
void Teuchos::ArrayView< T >::debug_assert_not_null ( ) const [inline, private]

Definition at line 367 of file Teuchos_ArrayViewDecl.hpp.

template<class T>
void Teuchos::ArrayView< T >::debug_assert_in_range ( size_type  offset,
size_type  size_in 
) const [inline, private]

Definition at line 374 of file Teuchos_ArrayViewDecl.hpp.

template<class T>
void Teuchos::ArrayView< T >::debug_assert_valid_ptr ( ) const [inline, private]

Definition at line 382 of file Teuchos_ArrayViewDecl.hpp.

template<class T>
T* Teuchos::ArrayView< T >::access_private_ptr ( ) const [inline]

Definition at line 393 of file Teuchos_ArrayViewDecl.hpp.


Friends And Related Function Documentation

template<class T >
ArrayView< T > arrayView ( T *  p,
typename ArrayView< T >::size_type  size 
) [related]

Construct a const or non-const view to const or non-const data.

template<class T >
ArrayView< T > arrayViewFromVector ( std::vector< T > &  vec) [related]

Construct a non-const view of an std::vector.

template<class T >
ArrayView< const T > arrayViewFromVector ( const std::vector< T > &  vec) [related]

Construct a const view of an std::vector.

template<class T >
std::vector< T > createVector ( const ArrayView< T > &  av) [related]

Get a new std::vector<T> object out of an ArrayView<T> object.

Note that a copy of data is made!

template<class T >
std::vector< T > createVector ( const ArrayView< const T > &  av) [related]

Get a new std::vector<T> object out of an ArrayView<const T> object.

Note that a copy of data is made!

template<class T >
bool is_null ( const ArrayView< T > &  av) [related]

Returns true if av.is_null()==true.

template<class T >
bool nonnull ( const ArrayView< T > &  av) [related]

Returns true if av.get()!=NULL.

template<class T >
std::ostream & operator<< ( std::ostream &  out,
const ArrayView< T > &  av 
) [related]

Output stream inserter.

The implementation of this function just prints pointer addresses and therefore puts no restrictions on the data types involved.

template<class T2 , class T1 >
ArrayView< T2 > av_const_cast ( const ArrayView< T1 > &  p1) [related]

Const cast of underlying ArrayView type from const T* to T*.

The function will compile only if (const_cast<T2*>(p1.get());) compiles.

template<class T2 , class T1 >
ArrayView< T2 > av_reinterpret_cast ( const ArrayView< T1 > &  p1) [related]

Reinterpret cast of underlying ArrayView type from T1* to T2*.

The function will compile only if (reinterpret_cast<T2*>(p1.get());) compiles.

Warning! Do not use this function unless you absolutely know what you are doing. Doing a reinterpret cast is always a tricking thing and must only be done by developers who are 100% comfortable with what they are doing.


Member Data Documentation

template<class T>
T* Teuchos::ArrayView< T >::ptr_ [private]

Definition at line 356 of file Teuchos_ArrayViewDecl.hpp.

template<class T>
int Teuchos::ArrayView< T >::size_ [private]

Definition at line 357 of file Teuchos_ArrayViewDecl.hpp.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines