Array< 1, T, A > Class Template Reference

A 1-D array of type T. More...

#include <Array1.h>

Inheritance diagram for Array< 1, T, A >:
ArrayContainer< T, A > ArrayIndexing< 1, T > ArrayIndexingBase< 1 >

List of all members.

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)
Arrayoperator= (const Array &other)
 Assignment operator.
template<typename T2 , bool A2>
Arrayoperator= (const Array< 1, T2, A2 > &x)
 Assignment operator for an array of different type or allocation policy.
template<int N2, typename T2 , bool A2>
Arrayoperator= (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.

Convert a single index to a multi-index in a 1-D array.

Precondition:
This must be a 1-D array.
size_type getMemoryUsage () const
 Return the memory size in bytes.
Manipulators.

Return the root for indexing.

Return a reference to the element. Return a reference to the element.

This performs indexing into the array. The index i must be in the range [ lbound() .. ubound()). This is different than the container indexing performed in ArrayContainer::operator[].

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.

Arrayoperator= (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

Detailed Description

template<typename T, bool A>
class Array< 1, T, A >

A 1-D array of type T.

Parameters:
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();

Member Typedef Documentation

template<typename T , bool A>
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 >.

template<typename T , bool A>
typedef types::size_type Array< 1, T, A >::size_type

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 >.

template<typename T , bool 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 >.

template<typename T , bool 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*.


Constructor & Destructor Documentation

template<typename T , bool A>
Array< 1, T, A >::Array ( const Array< 1, T, A > &  x  )  [inline]

Copy constructor.

If A is true, allocate memory and copy the elements. Otherwise, reference the data in x.

template<typename T , bool A>
template<typename T2 , bool A2>
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.

template<typename T , bool A>
template<int N2, typename T2 , bool A2>
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.

template<typename T , bool A>
template<typename ForwardIterator >
Array< 1, T, A >::Array ( ForwardIterator  first,
ForwardIterator  last 
) [inline]

Construct from a range of values.

Parameters:
first points to the beginning of the range.
last points to the end of the range, (one past the last element).
template<typename T , bool A>
template<typename InputIterator >
Array< 1, T, A >::Array ( const size_type  size,
InputIterator  first,
InputIterator  last 
) [inline, explicit]

Construct the array extent and a range of values.

Parameters:
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).
template<typename T , bool A>
template<typename InputIterator >
Array< 1, T, A >::Array ( const index_type extent,
InputIterator  first,
InputIterator  last 
) [inline, explicit]

Construct the array extent and a range of values.

Parameters:
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).
template<typename T , bool A>
template<typename InputIterator >
Array< 1, T, A >::Array ( const range_type range,
InputIterator  first,
InputIterator  last 
) [inline, explicit]

Construct from a range of values.

Parameters:
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).
template<typename T , bool A>
Array< 1, T, A >::Array ( const size_type  size,
const void_pointer  data 
) [inline]

Construct from size and a pointer to data.

Parameters:
size is the size of the array.
data points to an array.
template<typename T , bool A>
Array< 1, T, A >::Array ( const range_type range,
const void_pointer  data 
) [inline]

Construct from a range and a pointer to data.

Parameters:
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.


Member Function Documentation

template<typename T , bool A>
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.

template<typename T , bool A>
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.

template<typename T , bool A>
size_type Array< 1, T, A >::getMemoryUsage (  )  const [inline]

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().

template<typename T , bool A>
template<int N2, typename T2 , bool A2>
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().

template<typename T , bool A>
template<typename T2 , bool A2>
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().

template<typename T , bool A>
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().

template<typename T , bool A>
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.

template<typename T , bool A>
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.

template<typename T , bool A>
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().

template<typename T , bool A>
template<typename ForwardIterator >
void Array< 1, T, A >::rebuild ( ForwardIterator  first,
ForwardIterator  last 
) [inline]

Rebuild from a range of values.

Parameters:
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().

template<typename T , bool A>
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.

template<typename T , bool A>
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().

template<typename T , bool A>
void Array< 1, T, A >::resize ( const size_type  size  ) 

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 >.

template<typename T , bool 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().


The documentation for this class was generated from the following file:
Generated on Thu Jun 30 02:14:51 2016 for Algorithms and Data Structures Package by  doxygen 1.6.3