dlr::numeric::Array1D< Type > Class Template Reference

The Array1D class template represents a 1D array of arbitrary type. More...

#include <array1D.h>

Inheritance diagram for dlr::numeric::Array1D< Type >:
[legend]
Collaboration diagram for dlr::numeric::Array1D< Type >:
[legend]

List of all members.

Public Types

typedef Type value_type
 Typedef for value_type describes the contents of the array.
typedef Type * iterator
 Typedef for iterator type helps with standard library interface.
typedef const Type * const_iterator
 Typedef for const_iterator type helps with standard library interface.

Public Member Functions

 Array1D ()
 Default constructor initializes to zero size.
 Array1D (size_t arraySize)
 Constructs an "arraySize" element array.
 Array1D (const std::string &inputString)
 Constructs an Array1D by parsing an input string.
 Array1D (const Array1D< Type > &source)
 The copy constructor does a shallow copy.
 Array1D (size_t arraySize, Type *const dataPtr)
 Construct an array around external data.
 Array1D (size_t arraySize, Type *const dataPtr, size_t *const referenceCountPtr)
 Construct an array around external data which was allocated by an Array?D instance.
 ~Array1D ()
 Destroys the Array1D instance and deletes the internal data store if no remaining arrays point to it.
iterator begin ()
 Return begin() iterator for Standard Library algorithms.
const_iterator begin () const
 Return begin() const_iterator for Standard Library algorithms.
void checkDimension (size_t arraySize) const
 Optionally throw an exception if the shape of *this is different than specified.
void clear ()
 Reset the array to zero size, abandoning all contents.
Array1D< Type > copy () const
 Allocate a new array and deep copy the contents of *this.
template<class Type2 >
void copy (const Array1D< Type2 > &source)
 Deep copies the contents of source.
template<class Type2 >
void copy (const Type2 *dataPtr)
 Copies elements from dataPtr.
Type * data ()
 Returns a pointer to the internal data store.
const Type * data () const
 This version of data(void) is appropriate for const Array1D, and returns a pointer-to-const.
Type * data (size_t index)
 Just like data(void), which is documented above, but returns a pointer to the (index)th element instead of the first element.
const Type * data (size_t index) const
 This version of data(size_t) is appropriate for const Array1D, and returns a pointer-to-const.
bool empty () const
 This member function returns true if the array instance contains no elements.
iterator end ()
 Return end() iterator for Standard Library algorithms.
const_iterator end () const
 Return end() const_iterator for Standard Library algorithms.
Type getElement (size_t index0) const
 This member function returns a specific element of the array by value.
bool isAllocated () const
 Indicates whether the internal data array is being managed (and reference counted) by *this.
size_t length () const
 Returns the number of elements in the array.
std::istream & readFromStream (std::istream &inputStream)
 This member function sets the value of the array from an input stream.
size_t * refCountPtr () const
 Temporary function to ease porting of code from early versions of dlr_libs.
void reinit (size_t arraySize)
 Changes the shape of the array and reallocates storage.
void reinitIfNecessary (size_t arraySize)
 Behaves just like member function reinit() unless this->size() matches the requested size, in which case this member function does nothing.
Type & setElement (size_t index0, const Type &value)
 This member function sets the value of a specific element of the array.
size_t size () const
 Returns the number of elements in the array.
Array1D< Type > & operator= (const Array1D< Type > &source)
 Assignment operator shallow copies the contents of source.
Array1D< Type > & operator= (Type value)
 Assign value to every element in the array.
Type & operator() (size_t index)
 Returns the (index)th element of the array by reference.
Type operator() (size_t index) const
 Returns the (index)th element of the array by value.
Type & operator[] (size_t index)
 Returns the (index)th element of the array by reference.
Type operator[] (size_t index) const
 Returns the (index)th element of the array by value.
template<class Type2 >
Array1D< Type > & operator+= (const Array1D< Type2 > &arg)
 Increments each element of *this by the value of the corresponding element of arg.
Array1D< Type > & operator+= (const Type arg)
 Increments each element of *this by a constant.
template<class Type2 >
Array1D< Type > & operator-= (const Array1D< Type2 > &arg)
 Decrements each element of *this by the value of the corresponding element of arg.
Array1D< Type > & operator-= (const Type arg)
 Decrements each element of *this by a constant.
template<class Type2 >
Array1D< Type > & operator*= (const Array1D< Type2 > &arg)
 Multiplies each element of *this by the value of the corresponding element of arg.
