A 1-D array of type T. More...
#include <Array1.h>
Public Types | |
typedef types::value_type | value_type |
The element type of the array. | |
typedef types::parameter_type | parameter_type |
The parameter type. | |
typedef types::unqualified_value_type | unqualified_value_type |
The unqualified value type. | |
typedef types::pointer | pointer |
A pointer to an array element. | |
typedef types::const_pointer | const_pointer |
A const pointer to an array element. | |
typedef types::iterator | iterator |
An iterator in the array. | |
typedef types::const_iterator | const_iterator |
A const iterator in the array. | |
typedef types::reference | reference |
A reference to an array element. | |
typedef types::const_reference | const_reference |
A const reference to an array element. | |
typedef types::size_type | size_type |
The size type is a signed integer. | |
typedef types::difference_type | difference_type |
Pointer difference type. | |
typedef Loki::Select< A||Loki::TypeTraits < value_type >::isConst, const void *, void * >::Result | void_pointer |
A void pointer. | |
typedef indexing_base::index_type | index_type |
An index into the array. | |
typedef indexing_base::range_type | range_type |
A range of multi-indices. | |
Public Member Functions | |
void | get (std::istream &in, Loki::Int2Type< true >) |
Read from a file stream in ascii format. | |
void | get (std::istream &in, Loki::Int2Type< false >) |
Read from a file stream in ascii format. | |
void | read (std::istream &in, Loki::Int2Type< true >) |
Read from a file stream in binary format. | |
void | read (std::istream &in, Loki::Int2Type< false >) |
Read from a file stream in binary format. | |
Constructors etc. | |
Array () | |
Default constructor. | |
Array (const Array &x) | |
Copy constructor. | |
template<typename T2 , bool A2> | |
Array (const Array< 1, T2, A2 > &x) | |
template<int N2, typename T2 , bool A2> | |
Array (const Array< N2, T2, A2 > &x) | |
Array & | operator= (const Array &other) |
Assignment operator. | |
template<typename T2 , bool A2> | |
Array & | operator= (const Array< 1, T2, A2 > &x) |
Assignment operator for an array of different type or allocation policy. | |
template<int N2, typename T2 , bool A2> | |
Array & | operator= (const Array< N2, T2, A2 > &x) |
Assignment operator for an array of different rank, type, or allocation policy. | |
Array (const size_type size) | |
Construct a given size array. Leave the elements uninitialized. | |
Array (const size_type size, parameter_type value) | |
Construct an array of the given size , and initialized to value . | |
template<typename ForwardIterator > | |
Array (ForwardIterator first, ForwardIterator last) | |
Construct from a range of values. | |
template<typename ForwardIterator > | |
void | rebuild (ForwardIterator first, ForwardIterator last) |
Rebuild from a range of values. | |
template<typename InputIterator > | |
Array (const size_type size, InputIterator first, InputIterator last) | |
Construct the array extent and a range of values. | |
Array (const index_type &extent) | |
Construct from array extent. Leave the elements uninitialized. | |
Array (const index_type &extent, parameter_type value) | |
Construct from array extent and an initial value. | |
template<typename InputIterator > | |
Array (const index_type &extent, InputIterator first, InputIterator last) | |
Construct the array extent and a range of values. | |
Array (const range_type &range) | |
Construct an array over the given index range . | |
Array (const range_type &range, parameter_type value) | |
Construct an array over the range , and initialized to value . | |
template<typename InputIterator > | |
Array (const range_type &range, InputIterator first, InputIterator last) | |
Construct from a range of values. | |
Array (const size_type size, const void_pointer data) | |
Construct from size and a pointer to data. | |
Array (const range_type &range, const void_pointer data) | |
Construct from a range and a pointer to data. | |
~Array () | |
Destructor. Delete memory if it was allocated. | |
Accesors: Memory. | |
size_type | getMemoryUsage () const |
Return the memory size in bytes. | |
Manipulators. | |
Return a reference to the element. Return a reference to the element. This performs indexing into the array. The index | |
void | swap (Array &x) |
Swaps data with another Array. | |
void | resize (const size_type size) |
Resize the array to the specified size . | |
void | resize (const index_type &extent) |
Resize the array to the specified extent . | |
void | resize (const range_type &range) |
Resize the array to cover the specified range . | |
Assignment operators with scalar operand. | |
Array & | operator= (parameter_type x) |
Set each component to x . | |
File I/O | |
void | put (std::ostream &out) const |
Write the array to a file stream in ascii format. | |
void | get (std::istream &in) |
Read from a file stream in ascii format. | |
void | write (std::ostream &out) const |
Write to a file stream in binary format. | |
void | read (std::istream &in) |
Read from a file stream in binary format. | |
void | write_elements_ascii (std::ostream &out) const |
Write the elements in ascii format. Do not write the array size. | |
void | write_elements_binary (std::ostream &out) const |
Write the elements in binary format. Do not write the array size. | |
void | read_elements_ascii (std::istream &in) |
Read the elements in ascii format. Do not read the array size. | |
void | read_elements_binary (std::istream &in) |
Read the elements in binary format. Do not read the array size. | |
Equality. | |
template<typename T2 , bool A2> | |
bool | operator== (const Array< 1, T2, A2 > &x) const |
A 1-D array of type T.
T | is the value type of the array. By default it is double. | |
A | determines whether the array will allocate memory for the elements or use externally allocated memory. By default A is true. |
Equality Tests
Test the equality of Array's with operator==(const Array<T1>& a, const Array<T2>& b) and operator!=(const Array<T1>& a, const Array<T2>& b). The arrays are equal if and only if they have the same index ranges and the same element values. There are also operators for comparing different kinds of 1-D arrays and for comparing 1-D arrays to multi-arrays.
File I/O
The file format for all 1-D arrays is:
lbound ubound element_0 element_1 element_2 ...
Array inherits file output capability from Array via Array<T>::write(std::ostream& out)
for binary output and operator<<(std::ostream& out, const Array<T>& x) for ascii output.
Read from a file stream in binary format with read(std::istream& in) and in ascii format with operator>>(std::istream& in, Array<T>& x).
// Make an array. ads::Array<> a(10, 42); // Write the array to "array.txt" in ascii format. std::ofstream out("array.txt"); out << a; out.close(); // Read an array from "array.txt" in ascii format. std::ifstream in("array.txt"); ads::Array<> x; in >> x; in.close();
// Make an array. ads::Array<> a(10, 42); // Write the array to "array.bin" in binary format. std::ofstream out("array.bin"); a.write(out); out.close(); // Read an array from "array.bin" in binary format. std::ifstream in("array.bin"); ads::Array<> x; x.read(in); in.close();
typedef types::parameter_type Array< 1, T, A >::parameter_type |
The parameter type.
This is used for passing the value type as an argument.
Reimplemented from ArrayContainer< T, A >.
The size type is a signed integer.
Having std::size_t
(which is an unsigned integer) as the size type causes minor problems. Consult "Large Scale C++ Software Design" by John Lakos for a discussion of using unsigned integers in a class interface.
Reimplemented from ArrayContainer< T, A >.
typedef types::unqualified_value_type Array< 1, T, A >::unqualified_value_type |
The unqualified value type.
The value type with top level const
and volatile
qualifiers removed.
Reimplemented from ArrayContainer< T, A >.
typedef Loki::Select< A || Loki::TypeTraits<value_type>::isConst, const void*, void* >::Result Array< 1, T, A >::void_pointer |
A void pointer.
If we allocate our own memory or if the value type has a top level const qualifier, this is const void*
. Otherwise it is void*
.
Copy constructor.
If A
is true, allocate memory and copy the elements. Otherwise, reference the data in x
.
Array< 1, T, A >::Array | ( | const Array< 1, T2, A2 > & | x | ) | [inline] |
If A
is true, allocate memory and copy the elements. Otherwise, reference the data in x
.
Array< 1, T, A >::Array | ( | const Array< N2, T2, A2 > & | x | ) | [inline] |
If A
is true, allocate memory and copy the elements. Otherwise, reference the data in x
.
Array< 1, T, A >::Array | ( | ForwardIterator | first, | |
ForwardIterator | last | |||
) | [inline] |
Construct from a range of values.
first | points to the beginning of the range. | |
last | points to the end of the range, (one past the last element). |
Array< 1, T, A >::Array | ( | const size_type | size, | |
InputIterator | first, | |||
InputIterator | last | |||
) | [inline, explicit] |
Construct the array extent and a range of values.
size | is the number of array elements. | |
first | points to the beginning of the range. | |
last | points to the end of the range, (one past the last element). |
Array< 1, T, A >::Array | ( | const index_type & | extent, | |
InputIterator | first, | |||
InputIterator | last | |||
) | [inline, explicit] |
Construct the array extent and a range of values.
extent | is the array extent. | |
first | points to the beginning of the range. | |
last | points to the end of the range, (one past the last element). |
Array< 1, T, A >::Array | ( | const range_type & | range, | |
InputIterator | first, | |||
InputIterator | last | |||
) | [inline, explicit] |
Construct from a range of values.
range | is the index range of the array. | |
first | points to the beginning of the range. | |
last | points to the end of the range, (one past the last element). |
Array< 1, T, A >::Array | ( | const size_type | size, | |
const void_pointer | data | |||
) | [inline] |
Construct from size and a pointer to data.
size | is the size of the array. | |
data | points to an array. |
Array< 1, T, A >::Array | ( | const range_type & | range, | |
const void_pointer | data | |||
) | [inline] |
Construct from a range and a pointer to data.
range | in the index range. | |
data | points to an array. |
No memory is allocated, this array adopts the data. Thus the data must not be deleted before this array.
void Array< 1, T, A >::get | ( | std::istream & | in, | |
Loki::Int2Type< false > | ||||
) |
Read from a file stream in ascii format.
The array must be the correct size.
void Array< 1, T, A >::get | ( | std::istream & | in, | |
Loki::Int2Type< true > | ||||
) |
Read from a file stream in ascii format.
Resize the array if necessary.
Return the memory size in bytes.
Count the array memory whether we allocated it or not.
Reimplemented from ArrayContainer< T, A >.
References ArrayContainer< T, A >::size().
Array& Array< 1, T, A >::operator= | ( | const Array< N2, T2, A2 > & | x | ) | [inline] |
Assignment operator for an array of different rank, type, or allocation policy.
If A
is true, allocate memory and copy the elements. Otherwise, reference the data in x
.
References ArrayContainer< T, A >::data(), ArrayContainer< T, A >::operator=(), ArrayIndexing< N, T >::rebuild(), and ArrayContainer< T, A >::size().
Array& Array< 1, T, A >::operator= | ( | const Array< 1, T2, A2 > & | x | ) | [inline] |
Assignment operator for an array of different type or allocation policy.
If A
is true, allocate memory and copy the elements. Otherwise, reference the data in x
.
References ArrayContainer< T, A >::data(), ArrayContainer< T, A >::operator=(), and ArrayIndexing< N, T >::rebuild().
Array& Array< 1, T, A >::operator= | ( | const Array< 1, T, A > & | other | ) | [inline] |
Assignment operator.
If A
is true, allocate memory and copy the elements. Otherwise, reference the data in x
.
References ArrayContainer< T, A >::data(), ArrayContainer< T, A >::operator=(), and ArrayIndexing< N, T >::rebuild().
void Array< 1, T, A >::read | ( | std::istream & | in, | |
Loki::Int2Type< false > | ||||
) |
Read from a file stream in binary format.
The array must be the correct size.
void Array< 1, T, A >::read | ( | std::istream & | in, | |
Loki::Int2Type< true > | ||||
) |
Read from a file stream in binary format.
Resize the array if necessary.
void Array< 1, T, A >::read | ( | std::istream & | in | ) | [inline] |
Read from a file stream in binary format.
File format:
lbound ubound element_0 element_1 element_2 ...
Reimplemented from ArrayContainer< T, A >.
References Array< N, T, A >::read().
void Array< 1, T, A >::rebuild | ( | ForwardIterator | first, | |
ForwardIterator | last | |||
) | [inline] |
Rebuild from a range of values.
first | points to the beginning of the range. | |
last | points to the end of the range, (one past the last element). |
Reimplemented from ArrayContainer< T, A >.
References ArrayContainer< T, A >::data(), ArrayIndexing< N, T >::rebuild(), ArrayContainer< T, A >::rebuild(), and ArrayContainer< T, A >::size().
void Array< 1, T, A >::resize | ( | const range_type & | range | ) |
Resize the array to cover the specified range
.
If the array alread has the specified range
, then this function has no effect. If the array's size is equal to range.exent()
, the the index range of the array changed, but the elements remain the same. Otherwise, the index range is changed and the elements are left uninitialized.
void Array< 1, T, A >::resize | ( | const index_type & | extent | ) | [inline] |
Resize the array to the specified extent
.
If the array already has the specified extent
, then this function has no effect. Otherwise, the array is resized to have the index range [0..extent) and the elements are left uninitialized.
References Array< N, T, A >::resize().
Resize the array to the specified size
.
If the array already has the specified size
, then this function has no effect. Otherwise, the array is resized to have the index range [0..size) and the elements are left uninitialized.
Reimplemented from ArrayContainer< T, A >.
void Array< 1, T, A >::write | ( | std::ostream & | out | ) | const [inline] |
Write to a file stream in binary format.
File format:
lbound ubound element_0 element_1 element_2 ...
Reimplemented from ArrayContainer< T, A >.
References ArrayContainer< T, A >::write(), and ArrayIndexing< N, T >::write().