#include <Teuchos_ArrayViewDecl.hpp>
Public Types | |
std::vector typedefs | |
typedef Teuchos_Index | Ordinal |
| |
typedef T | value_type |
| |
typedef T * | pointer |
| |
typedef const T * | const_pointer |
| |
typedef T & | reference |
| |
typedef const T & | const_reference |
| |
typedef ArrayRCP< T > | iterator |
| |
typedef size_t | size_type |
| |
typedef ptrdiff_t | difference_type |
| |
Public Member Functions | |
Constructors/Destructors | |
ArrayView (ENull null_arg=null) | |
Initialize to NULL. | |
ArrayView (T *p, Ordinal size) | |
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 () | |
Destroy the array view object. | |
General query functions | |
Ordinal | 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[] (Ordinal i) const |
Random object access. | |
T & | front () const |
Get the first element. | |
T & | back () const |
Get the last element. | |
Views | |
ArrayView< T > | view (Ordinal offset, Ordinal size) const |
Return a view of a contiguous range of elements. | |
ArrayView< T > | operator() (Ordinal offset, Ordinal 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. | |
ArrayView< T > & | operator= (const ArrayView< T > &) |
Reassign this ArrayView to another ArrayView of the same type. | |
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 (Ordinal offset, Ordinal 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 . | |
Related Functions | |
(Note that these are not member functions.) | |
template<class T > | |
ArrayView< T > | arrayView (T *p, typename ArrayView< T >::Ordinal 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 > &ptr) |
Get a new std::vector<T> object out of an ArrayView<T> object. | |
template<class T > | |
std::vector< T > | createVector (const ArrayView< const T > &ptr) |
Get a new std::vector<T> object out of an ArrayView<const T> object. | |
template<class T > | |
std::ostream & | operator<< (std::ostream &out, const ArrayView< T > &p) |
Output stream inserter. |
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 bind on construction semantics where once an ArrayView
object is bound to an array of data, it can not be bound to a different view of data. Therefore, a const ArrayView
object means that the data entries are const
which is similar to the behavior of a const std::vector
object for instance.
Note that once an ArrayView
object has been constructed, it can not be changed to point to different memory. This is to help avoid improper usage. Therefore, an const ArrayView<T> object is no less restrictive than a non-const ArrayView<T> object. It is the type of T itself that determines if the underying data can be changed or not. Therefore, the only non-const public functions defined on this interface are the constructors and destructor! This may all seem strange but it is very effective.
ToDo: Finish documentation!
Definition at line 77 of file Teuchos_ArrayViewDecl.hpp.
typedef const T* Teuchos::ArrayView< T >::const_pointer |
typedef const T& Teuchos::ArrayView< T >::const_reference |
typedef ptrdiff_t Teuchos::ArrayView< T >::difference_type |
typedef ArrayRCP<T> Teuchos::ArrayView< T >::iterator |
typedef Teuchos_Index Teuchos::ArrayView< T >::Ordinal |
typedef T* Teuchos::ArrayView< T >::pointer |
typedef T& Teuchos::ArrayView< T >::reference |
typedef size_t Teuchos::ArrayView< T >::size_type |
typedef T Teuchos::ArrayView< T >::value_type |
Teuchos::ArrayView< T >::ArrayView | ( | ENull | null_arg = null |
) | [inline] |
Initialize to NULL.
WARNING! Once you initialize to null, you can not rebind to view!
Note: A default value is not given for null_arg
since we want to avoid mistakes where a view is initalized to null and then can't be reset to point to something else!
Definition at line 45 of file Teuchos_ArrayView.hpp.
Teuchos::ArrayView< T >::ArrayView | ( | T * | p, | |
Ordinal | size | |||
) | [inline] |
Initialize view from raw memory.
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! |
p!=0
] size > 0
p==0
] size == 0
Postconditions:
Definition at line 55 of file Teuchos_ArrayView.hpp.
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 67 of file Teuchos_ArrayView.hpp.
Teuchos::ArrayView< T >::ArrayView | ( | std::vector< typename ConstTypeTraits< T >::NonConstType > & | vec | ) | [inline] |
Teuchos::ArrayView< T >::ArrayView | ( | const std::vector< typename ConstTypeTraits< T >::NonConstType > & | vec | ) | [inline] |
Teuchos::ArrayView< T >::~ArrayView | ( | ) | [inline] |
const ArrayView< T > & Teuchos::ArrayView< T >::assert_in_range | ( | Ordinal | offset, | |
Ordinal | size | |||
) | const [inline] |
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 284 of file Teuchos_ArrayView.hpp.
const ArrayView< T > & Teuchos::ArrayView< T >::assert_not_null | ( | ) | const [inline] |
Throws NullReferenceError
if this->get()==NULL
, otherwise returns reference to *this
.
Definition at line 274 of file Teuchos_ArrayView.hpp.
void Teuchos::ArrayView< T >::assign | ( | const ArrayView< const T > & | array | ) | const [inline] |
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!
Definition at line 219 of file Teuchos_ArrayView.hpp.
T & Teuchos::ArrayView< T >::back | ( | ) | const [inline] |
ArrayView< T >::iterator Teuchos::ArrayView< T >::begin | ( | ) | const [inline] |
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:
Definition at line 249 of file Teuchos_ArrayView.hpp.
ArrayView< T >::iterator Teuchos::ArrayView< T >::end | ( | ) | const [inline] |
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 260 of file Teuchos_ArrayView.hpp.
T & Teuchos::ArrayView< T >::front | ( | ) | const [inline] |
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 202 of file Teuchos_ArrayView.hpp.
T * Teuchos::ArrayView< T >::getRawPtr | ( | ) | const [inline] |
Return a raw pointer to beginning of array or NULL if unsized.
Definition at line 136 of file Teuchos_ArrayView.hpp.
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 209 of file Teuchos_ArrayView.hpp.
const ArrayView< T > & Teuchos::ArrayView< T >::operator() | ( | ) | const [inline] |
Return a *this (just for compatibility with Array and ArrayPtr).
Definition at line 195 of file Teuchos_ArrayView.hpp.
ArrayView< T > Teuchos::ArrayView< T >::operator() | ( | Ordinal | offset, | |
Ordinal | size | |||
) | const [inline] |
Return a view of a contiguous range of elements (calls view(offset,size)).
Definition at line 188 of file Teuchos_ArrayView.hpp.
ArrayView< T > & Teuchos::ArrayView< T >::operator= | ( | const ArrayView< T > & | array | ) | [inline] |
Reassign this ArrayView to another ArrayView of the same type.
Definition at line 235 of file Teuchos_ArrayView.hpp.
T & Teuchos::ArrayView< T >::operator[] | ( | Ordinal | i | ) | const [inline] |
ArrayView< T >::Ordinal Teuchos::ArrayView< T >::size | ( | ) | const [inline] |
The total number of items in the managed array.
Definition at line 108 of file Teuchos_ArrayView.hpp.
std::string Teuchos::ArrayView< T >::toString | ( | ) | const [inline] |
ArrayView< T > Teuchos::ArrayView< T >::view | ( | Ordinal | offset, | |
Ordinal | size | |||
) | const [inline] |
Return a view of a contiguous range of elements.
Preconditions:
Postconditions:
returnVal.size() == size
Definition at line 176 of file Teuchos_ArrayView.hpp.
ArrayView< T > arrayView | ( | T * | p, | |
typename ArrayView< T >::Ordinal | size | |||
) | [related] |
Construct a const or non-const view to const or non-const data.
ArrayView< const T > arrayViewFromVector | ( | const std::vector< T > & | vec | ) | [related] |
Construct a const view of an std::vector.
ArrayView< T > arrayViewFromVector | ( | std::vector< T > & | vec | ) | [related] |
Construct a non-const view of an std::vector.
std::vector< T > createVector | ( | const ArrayView< const T > & | ptr | ) | [related] |
Get a new std::vector<T>
object out of an ArrayView<const T>
object.
Note that a copy of data is made!
std::vector< T > createVector | ( | const ArrayView< T > & | ptr | ) | [related] |
Get a new std::vector<T>
object out of an ArrayView<T>
object.
Note that a copy of data is made!
std::ostream & operator<< | ( | std::ostream & | out, | |
const ArrayView< T > & | p | |||
) | [related] |
Output stream inserter.
The implementation of this function just prints pointer addresses and therefore puts no restrictions on the data types involved.