Array1D< Type > & operator*= (const Type arg)
 Multiplies each element of *this by a constant.
template<class Type2 >
Array1D< Type > & operator/= (const Array1D< Type2 > &arg)
 Divides each element of *this by the value of the corresponding element of arg.
Array1D< Type > & operator/= (const Type arg)
 Divides each element of *this by a constant.


Detailed Description

template<class Type>
class dlr::numeric::Array1D< Type >

The Array1D class template represents a 1D array of arbitrary type.

This class has internal reference counting.

IMPORTANT: This class does _shallow_ copies by default. If you type:

array1 = array2;

then array1 and array2 point to the same data. To do a deep copy, type

array1.copy(array2);

or

array1 = array2.copy();

The advantage of the first form is that it doesn't involve allocating memory. The advantage of the second form is that there's no error if array1 and array2 have different shapes/sizes.

Definition at line 55 of file array1D.h.


Member Typedef Documentation

template<class Type>
typedef const Type* dlr::numeric::Array1D< Type >::const_iterator

Typedef for const_iterator type helps with standard library interface.

Definition at line 73 of file array1D.h.

template<class Type>
typedef Type* dlr::numeric::Array1D< Type >::iterator

Typedef for iterator type helps with standard library interface.

Definition at line 67 of file array1D.h.

template<class Type>
typedef Type dlr::numeric::Array1D< Type >::value_type

Typedef for value_type describes the contents of the array.

Definition at line 62 of file array1D.h.


Constructor & Destructor Documentation

template<class Type >
dlr::numeric::Array1D< Type >::Array1D (  )  [inline]

Default constructor initializes to zero size.

Definition at line 1012 of file array1D.h.

template<class Type >
dlr::numeric::Array1D< Type >::Array1D ( size_t  arraySize  )  [inline, explicit]

Constructs an "arraySize" element array.

Parameters:
arraySize Number of elements in the array after successful construction.

Definition at line 1024 of file array1D.h.

template<class Type >
dlr::numeric::Array1D< Type >::Array1D ( const std::string &  inputString  )  [inline, explicit]

Constructs an Array1D by parsing an input string.

For example, the code line

Array1D<double> testArray("[1.0, 2.0, 3.0]");

would construct a 3 element array.

Parameters:
inputString A formatted string which could be reasonably expected to parse into the desired array values.

Definition at line 1037 of file array1D.h.

template<class Type>
dlr::numeric::Array1D< Type >::Array1D ( const Array1D< Type > &  source  )  [inline]

The copy constructor does a shallow copy.

The newly created array points to the same data as copied array.

Parameters:
source The Array1D<> instance to be copied.

Definition at line 1066 of file array1D.h.

template<class Type>
dlr::numeric::Array1D< Type >::Array1D ( size_t  arraySize,
Type *const   dataPtr 
) [inline]

Construct an array around external data.

Arrays constructed in this way will not implement reference counting, and will not delete dataPtr when done.

Parameters:
arraySize Number of elements in the array after construction.
dataPtr A C-style array of Type into which the newly constructed Array1D should index.

Definition at line 1080 of file array1D.h.

template<class Type>
dlr::numeric::Array1D< Type >::Array1D ( size_t  arraySize,
Type *const   dataPtr,
size_t *const   referenceCountPtr 
) [inline]

Construct an array around external data which was allocated by an Array?D instance.

Arrays constructed in this way _do_ implement reference counting, and will delete dataPtr when done. This constructor is provided primarily so that higher dimensionality array classes can return Array1D instances which reference their data without being friend classes. Caveat emptor.

Parameters:
arraySize Number of elements in the array after construction.
dataPtr A C-style array of Type into which the newly constructed Array1D should index.
referenceCountPtr Pointer to size_t indicating the number of Array classes currently using dataPtr.

Definition at line 1092 of file array1D.h.

template<class Type >
dlr::numeric::Array1D< Type >::~Array1D (  )  [inline]

Destroys the Array1D instance and deletes the internal data store if no remaining arrays point to it.

Definition at line 1104 of file array1D.h.


Member Function Documentation

template<class Type>
const_iterator dlr::numeric::Array1D< Type >::begin (  )  const [inline]

Return begin() const_iterator for Standard Library algorithms.

Returns:
Const iterator pointing to the first element of the array.

Definition at line 166 of file array1D.h.

template<class Type>
iterator dlr::numeric::Array1D< Type >::begin (  )  [inline]

