Teuchos Package Browser (Single Doxygen Collection)
Version of the Day
|
Replacement for std::vector that is compatible with the Teuchos Memory Management classes. More...
#include <Teuchos_Array.hpp>
Private Member Functions | |
std::vector< T > & | vec (bool isStructureBeingModified=false, bool activeIter=false) |
const std::vector< T > & | vec () const |
std::vector< T >::iterator | raw_position (iterator position) |
void | assertIndex (size_type i) const |
void | assertNotNull () const |
Private Attributes | |
std::vector< T > | vec_ |
Friends | |
template<typename T2 > | |
bool | Teuchos::operator== (const Array< T2 > &a1, const Array< T2 > &a2) |
template<typename T2 > | |
bool | Teuchos::operator!= (const Array< T2 > &a1, const Array< T2 > &a2) |
template<typename T2 > | |
void | swap (Array< T2 > &a1, Array< T2 > &a2) |
template<typename T2 > | |
bool | Teuchos::operator< (const Array< T2 > &a1, const Array< T2 > &a2) |
template<typename T2 > | |
bool | Teuchos::operator<= (const Array< T2 > &a1, const Array< T2 > &a2) |
template<typename T2 > | |
bool | Teuchos::operator> (const Array< T2 > &a1, const Array< T2 > &a2) |
template<typename T2 > | |
bool | Teuchos::operator>= (const Array< T2 > &a1, const Array< T2 > &a2) |
Related Functions | |
(Note that these are not member functions.) | |
template<typename T > | |
bool | operator== (const Array< T > &a1, const Array< T > &a2) |
Equality operator. More... | |
template<typename T > | |
bool | operator!= (const Array< T > &a1, const Array< T > &a2) |
Non-equality operator. More... | |
template<typename T > | |
void | swap (Array< T > &a1, Array< T > &a2) |
Non-member swap (specializes default std version). More... | |
template<typename T > | |
bool | operator< (const Array< T > &a1, const Array< T > &a2) |
Less-than operator. More... | |
template<typename T > | |
bool | operator<= (const Array< T > &a1, const Array< T > &a2) |
Less-than-or-equal operator. More... | |
template<typename T > | |
bool | operator> (const Array< T > &a1, const Array< T > &a2) |
Greater-than operator. More... | |
template<typename T > | |
bool | operator>= (const Array< T > &a1, const Array< T > &a2) |
Greater-than-or-equal operator. More... | |
template<typename T > | |
std::ostream & | operator<< (std::ostream &os, const Array< T > &array) |
Write an Array to an ostream. More... | |
template<typename T > | |
int | hashCode (const Array< T > &array) |
Return the hash code. More... | |
template<typename T > | |
std::vector< T > | createVector (const Array< T > &a) |
Copy conversion to an std::vector. More... | |
template<typename T > | |
std::string | toString (const Array< T > &array) |
Convert an array to a string representation. More... | |
template<typename T > | |
Array< T > | fromStringToArray (const std::string &arrayStr) |
Converts from std::string representation (as created by toString() ) back into the array object. More... | |
template<typename T > | |
std::istringstream & | operator>> (std::istringstream &in, Array< T > &array) |
A wrapper around the fromStringToArray function which allows the operator>> to be used on Arrays. More... | |
template<typename T > | |
void | extractDataFromISS (std::istringstream &iss, T &data) |
Extracts data from an istringstream object. More... | |
void | extractDataFromISS (std::istringstream &iss, std::string &data) |
Extracts std::string data from an istringstream object. More... | |
std::string | getArrayTypeNameTraitsFormat () |
Get the format that is used for the specialization of the TypeName traits class for Array. More... | |
std::vector typedefs | |
typedef Teuchos_Ordinal | Ordinal |
The type of indices. More... | |
typedef Ordinal | size_type |
The type of Array sizes and capacities. More... | |
typedef Ordinal | difference_type |
The type of the difference between two size_type values. More... | |
typedef std::vector< T > ::value_type | value_type |
The type of an entry of the Array; for compatibility with std::vector. More... | |
typedef std::vector< T >::pointer | pointer |
The type of a pointer to T; for compatibility with std::vector. More... | |
typedef std::vector< T > ::const_pointer | const_pointer |
The type of a const pointer to T; for compatibility with std::vector. More... | |
typedef std::vector< T >::reference | reference |
The type of a reference to T; for compatibility with std::vector. More... | |
typedef std::vector< T > ::const_reference | const_reference |
The type of a const reference to T; for compatibility with std::vector. More... | |
typedef std::vector< T > ::allocator_type | allocator_type |
The allocator type; for compatibility with std::vector. More... | |
typedef std::vector< T >::iterator | iterator |
The type of a forward iterator. More... | |
typedef std::vector< T > ::const_iterator | const_iterator |
The type of a const forward iterator. More... | |
typedef std::vector< T > ::reverse_iterator | reverse_iterator |
The type of a reverse iterator. More... | |
typedef std::vector< T > ::const_reverse_iterator | const_reverse_iterator |
The type of a const reverse iterator. More... | |
All constructors | |
Array () | |
Default constructor; creates an empty Array. More... | |
Array (size_type n, const value_type &value=value_type()) | |
Create an array of length n, and fill it with the given value. More... | |
Array (const Array< T > &x) | |
Copy constructor (does a deep copy). More... | |
template<typename InputIterator > | |
Array (InputIterator first, InputIterator last) | |
Create an array, and fill it with values from the given iterator range. More... | |
Array (const ArrayView< const T > &a) | |
Create an Array which is a deep copy of the given ArrayView. More... | |
template<int N> | |
Array (const Tuple< T, N > &t) | |
Copy constructor from the given Tuple. More... | |
~Array () | |
Destructor. More... | |
Array & | operator= (const Array< T > &a) |
Assignment operator (does a deep copy). More... | |
Other std::vector functions | |
Array has mostly the same interface as std::vector. This allows use of Array in place of std::vector, for gradual porting to use the Teuchos Memory Management classes. | |
void | assign (size_type n, const value_type &val) |
template<typename InputIterator > | |
void | assign (InputIterator first, InputIterator last) |
iterator | begin () |
iterator | end () |
const_iterator | begin () const |
const_iterator | end () const |
reverse_iterator | rbegin () |
reverse_iterator | rend () |
const_reverse_iterator | rbegin () const |
const_reverse_iterator | rend () const |
size_type | size () const |
size_type | max_size () const |
void | resize (size_type new_size, const value_type &x=value_type()) |
size_type | capacity () const |
bool | empty () const |
void | reserve (size_type n) |
reference | operator[] (size_type i) |
const_reference | operator[] (size_type i) const |
reference | at (size_type i) |
const_reference | at (size_type i) const |
reference | front () |
const_reference | front () const |
reference | back () |
const_reference | back () const |
void | push_back (const value_type &x) |
void | pop_back () |
iterator | insert (iterator position, const value_type &x) |
void | insert (iterator position, size_type n, const value_type &x) |
template<typename InputIterator > | |
void | insert (iterator position, InputIterator first, InputIterator last) |
iterator | erase (iterator position) |
iterator | erase (iterator first, iterator last) |
void | swap (Array &x) |
void | clear () |
General non-standard functions. | |
Array< T > & | append (const T &x) |
Add a new entry at the end of the array. More... | |
void | remove (int i) |
Remove the i-th element from the array, with optional boundschecking. More... | |
int | length () const |
Return number of elements in the array. More... | |
std::string | toString () const |
Convert an Array to an std::string More... | |
T * | getRawPtr () |
Return a raw pointer to beginning of array or NULL if unsized. More... | |
T * | data () |
Return a raw pointer to beginning of array. More... | |
const T * | getRawPtr () const |
Return a const raw pointer to beginning of array or NULL if unsized. More... | |
const T * | data () const |
Return a const raw pointer to beginning of array. More... | |
static bool | hasBoundsChecking () |
Return true if Array has been compiled with boundschecking on. More... | |
Conversions to and from std::vector. | |
Array (const std::vector< T > &v) | |
Copy constructor from an std::vector (does a deep copy). More... | |
std::vector< T > | toVector () const |
Explicit copy conversion to an std::vector. More... | |
Array & | operator= (const std::vector< T > &v) |
Assignment operator for std::vector. More... | |
Views | |
ArrayView< T > | view (size_type offset, size_type size) |
Return non-const view of a contiguous range of elements. More... | |
ArrayView< const T > | view (size_type offset, size_type size) const |
Return const view of a contiguous range of elements. More... | |
ArrayView< T > | operator() (size_type offset, size_type size) |
Return a non-const view of a contiguous range of elements (calls view(offset,size)). More... | |
ArrayView< const T > | operator() (size_type offset, size_type size) const |
Return a const view of a contiguous range of elements (calls view(offset,size)). More... | |
ArrayView< T > | operator() () |
Return an non-const ArrayView of *this. More... | |
ArrayView< const T > | operator() () const |
Return an const ArrayView of *this. More... | |
operator ArrayView< T > () | |
Perform an implicit conversion to a non-const ArrayView (calls operator()()). More... | |
operator ArrayView< const T > () const | |
Perform an implicit conversion to a non-const ArrayView (calls operator()()). More... | |
Replacement for std::vector that is compatible with the Teuchos Memory Management classes.
T | The type of each entry in the array. |
This class implements a one-dimensional array, with a number of entries specified at run time. It can be used as a drop-in replacement for the C++98 version of std::vector<T>. It also has functions and methods for interacting with the other Teuchos Memory Management classes. For example, you can get a nonpersisting view of an Array's entries as an ArrayView, or a nonowning (weak) ArrayRCP.
If the CMake configuration option Teuchos_ENABLE_DEBUG is ON at build time, Array will do bounds and iterator checking at run time. This has a nontrivial run-time cost, so it is off by default, but you may find it useful for debugging. Please note that if debugging is on, the types of Array's iterators change in order to implement these checks. Thus, you should always use Array's typedefs to get the iterator types, and not assume that they are raw pointers.
A user can create a Teuchos::Tuple object to initialize an Array object by using one of the the convenient overloaded Teuchos::tuple() non-member constructor functions. For example, see Array_test.cpp for how this is done.
Currently, this class defines implicit conversions to ArrayView. An alternative design would be to have Array derive from ArrayView. This is a workable design but it would impart some extra storage and runtime overhead. Perhaps the most significant overhead would be having the reset the base ArrayView pointer and size on each and every change in the structure of the container. This would import extra overhead beyond a straight std::vector.
The big advantage of deriving Array from ArrayView is that this would allow Array to be used to call some functions taking ArrayView without requiring an implicit conversion. While the implicit shallow conversion from Array to ArrayView is very cheap (just a pointer and int copy), it does cause problems where the compiler will refuse to perform an implicit conversion to call a templated function. However, note that an implicit conversion to an ArrayView<const T> would always have to be performed no matter what.
In summary, having Array implicitly convert to ArrayView instead of having Array derive from ArrayView results in faster and simpler code at the expense of the compiler refusing the make implicit conversions in some cases when calling template functions. Such conversion problems can always be dealt with by using explicit template arguments.
Definition at line 72 of file Teuchos_Array.hpp.
typedef Teuchos_Ordinal Teuchos::Array< T >::Ordinal |
The type of indices.
Definition at line 235 of file Teuchos_Array.hpp.
typedef Ordinal Teuchos::Array< T >::size_type |
The type of Array sizes and capacities.
Definition at line 237 of file Teuchos_Array.hpp.
typedef Ordinal Teuchos::Array< T >::difference_type |
The type of the difference between two size_type values.
Definition at line 239 of file Teuchos_Array.hpp.
typedef std::vector<T>::value_type Teuchos::Array< T >::value_type |
The type of an entry of the Array; for compatibility with std::vector.
Definition at line 241 of file Teuchos_Array.hpp.
typedef std::vector<T>::pointer Teuchos::Array< T >::pointer |
The type of a pointer to T; for compatibility with std::vector.
Definition at line 243 of file Teuchos_Array.hpp.
typedef std::vector<T>::const_pointer Teuchos::Array< T >::const_pointer |
The type of a const pointer to T; for compatibility with std::vector.
Definition at line 245 of file Teuchos_Array.hpp.
typedef std::vector<T>::reference Teuchos::Array< T >::reference |
The type of a reference to T; for compatibility with std::vector.
Definition at line 247 of file Teuchos_Array.hpp.
typedef std::vector<T>::const_reference Teuchos::Array< T >::const_reference |
The type of a const reference to T; for compatibility with std::vector.
Definition at line 249 of file Teuchos_Array.hpp.
typedef std::vector<T>::allocator_type Teuchos::Array< T >::allocator_type |
The allocator type; for compatibility with std::vector.
Definition at line 251 of file Teuchos_Array.hpp.
typedef std::vector<T>::iterator Teuchos::Array< T >::iterator |
The type of a forward iterator.
Definition at line 264 of file Teuchos_Array.hpp.
typedef std::vector<T>::const_iterator Teuchos::Array< T >::const_iterator |
The type of a const forward iterator.
Definition at line 266 of file Teuchos_Array.hpp.
typedef std::vector<T>::reverse_iterator Teuchos::Array< T >::reverse_iterator |
The type of a reverse iterator.
Definition at line 268 of file Teuchos_Array.hpp.
typedef std::vector<T>::const_reverse_iterator Teuchos::Array< T >::const_reverse_iterator |
The type of a const reverse iterator.
Definition at line 270 of file Teuchos_Array.hpp.
|
inline |
Default constructor; creates an empty Array.
Definition at line 799 of file Teuchos_Array.hpp.
|
inlineexplicit |
Create an array of length n, and fill it with the given value.
Definition at line 807 of file Teuchos_Array.hpp.
|
inline |
Copy constructor (does a deep copy).
Definition at line 817 of file Teuchos_Array.hpp.
|
inline |
Create an array, and fill it with values from the given iterator range.
Definition at line 827 of file Teuchos_Array.hpp.
|
inline |
Create an Array which is a deep copy of the given ArrayView.
Definition at line 842 of file Teuchos_Array.hpp.
Copy constructor from the given Tuple.
Definition at line 854 of file Teuchos_Array.hpp.
|
inline |
Destructor.
Definition at line 837 of file Teuchos_Array.hpp.
|
inline |
Copy constructor from an std::vector (does a deep copy).
Definition at line 1402 of file Teuchos_Array.hpp.
|
inline |
Assignment operator (does a deep copy).
Definition at line 864 of file Teuchos_Array.hpp.
|
inline |
Definition at line 878 of file Teuchos_Array.hpp.
|
inline |
Definition at line 888 of file Teuchos_Array.hpp.
|
inline |
Definition at line 899 of file Teuchos_Array.hpp.
|
inline |
Definition at line 923 of file Teuchos_Array.hpp.
|
inline |
Definition at line 934 of file Teuchos_Array.hpp.
|
inline |
Definition at line 967 of file Teuchos_Array.hpp.
|
inline |
Definition at line 979 of file Teuchos_Array.hpp.
|
inline |
Definition at line 991 of file Teuchos_Array.hpp.
|
inline |
Definition at line 1003 of file Teuchos_Array.hpp.
|
inline |
Definition at line 1015 of file Teuchos_Array.hpp.
|
inline |
Definition at line 1027 of file Teuchos_Array.hpp.
|
inline |
Definition at line 1035 of file Teuchos_Array.hpp.
|
inline |
Definition at line 1043 of file Teuchos_Array.hpp.
|
inline |
Definition at line 1054 of file Teuchos_Array.hpp.
|
inline |
Definition at line 1061 of file Teuchos_Array.hpp.
|
inline |
Definition at line 1068 of file Teuchos_Array.hpp.
|
inline |
Definition at line 1079 of file Teuchos_Array.hpp.
|
inline |
Definition at line 1090 of file Teuchos_Array.hpp.
|
inline |
Definition at line 1101 of file Teuchos_Array.hpp.
|
inline |
Definition at line 1112 of file Teuchos_Array.hpp.
|
inline |
Definition at line 1123 of file Teuchos_Array.hpp.
|
inline |
Definition at line 1134 of file Teuchos_Array.hpp.
|
inline |
Definition at line 1145 of file Teuchos_Array.hpp.
|
inline |
Definition at line 1156 of file Teuchos_Array.hpp.
|
inline |
Definition at line 1166 of file Teuchos_Array.hpp.
|
inline |
Definition at line 1176 of file Teuchos_Array.hpp.
|
inline |
Definition at line 1202 of file Teuchos_Array.hpp.
|
inline |
Definition at line 1224 of file Teuchos_Array.hpp.
|
inline |
Definition at line 1239 of file Teuchos_Array.hpp.
|
inline |
Definition at line 1255 of file Teuchos_Array.hpp.
|
inline |
Definition at line 1279 of file Teuchos_Array.hpp.
|
inline |
Definition at line 1308 of file Teuchos_Array.hpp.
|
inline |
Definition at line 1318 of file Teuchos_Array.hpp.
|
inline |
Add a new entry at the end of the array.
Resize to allow space for the new entry.
Definition at line 1331 of file Teuchos_Array.hpp.
|
inline |
Remove the i-th element from the array, with optional boundschecking.
Definition at line 1339 of file Teuchos_Array.hpp.
|
inline |
Return number of elements in the array.
Equivalent to size(), but * included for backwards compatibility.
Definition at line 1350 of file Teuchos_Array.hpp.
|
inline |
Convert an Array to an std::string
Definition at line 1357 of file Teuchos_Array.hpp.
|
inlinestatic |
Return true if Array has been compiled with boundschecking on.
Definition at line 1364 of file Teuchos_Array.hpp.
|
inline |
Return a raw pointer to beginning of array or NULL if unsized.
Definition at line 1375 of file Teuchos_Array.hpp.
|
inline |
Return a raw pointer to beginning of array.
Same semantics as getRawPtr
(which see).
Definition at line 1381 of file Teuchos_Array.hpp.
|
inline |
Return a const raw pointer to beginning of array or NULL if unsized.
Definition at line 1387 of file Teuchos_Array.hpp.
|
inline |
Return a const raw pointer to beginning of array.
Same semantics as getRawPtr
(which see).
Definition at line 1393 of file Teuchos_Array.hpp.
|
inline |
Explicit copy conversion to an std::vector.
Definition at line 1412 of file Teuchos_Array.hpp.
|
inline |
Assignment operator for std::vector.
Definition at line 1422 of file Teuchos_Array.hpp.
|
inline |
Return non-const view of a contiguous range of elements.
<b>Preconditions:</b><ul>
0 <= offset && offset + size <= this->size()
Postconditions:
returnVal.size() == size
NOTE: A size==0
view of even an empty Array is allowed and returns a null
view.
Definition at line 1436 of file Teuchos_Array.hpp.
|
inline |
Return const view of a contiguous range of elements.
<b>Preconditions:</b><ul>
0 <= offset && offset + size <= this->size()
Postconditions:
returnVal.size() == size
NOTE: A size==0
view of even an empty Array is allowed and returns a null
view.
Definition at line 1450 of file Teuchos_Array.hpp.
|
inline |
Return a non-const view of a contiguous range of elements (calls view(offset,size)).
Definition at line 1467 of file Teuchos_Array.hpp.
|
inline |
Return a const view of a contiguous range of elements (calls view(offset,size)).
Definition at line 1474 of file Teuchos_Array.hpp.
|
inline |
Return an non-const ArrayView of *this.
NOTE: This will return a null ArrayView if this->size() == 0.
Definition at line 1481 of file Teuchos_Array.hpp.
|
inline |
Return an const ArrayView of *this.
NOTE: This will return a null ArrayView if this->size() == 0.
Definition at line 1490 of file Teuchos_Array.hpp.
|
inline |
Perform an implicit conversion to a non-const ArrayView (calls operator()()).
Definition at line 1499 of file Teuchos_Array.hpp.
|
inline |
Perform an implicit conversion to a non-const ArrayView (calls operator()()).
Definition at line 1506 of file Teuchos_Array.hpp.
|
inlineprivate |
Definition at line 1517 of file Teuchos_Array.hpp.
|
inlineprivate |
Definition at line 1544 of file Teuchos_Array.hpp.
|
inlineprivate |
Definition at line 1556 of file Teuchos_Array.hpp.
|
inlineprivate |
Definition at line 1576 of file Teuchos_Array.hpp.
|
inlineprivate |
Definition at line 1586 of file Teuchos_Array.hpp.
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
Equality operator.
Non-equality operator.
Non-member swap (specializes default std version).
Less-than operator.
Less-than-or-equal operator.
Greater-than operator.
Greater-than-or-equal operator.
|
related |
|
related |
Return the hash code.
|
related |
Copy conversion to an std::vector.
This function is included for consistency with ArrayView.
|
related |
Convert an array to a string representation.
|
related |
Converts from std::string representation (as created by toString()
) back into the array object.
arrayStr | [in] The std::string representation of the array (see below). |
Exceptions: If the std::string representation is not valid, then an std::exception of type InvalidArrayStringRepresentation
with be thrown with a decent error message attached.
The formating of the std::string arrayStr
must look like:
{ val[0], val[1], val[2], val[3], ..., val[n-1] }
Currently operator>>()
is used to convert the entries from their std::string representation to objects of type T
. White space is unimportant and the parser keys off of ',', '{' and '}' so even newlines are allowed. In the future, a traits class might be defined that will allow for finer-grained control of how the conversion from strings to values is performed in cases where operator>>()
does not exist for certain types.
Warning! Currently this function only supports reading in flat array objects for basic types like bool
, int
, and double
and does not yet support nested arrays (i.e. no Array<Array<int> >
) or other such fancy nested types. Support for nested arrays and other user defined types T
can be added in the future with no impact on user code. Only the parser for the array needs to be improved. More specifically, the current implementation will not work for any types T
who's std::string representation contains the characters ','
or '}'
. This implementation can be modified to allow any such types by watching for the nesting of common enclosing structures like [...]
, {...}
or (...)
within each entry of the std::string representation. However, this should all just work fine on most machines for the types int
, bool
, float
, double
etc.
Warning! Trying to read in an array in std::string format of doubles in scientific notation such as {1e+2,3.53+6,...}
into an array object such as Array<int>
will not yield the correct results. If one wants to allow a neutral std::string representation to be read in as an Array<double>
object or an Array<int>
object, then general formating such as {100,3530000,...}
should be used. This templated function is unable to deal std::complex type conversion issues.
|
related |
A wrapper around the fromStringToArray
function which allows the operator>> to be used on Arrays.
Definition at line 707 of file Teuchos_Array.hpp.
|
related |
Extracts data from an istringstream object.
fromStringToArray
function.Definition at line 718 of file Teuchos_Array.hpp.
|
related |
Extracts std::string data from an istringstream object.
extractDataFromISS
function and is necessary for the proper extraction of std::string objects by the fromStringToArray
function.Definition at line 730 of file Teuchos_Array.hpp.
|
related |
Get the format that is used for the specialization of the TypeName traits class for Array.
The string returned will contain only one "*" character. The "*" character should then be replaced with the actual template type of the array.
Definition at line 748 of file Teuchos_Array.hpp.
|
private |
Definition at line 515 of file Teuchos_Array.hpp.