#include <array1D.h>
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. |
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.
typedef const Type* dlr::numeric::Array1D< Type >::const_iterator |
typedef Type* dlr::numeric::Array1D< Type >::iterator |
typedef Type dlr::numeric::Array1D< Type >::value_type |
dlr::numeric::Array1D< Type >::Array1D | ( | ) | [inline] |
dlr::numeric::Array1D< Type >::Array1D | ( | size_t | arraySize | ) | [inline, explicit] |
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.
inputString | A formatted string which could be reasonably expected to parse into the desired array values. |
dlr::numeric::Array1D< Type >::Array1D | ( | const Array1D< Type > & | source | ) | [inline] |
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.
arraySize | Number of elements in the array after construction. | |
dataPtr | A C-style array of Type into which the newly constructed Array1D should index. |
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.
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. |
dlr::numeric::Array1D< Type >::~Array1D | ( | ) | [inline] |
const_iterator dlr::numeric::Array1D< Type >::begin | ( | ) | const [inline] |
iterator dlr::numeric::Array1D< Type >::begin | ( | ) | [inline] |
Return begin() iterator for Standard Library algorithms.
Definition at line 157 of file array1D.h.
Referenced by dlr::numeric::convolve(), dlr::numeric::convolve1D(), dlr::numeric::ArrayND< Dimension, Type >::flattenIndex(), dlr::numeric::BSpline< Type >::getSpanNumber(), dlr::numeric::operator*(), dlr::numeric::operator+(), dlr::numeric::operator-(), dlr::numeric::operator/(), dlr::numeric::operator==(), dlr::numeric::operator>(), dlr::numeric::operator>=(), dlr::numeric::Array1D< Type >::readFromStream(), dlr::numeric::BSpline< Type >::setKnotMultiplicities(), and dlr::numeric::BSpline< Type >::setNodePositions().
void dlr::numeric::Array1D< Type >::checkDimension | ( | size_t | arraySize | ) | const [inline] |
Optionally throw an exception if the shape of *this is different than specified.
arraySize | The required array size. |
Definition at line 1112 of file array1D.h.
References dlr::numeric::Array1D< Type >::size().
Referenced by dlr::numeric::operator==().
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().
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());
dataPtr | Pointer to the data to be copied. |
Definition at line 1157 of file array1D.h.
References dlr::numeric::Array1D< Type >::copy().
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.
source | The array to be copied. |
ValueException | on incompatible array sizes |
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().
Array1D< Type > dlr::numeric::Array1D< Type >::copy | ( | ) | const [inline] |
Allocate a new array and deep copy the contents of *this.
Definition at line 1128 of file array1D.h.
References dlr::numeric::Array1D< Type >::copy().
Referenced by dlr::numeric::ArrayND< Dimension, Type >::ArrayND(), dlr::numeric::BSpline2D< Type >::BSpline2D(), dlr::numeric::convolve(), dlr::numeric::Array1D< Type >::copy(), dlr::numeric::BSpline< Type >::getCoefficientMatrices(), dlr::numeric::BSpline< Type >::operator=(), dlr::numeric::ArrayND< Dimension, Type >::operator=(), dlr::numeric::Array1D< Type >::readFromStream(), and dlr::numeric::ArrayND< Dimension, Type >::reinit().
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.
index | Indicates to which element of the array the return value should point. |
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" .
index | Indicates to which element of the array the return value should point. |
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.
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.
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/=().
bool dlr::numeric::Array1D< Type >::empty | ( | ) | const [inline] |
const_iterator dlr::numeric::Array1D< Type >::end | ( | ) | const [inline] |
iterator dlr::numeric::Array1D< Type >::end | ( | ) | [inline] |
Return end() iterator for Standard Library algorithms.
Definition at line 285 of file array1D.h.
Referenced by dlr::numeric::convolve(), dlr::numeric::convolve1D(), dlr::numeric::ArrayND< Dimension, Type >::flattenIndex(), dlr::numeric::BSpline< Type >::getSpanNumber(), dlr::numeric::operator*(), dlr::numeric::operator+(), dlr::numeric::operator-(), dlr::numeric::operator/(), dlr::numeric::operator==(), dlr::numeric::operator>(), and dlr::numeric::operator>=().
Type dlr::numeric::Array1D< Type >::getElement | ( | size_t | index0 | ) | const [inline] |
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.
size_t dlr::numeric::Array1D< Type >::length | ( | ) | const [inline] |
Type dlr::numeric::Array1D< Type >::operator() | ( | size_t | index | ) | const [inline] |
Type& dlr::numeric::Array1D< Type >::operator() | ( | size_t | index | ) | [inline] |
Returns the (index)th element of the array by reference.
index | Indicates the selected element. |
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().
Array1D< Type > & dlr::numeric::Array1D< Type >::operator*= | ( | const Type | arg | ) | [inline] |
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.
arg | Array1D of values by which the elements of *this should be multiplied. |
ValueException | on incompatible array sizes |
Definition at line 1356 of file array1D.h.
References dlr::numeric::Array1D< Type >::data(), and dlr::numeric::Array1D< Type >::size().
Array1D< Type > & dlr::numeric::Array1D< Type >::operator+= | ( | const Type | arg | ) | [inline] |
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.
arg | Array1D of values to be added to the elements of *this. |
ValueException | on incompatible array sizes |
Definition at line 1296 of file array1D.h.
References dlr::numeric::Array1D< Type >::data(), and dlr::numeric::Array1D< Type >::size().
Array1D< Type > & dlr::numeric::Array1D< Type >::operator-= | ( | const Type | arg | ) | [inline] |
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.
arg | Array1D of values to be subtracted from the elements of *this. |
ValueException | on incompatible array sizes |
Definition at line 1326 of file array1D.h.
References dlr::numeric::Array1D< Type >::data(), and dlr::numeric::Array1D< Type >::size().
Array1D< Type > & dlr::numeric::Array1D< Type >::operator/= | ( | const Type | arg | ) | [inline] |
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.
arg | Array1D of values by which the elements of *this should be divided. |
ValueException | on incompatible array sizes |
Definition at line 1386 of file array1D.h.
References dlr::numeric::Array1D< Type >::data(), and dlr::numeric::Array1D< Type >::size().
Array1D< Type > & dlr::numeric::Array1D< Type >::operator= | ( | Type | value | ) | [inline] |
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.
source | The Array1D instance to be copied. |
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.
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.
index | Indicates the selected element. |
Type& dlr::numeric::Array1D< Type >::operator[] | ( | size_t | index | ) | [inline] |
Returns the (index)th element of the array by reference.
Synonymous with operator()().
index | Indicates the selected element. |
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.
inputStream | This is the stream from which to read the array. |
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>>().
size_t* dlr::numeric::Array1D< Type >::refCountPtr | ( | ) | const [inline] |
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.
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().
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.
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().
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.
index0 | This argument specifies which element value should be set. | |
value | This argument will be copied into the selected array element. |
size_t dlr::numeric::Array1D< Type >::size | ( | ) | const [inline] |
Returns the number of elements in the array.
This is a synonym for length().
Definition at line 403 of file array1D.h.
Referenced by dlr::numeric::BSpline2D< Type >::BSpline2D(), dlr::numeric::ArrayND< Dimension, Type >::checkDimension(), dlr::numeric::Array1D< Type >::checkDimension(), dlr::numeric::BSpline< Type >::computeBasisFunction(), dlr::numeric::convolve(), dlr::numeric::convolve1D(), dlr::numeric::Array1D< Type >::copy(), dlr::numeric::correlate1D(), dlr::numeric::Array1D< size_t >::empty(), dlr::numeric::BSpline< Type >::getControlPointVectors(), dlr::numeric::BSpline< Type >::getKnotPosition(), dlr::numeric::BSpline< Type >::getMaximumSValue(), dlr::numeric::BSpline< Type >::getMinimumSValue(), dlr::numeric::Array1D< size_t >::length(), dlr::numeric::BSpline< Type >::operator()(), dlr::numeric::operator*(), dlr::numeric::Array1D< Type >::operator*=(), dlr::numeric::operator+(), dlr::numeric::Array1D< Type >::operator+=(), dlr::numeric::operator-(), dlr::numeric::Array1D< Type >::operator-=(), dlr::numeric::operator/(), dlr::numeric::Array1D< Type >::operator/=(), dlr::numeric::operator==(), dlr::numeric::operator>(), dlr::numeric::operator>=(), dlr::numeric::Array1D< Type >::reinitIfNecessary(), dlr::numeric::BSpline< Type >::setControlPoints(), dlr::numeric::BSpline< Type >::setKnotMultiplicities(), dlr::numeric::BSpline< Type >::setNodePositions(), and dlr::numeric::SubArray1D< Type >::SubArray1D().