template<class Type >
void dlr::numeric::Array1D< Type >::checkDimension ( size_t  arraySize  )  const [inline]

Optionally throw an exception if the shape of *this is different than specified.

Parameters:
arraySize The required array size.

Definition at line 1112 of file array1D.h.

References dlr::numeric::Array1D< Type >::size().

Referenced by dlr::numeric::operator==().

template<class Type>
void dlr::numeric::Array1D< Type >::clear (  )  [inline]

Reset the array to zero size, abandoning all contents.

This is equivalent to this->reinit(0);

Definition at line 184 of file array1D.h.

Referenced by dlr::numeric::Array2D< Type >::readFromStream().

template<class Type >
template<class Type2 >
void dlr::numeric::Array1D< Type >::copy ( const Type2 *  dataPtr  )  [inline]

Copies elements from dataPtr.

There must be valid data at all addresses from dataPtr to (dataPtr + this->size());

Parameters:
dataPtr Pointer to the data to be copied.

Definition at line 1157 of file array1D.h.

References dlr::numeric::Array1D< Type >::copy().

template<class Type >
template<class Type2 >
void dlr::numeric::Array1D< Type >::copy ( const Array1D< Type2 > &  source  )  [inline]

Deep copies the contents of source.

It is an error if source does not have the same size as *this.

Parameters:
source The array to be copied.
Exceptions:
ValueException on incompatible array sizes
See also:
void Array1D<Type>::copy(const Type2* dataPtr)

Definition at line 1138 of file array1D.h.

References dlr::numeric::Array1D< Type >::copy(), dlr::numeric::Array1D< Type >::data(), and dlr::numeric::Array1D< Type >::size().

template<class Type >
Array1D< Type > dlr::numeric::Array1D< Type >::copy (  )  const [inline]

template<class Type>
const Type* dlr::numeric::Array1D< Type >::data ( size_t  index  )  const [inline]

This version of data(size_t) is appropriate for const Array1D, and returns a pointer-to-const.

Parameters:
index Indicates to which element of the array the return value should point.
Returns:
Const pointer to the (index)th element of the array.

Definition at line 261 of file array1D.h.

template<class Type>
Type* dlr::numeric::Array1D< Type >::data ( size_t  index  )  [inline]

Just like data(void), which is documented above, but returns a pointer to the (index)th element instead of the first element.

Note that "data(index)" is synonymous with "data() + index" .

Parameters:
index Indicates to which element of the array the return value should point.
Returns:
Pointer to the (index)th element of the array.

Definition at line 246 of file array1D.h.

template<class Type>
const Type* dlr::numeric::Array1D< Type >::data ( void   )  const [inline]

This version of data(void) is appropriate for const Array1D, and returns a pointer-to-const.

Returns:
Const pointer to the internal data store.

Definition at line 233 of file array1D.h.

template<class Type>
Type* dlr::numeric::Array1D< Type >::data ( void   )  [inline]

Returns a pointer to the internal data store.

This is ugly but often necessary for interfacing with external libraries. Data is stored contiguously.

Returns:
Pointer to the internal data store.

Definition at line 224 of file array1D.h.

Referenced by dlr::numeric::Array1D< Type >::copy(), dlr::numeric::Array1D< Type >::operator*=(), dlr::numeric::Array1D< Type >::operator+=(), dlr::numeric::Array1D< Type >::operator-=(), and dlr::numeric::Array1D< Type >::operator/=().

template<class Type>
bool dlr::numeric::Array1D< Type >::empty (  )  const [inline]

This member function returns true if the array instance contains no elements.

It has complexity O(1).

Returns:
The return value indicates whether or not the array is empty.

Definition at line 275 of file array1D.h.

template<class Type>
const_iterator dlr::numeric::Array1D< Type >::end (  )  const [inline]

Return end() const_iterator for Standard Library algorithms.

Returns:
Const iterator pointing just past the last element of the array.

Definition at line 294 of file array1D.h.

template<class Type>
iterator dlr::numeric::Array1D< Type >::end (  )  [inline]

template<class Type>
Type dlr::numeric::Array1D< Type >::getElement ( size_t  index0  )  const [inline]

This member function returns a specific element of the array by value.

Parameters:
index0 This argument specifies which element value should be returned.
Returns:
The return value is a copy of the requested element.

Definition at line 307 of file array1D.h.

template<class Type>
bool dlr::numeric::Array1D< Type >::isAllocated (  )  const [inline]

Indicates whether the internal data array is being managed (and reference counted) by *this.

This member function is only needed in very unusual circumstances.

Returns:
The return value is a bool indicating whether the internal data is being managed by *this.

Definition at line 319 of file array1D.h.

template<class Type>
size_t dlr::numeric::Array1D< Type >::length (  )  const [inline]

Returns the number of elements in the array.

This is a synonym for size().

Returns:
The number of elements in the array.

Definition at line 328 of file array1D.h.

template<class Type>
Type dlr::numeric::Array1D< Type >::operator() ( size_t  index  )  const [inline]

Returns the (index)th element of the array by value.

Parameters:
index Indicates the selected element.
Returns:
Value of the (index)th element of the array.

Definition at line 446 of file array1D.h.

template<class Type>
Type& dlr::numeric::Array1D< Type >::operator() ( size_t  index  )  [inline]

Returns the (index)th element of the array by reference.

Parameters:
index Indicates the selected element.
Returns:
Reference to the (index)th element of the array.

Definition at line 434 of file array1D.h.

Referenced by dlr::numeric::Array1D< size_t >::getElement(), dlr::numeric::Array1D< size_t >::operator[](), and dlr::numeric::Array1D< size_t >::setElement().

template<class Type>
Array1D< Type > & dlr::numeric::Array1D< Type >::operator*= ( const Type  arg  )  [inline]

Multiplies each element of *this by a constant.

Parameters:
arg Value by which array elements will be multiplied.
Returns:
Reference to *this.

Definition at line 1375 of file array1D.h.

template<class Type >
template<class Type2 >
Array1D< Type > & dlr::numeric::Array1D< Type >::operator*= ( const Array1D< Type2 > &  arg  )  [inline]

Multiplies each element of *this by the value of the corresponding element of arg.

Parameters:
arg Array1D of values by which the elements of *this should be multiplied.
Exceptions:
ValueException on incompatible array sizes
Returns:
Reference to *this.

Definition at line 1356 of file array1D.h.

References dlr::numeric::Array1D< Type >::data(), and dlr::numeric::Array1D< Type >::size().

template<class Type>
Array1D< Type > & dlr::numeric::Array1D< Type >::operator+= ( const Type  arg  )  [inline]

Increments each element of *this by a constant.

Parameters:
arg Value by which array elements will be incremented.
Returns:
Reference to *this.

Definition at line 1315 of file array1D.h.

template<class Type >
template<class Type2 >
Array1D< Type > & dlr::numeric::Array1D< Type >::operator+= ( const Array1D< Type2 > &  arg  )  [inline]

Increments each element of *this by the value of the corresponding element of arg.

Parameters:
arg Array1D of values to be added to the elements of *this.
Exceptions:
ValueException on incompatible array sizes
Returns:
Reference to *this.

Definition at line 1296 of file array1D.h.

References dlr::numeric::Array1D< Type >::data(), and dlr::numeric::Array1D< Type >::size().

template<class Type>
Array1D< Type > & dlr::numeric::Array1D< Type >::operator-= ( const Type  arg  )  [inline]

Decrements each element of *this by a constant.

Parameters:
arg Value by which array elements will be decremented.
Returns:
Reference to *this.

Definition at line 1345 of file array1D.h.

template<class Type >
template<class Type2 >
Array1D< Type > & dlr::numeric::Array1D< Type >::operator-= ( const Array1D< Type2 > &  arg  )  [inline]

Decrements each element of *this by the value of the corresponding element of arg.

Parameters:
arg Array1D of values to be subtracted from the elements of *this.
Exceptions:
ValueException on incompatible array sizes
Returns:
Reference to *this.

Definition at line 1326 of file array1D.h.

References dlr::numeric::Array1D< Type >::data(), and dlr::numeric::Array1D< Type >::size().

template<class Type>
Array1D< Type > & dlr::numeric::Array1D< Type >::operator/= ( const Type  arg  )  [inline]

Divides each element of *this by a constant.

Parameters:
arg Value by which array elements will be divided.
Returns:
Reference to *this.

Definition at line 1405 of file array1D.h.

template<class Type >
template<class Type2 >
Array1D< Type > & dlr::numeric::Array1D< Type >::operator/= ( const Array1D< Type2 > &  arg  )  [inline]

Divides each element of *this by the value of the corresponding element of arg.

Parameters:
arg Array1D of values by which the elements of *this should be divided.
Exceptions:
ValueException on incompatible array sizes
Returns:
Reference to *this.

Definition at line 1386 of file array1D.h.

References dlr::numeric::Array1D< Type >::data(), and dlr::numeric::Array1D< Type >::size().

template<class Type>
Array1D< Type > & dlr::numeric::Array1D< Type >::operator= ( Type  value  )  [inline]

Assign value to every element in the array.

Parameters:
value The value to be copied.
Returns:
Reference to *this.

Definition at line 1165 of file array1D.h.

template<class Type>
Array1D< Type > & dlr::numeric::Array1D< Type >::operator= ( const Array1D< Type > &  source  )  [inline]

Assignment operator shallow copies the contents of source.

After the copy, both arrays reference the same data.

Parameters:
source The Array1D instance to be copied.
Returns:
Reference to *this.

Definition at line 1275 of file array1D.h.

References dlr::numeric::Array1D< Type >::m_dataPtr, dlr::numeric::Array1D< Type >::m_isAllocated, dlr::numeric::Array1D< Type >::m_refCountPtr, and dlr::numeric::Array1D< Type >::m_size.

template<class Type>
Type dlr::numeric::Array1D< Type >::operator[] ( size_t  index  )  const [inline]

Returns the (index)th element of the array by value.

Synonymous with operator()() const.

Parameters:
index Indicates the selected element.
Returns:
Value of the (index)th element of the array.

Definition at line 469 of file array1D.h.

template<class Type>
Type& dlr::numeric::Array1D< Type >::operator[] ( size_t  index  )  [inline]

Returns the (index)th element of the array by reference.

Synonymous with operator()().

Parameters:
index Indicates the selected element.
Returns:
Reference to the (index)th element of the array.

Definition at line 459 of file array1D.h.

template<class Type >
std::istream & dlr::numeric::Array1D< Type >::readFromStream ( std::istream &  inputStream  )  [inline]

This member function sets the value of the array from an input stream.

The array is modified only if the read was successful, otherwise the array is not modified, and failbit is set in the stream state. Because of this nice behavior, readFromStream is quite slow.

Parameters:
inputStream This is the stream from which to read the array.
Returns:
The return value is a reference to inputStream.

Definition at line 1177 of file array1D.h.

References dlr::numeric::Array1D< Type >::begin(), dlr::numeric::Array1D< Type >::copy(), and dlr::numeric::Array1D< Type >::reinit().

Referenced by dlr::numeric::operator>>().

template<class Type>
size_t* dlr::numeric::Array1D< Type >::refCountPtr (  )  const [inline]

Temporary function to ease porting of code from early versions of dlr_libs.

The use of this function is discouraged.

Returns:
The return value is a pointer to the internal reference count.

Definition at line 353 of file array1D.h.

template<class Type >
void dlr::numeric::Array1D< Type >::reinit ( size_t  arraySize  )  [inline]

Changes the shape of the array and reallocates storage.

The current array contents are lost.

Parameters:
size Number of elements in the array after reallocation.

Definition at line 1255 of file array1D.h.

Referenced by dlr::numeric::ArrayND< Dimension, Type >::clear(), dlr::numeric::Array1D< size_t >::clear(), dlr::numeric::Array1D< Type >::readFromStream(), dlr::numeric::Array1D< Type >::reinitIfNecessary(), dlr::numeric::BSpline< Type >::setKnotMultiplicities(), and dlr::numeric::BSpline< Type >::setNodePositions().

template<class Type >
void dlr::numeric::Array1D< Type >::reinitIfNecessary ( size_t  arraySize  )  [inline]

Behaves just like member function reinit() unless this->size() matches the requested size, in which case this member function does nothing.

Parameters:
size Required number of elements in the array.

Definition at line 1265 of file array1D.h.

References dlr::numeric::Array1D< Type >::reinit(), and dlr::numeric::Array1D< Type >::size().

template<class Type>
Type& dlr::numeric::Array1D< Type >::setElement ( size_t  index0,
const Type &  value 
) [inline]

This member function sets the value of a specific element of the array.

Parameters:
index0 This argument specifies which element value should be set.
value This argument will be copied into the selected array element.
Returns:
The return value is a reference to the newly set array element.

Definition at line 391 of file array1D.h.

template<class Type>
size_t dlr::numeric::Array1D< Type >::size (  )  const [inline]


The documentation for this class was generated from the following file:

Generated on Wed Nov 25 00:42:47 2009 for dlrUtilities Utility Library by  doxygen 1.5.8