DUDS
Distributed Update of Data from Something
duds::general::NddArray< T > Class Template Reference

N-Dimensional Dynamic Array. More...

#include <NddArray.hpp>

Collaboration diagram for duds::general::NddArray< T >:

Public Types

typedef const T * const_iterator
 Simple const iterator. More...
 
typedef std::initializer_list< SizeTypeDimList
 A type that can specify the dimensions of the array, or a position of an element. More...
 
typedef std::vector< SizeTypeDimVec
 The type used to store the dimensions of the array. More...
 
typedef T * iterator
 Simple iterator. More...
 
typedef std::size_t SizeType
 The type used to store dimension lengths and the total number of elements. More...
 

Public Member Functions

 NddArray ()
 Makes an empty array. More...
 
 NddArray (const DimList &dims)
 Makes an array of the given size. More...
 
 NddArray (const DimVec &dims)
 Makes an array of the given size. More...
 
template<class Dim >
 NddArray (const Dim &dims)
 Makes an array of the given size. More...
 
 NddArray (const NddArray &ndda)
 Copy constructor; uses the assignment operator of T. More...
 
 NddArray (NddArray &&ndda) noexcept
 Move constructor; the elements are not copied. More...
 
 ~NddArray () noexcept
 Destructor; destroys the elements of the array. More...
 
template<class Dim >
T & at (const Dim &pos)
 Obtain an element from the array stored at a specific position. More...
 
T & at (const DimList &pos)
 Obtain an element from the array stored at a specific position. More...
 
template<class Dim >
const T & at (const Dim &pos) const
 Obtain an element from the array stored at a specific position. More...
 
const T & at (const DimList &pos) const
 Obtain an element from the array stored at a specific position. More...
 
T & back ()
 The last element of the array. More...
 
const T & back () const
 The last element of the array. More...
 
T * begin ()
 An iterator (really just a pointer) to the first element of the array. More...
 
const T * begin () const
 An iterator (really just a pointer) to the first element of the array. More...
 
const T * cbegin () const
 An iterator (really just a pointer) to the first element of the array. More...
 
const T * cend () const
 An iterator (really just a pointer) to one past the last element of the array. More...
 
void clear () noexcept
 Destroys the contents of the array. More...
 
template<class AV >
void copyFrom (const AV &av)
 Copies from a one dimensional container into this array. More...
 
template<std::size_t N>
void copyFrom (const std::array< T, N > &a)
 Copies from a std::array into this array. More...
 
void copyFrom (const std::vector< T > &v)
 Copies from a std::vector into this array. More...
 
template<std::size_t N>
void copyFrom (const T(&a)[N])
 Copies from a one dimensional array type into this array object. More...
 
template<std::size_t X, std::size_t Y>
void copyFrom (const T(&a)[X][Y])
 Copies from a two dimensional array type into this array object. More...
 
template<std::size_t N>
void copyTo (std::array< T, N > &a) const
 Copies the contents of this object into a std::array. More...
 
void copyTo (std::vector< T > &v) const
 Copies the contents of this object into a std::vector. More...
 
template<std::size_t N>
void copyTo (T(&a)[N]) const
 Copies the contents of this object into a one dimensional array. More...
 
template<std::size_t X, std::size_t Y>
void copyTo (T(&a)[X][Y]) const
 Copies the contents of this object into a two dimensional array. More...
 
SizeType dim (SizeType n) const
 Returns the size of dimension n. More...
 
const DimVecdim () const
 Provides access to the vector containing the array dimensions. More...
 
bool empty () const
 True if the array has zero dimensions. More...
 
T * end ()
 An iterator (really just a pointer) to one past the last element of the array. More...
 
const T * end () const
 An iterator (really just a pointer) to one past the last element of the array. More...
 
T & front ()
 The first element of the array. More...
 
const T & front () const
 The first element of the array. More...
 
template<class Dim >
NddArray makeWithNewSize (const Dim &dims) const
 Makes a new array with a new size and copies elements who's position is within bounds of the new array's dimensions. More...
 
NddArray makeWithNewSize (const DimList &dims) const
 Makes a new array with a new size and copies elements who's position is within bounds of the new array's dimensions. More...
 
SizeType numdims () const
 Returns the number of dimensions in the array. More...
 
SizeType numelems () const
 Returns the total number of elements within the array. More...
 
bool operator!= (const NddArray &ndda) const
 Inequality operator; uses the inequality operator of T. More...
 
template<class Dim >
T & operator() (const Dim &pos)
 Obtain an element from the array stored at a specific position. More...
 
T & operator() (const DimList &pos)
 Obtain an element from the array stored at a specific position. More...
 
template<class Dim >
const T & operator() (const Dim &pos) const
 Obtain an element from the array stored at a specific position. More...
 
const T & operator() (const DimList &pos) const
 Obtain an element from the array stored at a specific position. More...
 
NddArrayoperator= (const NddArray &ndda)
 Copy assignment; uses the assignment operator of T. More...
 
NddArrayoperator= (NddArray &&ndda) noexcept
 Move assignment; the elements are not copied. More...
 
template<std::size_t N>
NddArrayoperator= (const std::array< T, N > &a)
 Copies from a std::array into this array. More...
 
NddArrayoperator= (const std::vector< T > &v)
 Copies from a std::vector into this array. More...
 
template<std::size_t N>
NddArrayoperator= (const T(&a)[N])
 Copies from a one dimensional array type into this array object. More...
 
template<std::size_t X, std::size_t Y>
NddArrayoperator= (const T(&a)[X][Y])
 Copies from a two dimensional array type into this array object. More...
 
bool operator== (const NddArray &ndda) const
 Equality operator; uses the equality operator of T. More...
 
void remake (const DimList &dims)
 Clears the array and allocates a new one of the given dimensions. More...
 
void remake (const DimVec &dims)
 Clears the array and allocates a new one of the given dimensions. More...
 
template<class Dim >
void resize (const Dim &dims)
 Resizes the array and keeps elements who's position is within bounds of the new dimensions. More...
 
void resize (const DimList &dims)
 Resizes the array and keeps elements who's position is within bounds of the new dimensions. More...
 
SizeType size () const
 Returns the number of elements stored in the array. More...
 
void swap (NddArray &other)
 Swaps array contents. More...
 

Private Member Functions

 BOOST_SERIALIZATION_SPLIT_MEMBER ()
 
void copyElements (const NddArray &src)
 Alloactes space for and copies the elements of the array. More...
 
template<class Dim >
const T & indexArray (const Dim &pos) const
 Finds the location in array that holds the element for the given n-dimensional array position and returns the element. More...
 
template<class A >
void load (A &a, const unsigned int)
 Boost serialization support. More...
 
void makeArray ()
 Computes the new total number of elements and allocates space for the elements. More...
 
template<class A >
void save (A &a, const unsigned int) const
 Boost serialization support. More...
 

Private Attributes

T * array
 The array's element storage. More...
 
DimVec dsize
 The lengths of each dimension within the array. More...
 
SizeType elems
 Total number of elements; pre-calculated to speed up some operations. More...
 

Friends

class boost::serialization::access
 

Detailed Description

template<class T>
class duds::general::NddArray< T >

N-Dimensional Dynamic Array.

A dynamically allocated array with a dynamic number of dimensions. Storage internally is a std::vector for the dimensions, and a one dimensional array for elements. Indexing into the array is expensive compared with arrays of statically declared dimensions, but it allows for generalized data storage when the dimensions, including the number of dimensions, are only known at run-time.

Unlike std::vector, resizing is always expensive. No extra space is ever allocated.

To specifiy positions or new dimensions, std::initializer_list and std::vector may be used. The std::initializer_list is efficent for literal and temporary values, and std::vector works well when less is known about the dimensions at compile-time.

Support is provided for Boost serialization with name-value pairs.

One day there will be better iterators.

Todo:
The functions begin() and end() allow for iterating over the elements already using a pointer as the iterator. Would be nice to have an iterator that provides position-value pairs, too, so the array position of the element can be easily queried.
Template Parameters
TThe element type to store. It must have a default constructor. Some operations require the assignment, equality, or inequality operators, but those operators are only required if used. Boost serialization support is required if the array is serialized.
Author
Jeff Jackowski

Definition at line 87 of file NddArray.hpp.

Member Typedef Documentation

◆ const_iterator

template<class T>
typedef const T* duds::general::NddArray< T >::const_iterator

Simple const iterator.

Definition at line 109 of file NddArray.hpp.

◆ DimList

template<class T>
typedef std::initializer_list<SizeType> duds::general::NddArray< T >::DimList

A type that can specify the dimensions of the array, or a position of an element.

Definition at line 101 of file NddArray.hpp.

◆ DimVec

template<class T>
typedef std::vector<SizeType> duds::general::NddArray< T >::DimVec

The type used to store the dimensions of the array.

Definition at line 96 of file NddArray.hpp.

◆ iterator

template<class T>
typedef T* duds::general::NddArray< T >::iterator

Simple iterator.

Definition at line 105 of file NddArray.hpp.

◆ SizeType

template<class T>
typedef std::size_t duds::general::NddArray< T >::SizeType

The type used to store dimension lengths and the total number of elements.

Definition at line 92 of file NddArray.hpp.

Constructor & Destructor Documentation

◆ NddArray() [1/6]

template<class T>
duds::general::NddArray< T >::NddArray ( )
inline

Makes an empty array.

It must be given a new size, by calling remake() or resize(), before it can be used for storage.

Definition at line 235 of file NddArray.hpp.

◆ NddArray() [2/6]

template<class T>
duds::general::NddArray< T >::NddArray ( const DimList dims)
inline

Makes an array of the given size.

Parameters
dimsThe initial dimensions.

Definition at line 240 of file NddArray.hpp.

◆ NddArray() [3/6]

template<class T>
duds::general::NddArray< T >::NddArray ( const DimVec dims)
inline

Makes an array of the given size.

Parameters
dimsThe initial dimensions.

Definition at line 249 of file NddArray.hpp.

◆ NddArray() [4/6]

template<class T>
template<class Dim >
duds::general::NddArray< T >::NddArray ( const Dim &  dims)
inline

Makes an array of the given size.

Template Parameters
DimThe type holding the dimensions. It must have forward iterators.
Parameters
dimsThe initial dimensions.

Definition at line 261 of file NddArray.hpp.

◆ NddArray() [5/6]

template<class T>
duds::general::NddArray< T >::NddArray ( const NddArray< T > &  ndda)
inline

Copy constructor; uses the assignment operator of T.

Parameters
nddaThe array to copy.
Exceptions
exceptionAn exception thrown from the copy assignment operator of T. The array is cleared before rethorwing.

Definition at line 272 of file NddArray.hpp.

◆ NddArray() [6/6]

template<class T>
duds::general::NddArray< T >::NddArray ( NddArray< T > &&  ndda)
inlinenoexcept

Move constructor; the elements are not copied.

Parameters
nddaThe array to move.
Postcondition
The source array, ndda, will be empty. The constructed array will have the previous contents of ndda.
All iterators from ndda will continue to work with this object.

Definition at line 284 of file NddArray.hpp.

◆ ~NddArray()

template<class T>
duds::general::NddArray< T >::~NddArray ( )
inlinenoexcept

Destructor; destroys the elements of the array.

Definition at line 293 of file NddArray.hpp.

Member Function Documentation

◆ at() [1/4]

template<class T>
template<class Dim >
T& duds::general::NddArray< T >::at ( const Dim &  pos)
inline

Obtain an element from the array stored at a specific position.

Template Parameters
DimThe type holding the position. It must have forward iterators.
Parameters
posThe position. It's number of elements must match the number of dimensions of this array.
Returns
The element at the position.
Exceptions
ZeroSizeErrorThis object is empty and has no dimensions.
DimensionMismatchErrorThe number of items in pos does not match the number of dimensions in this object.
OutOfRangeErrorA position is beyond the range of the array.

Definition at line 679 of file NddArray.hpp.

Referenced by duds::data::QuantityNddArray::get(), duds::general::NddArray< double >::makeWithNewSize(), and duds::data::QuantityNddArray::set().

◆ at() [2/4]

template<class T>
T& duds::general::NddArray< T >::at ( const DimList pos)
inline

Obtain an element from the array stored at a specific position.

Parameters
posThe position. It's number of elements must match the number of dimensions of this array.
Returns
The element at the position.
Exceptions
ZeroSizeErrorThis object is empty and has no dimensions.
DimensionMismatchErrorThe number of items in pos does not match the number of dimensions in this object.
OutOfRangeErrorA position is beyond the range of the array.

Definition at line 694 of file NddArray.hpp.

◆ at() [3/4]

template<class T>
template<class Dim >
const T& duds::general::NddArray< T >::at ( const Dim &  pos) const
inline

Obtain an element from the array stored at a specific position.

Template Parameters
DimThe type holding the position. It must have forward iterators.
Parameters
posThe position. It's number of elements must match the number of dimensions of this array.
Returns
The element at the position.
Exceptions
ZeroSizeErrorThis object is empty and has no dimensions.
DimensionMismatchErrorThe number of items in pos does not match the number of dimensions in this object.
OutOfRangeErrorA position is beyond the range of the array.

Definition at line 712 of file NddArray.hpp.

◆ at() [4/4]

template<class T>
const T& duds::general::NddArray< T >::at ( const DimList pos) const
inline

Obtain an element from the array stored at a specific position.

Parameters
posThe position. It's number of elements must match the number of dimensions of this array.
Returns
The element at the position.
Exceptions
ZeroSizeErrorThis object is empty and has no dimensions.
DimensionMismatchErrorThe number of items in pos does not match the number of dimensions in this object.
OutOfRangeErrorA position is beyond the range of the array.

Definition at line 725 of file NddArray.hpp.

◆ back() [1/2]

template<class T>
T& duds::general::NddArray< T >::back ( )
inline

The last element of the array.

Its position is the maximum value for all dimensions.

Returns
The last element.
Exceptions
ZeroSizeErrorThis object is empty; there is no last element.

Definition at line 756 of file NddArray.hpp.

◆ back() [2/2]

template<class T>
const T& duds::general::NddArray< T >::back ( ) const
inline

The last element of the array.

Its position is the maximum value for all dimensions.

Returns
The last element.
Exceptions
ZeroSizeErrorThis object is empty; there is no last element.

Definition at line 768 of file NddArray.hpp.

◆ begin() [1/2]

template<class T>
T* duds::general::NddArray< T >::begin ( )
inline

An iterator (really just a pointer) to the first element of the array.

If the array is empty, the pointer will be null. There is nothing in place to prevent misuse of the iterator since it is really a pointer.

The iterator is valid until the array is resized. If the array is swapped with another, the iterator will function on the same dataset; it will follow the swap.

Definition at line 783 of file NddArray.hpp.

Referenced by duds::data::QuantityNddArray::begin().

◆ begin() [2/2]

template<class T>
const T* duds::general::NddArray< T >::begin ( ) const
inline

An iterator (really just a pointer) to the first element of the array.

If the array is empty, the pointer will be null. There is nothing in place to prevent misuse of the iterator since it is really a pointer.

The iterator is valid until the array is resized. If the array is swapped with another, the iterator will function on the same dataset; it will follow the swap.

Definition at line 795 of file NddArray.hpp.

◆ BOOST_SERIALIZATION_SPLIT_MEMBER()

template<class T>
duds::general::NddArray< T >::BOOST_SERIALIZATION_SPLIT_MEMBER ( )
private

◆ cbegin()

template<class T>
const T* duds::general::NddArray< T >::cbegin ( ) const
inline

An iterator (really just a pointer) to the first element of the array.

If the array is empty, the pointer will be null. There is nothing in place to prevent misuse of the iterator since it is really a pointer.

The iterator is valid until the array is resized. If the array is swapped with another, the iterator will function on the same dataset; it will follow the swap.

Definition at line 807 of file NddArray.hpp.

Referenced by duds::data::QuantityNddArray::cbegin().

◆ cend()

template<class T>
const T* duds::general::NddArray< T >::cend ( ) const
inline

An iterator (really just a pointer) to one past the last element of the array.

If the array is empty, the pointer will be null. There is nothing in place to prevent misuse of the iterator since it is really a pointer.

The iterator is valid until the array is resized. If the array is swapped with another, the iterator will function on the same dataset; it will follow the swap.

Definition at line 846 of file NddArray.hpp.

Referenced by duds::data::QuantityNddArray::cend().

◆ clear()

template<class T>
void duds::general::NddArray< T >::clear ( )
inlinenoexcept

Destroys the contents of the array.

Postcondition
The elements are destructed. The internal array is deallocated. The array is empty; it has zero dimensions.
All iterators on this object are invalid and must no longer be used.

Definition at line 934 of file NddArray.hpp.

Referenced by duds::data::QuantityNddArray::clear().

◆ copyElements()

template<class T>
void duds::general::NddArray< T >::copyElements ( const NddArray< T > &  src)
inlineprivate

Alloactes space for and copies the elements of the array.

Used in the copy constructor and assignment operator.

Precondition
dsize and elems have already been copied. array does not point to allocated memory and may be uninitialized.
Postcondition
array is allocated with copied elements, or is NULL if there are no elements. If an element failed to copy, the array will be cleared.
Parameters
srcThe source array for the copy.
Exceptions
exceptionAn exception thrown from the copy assignment operator of T. The array is cleared before rethorwing.

Definition at line 164 of file NddArray.hpp.

◆ copyFrom() [1/5]

template<class T>
template<class AV >
void duds::general::NddArray< T >::copyFrom ( const AV &  av)
inline

Copies from a one dimensional container into this array.

Each element is copied using the assignment operator.

Postcondition
The dimensions of this array will match the source.
All iterators on this object are invalid and must no longer be used.
Template Parameters
AVA one dimensional container type with forward iterators.
Parameters
avThe source container.

Definition at line 340 of file NddArray.hpp.

Referenced by duds::data::QuantityNddArray::operator=().

◆ copyFrom() [2/5]

template<class T>
template<std::size_t N>
void duds::general::NddArray< T >::copyFrom ( const std::array< T, N > &  a)
inline

Copies from a std::array into this array.

Each element is copied using the assignment operator.

Postcondition
The dimensions of this array will match the source.
All iterators on this object are invalid and must no longer be used.
Template Parameters
NThe length of the array.
Parameters
aThe source array.

Definition at line 363 of file NddArray.hpp.

◆ copyFrom() [3/5]

template<class T>
void duds::general::NddArray< T >::copyFrom ( const std::vector< T > &  v)
inline

Copies from a std::vector into this array.

Each element is copied using the assignment operator.

Postcondition
The dimensions of this array will match the source.
All iterators on this object are invalid and must no longer be used.
Parameters
vThe source vector.

Definition at line 377 of file NddArray.hpp.

◆ copyFrom() [4/5]

template<class T>
template<std::size_t N>
void duds::general::NddArray< T >::copyFrom ( const T(&)  a[N])
inline

Copies from a one dimensional array type into this array object.

Each element is copied using the assignment operator.

Postcondition
The dimensions of this array will match the source.
All iterators on this object are invalid and must no longer be used.
Template Parameters
NThe length of the array.
Parameters
aThe source array.

Definition at line 393 of file NddArray.hpp.

◆ copyFrom() [5/5]

template<class T>
template<std::size_t X, std::size_t Y>
void duds::general::NddArray< T >::copyFrom ( const T(&)  a[X][Y])
inline

Copies from a two dimensional array type into this array object.

Each element is copied using the assignment operator.

Postcondition
The dimensions of this array will match the source.
All iterators on this object are invalid and must no longer be used.
Template Parameters
XThe length of the source array's first dimension.
YThe length of the source array's second dimension.
Parameters
aThe source array.

Definition at line 417 of file NddArray.hpp.

◆ copyTo() [1/4]

template<class T>
template<std::size_t N>
void duds::general::NddArray< T >::copyTo ( std::array< T, N > &  a) const
inline

Copies the contents of this object into a std::array.

Each element is copied using the assignment operator.

Precondition
This object must have a single dimension.
Postcondition
The number of copied elements is the smaller of the length of this array and the length of the destination, N. Elements in the destination array that are not copied over are also not modified.
Template Parameters
NThe size of the array.
Parameters
aThe destination array.
Exceptions
DimensionMismatchErrorThis array does not have exactly one dimension.

Definition at line 510 of file NddArray.hpp.

Referenced by duds::data::QuantityArray< 3 >::operator=().

◆ copyTo() [2/4]

template<class T>
void duds::general::NddArray< T >::copyTo ( std::vector< T > &  v) const
inline

Copies the contents of this object into a std::vector.

Each element is copied using the assignment operator.

Precondition
This object must have a single dimension.
Postcondition
The destination's size will match this array's size.
Parameters
vThe destination vector.
Exceptions
DimensionMismatchErrorThis array does not have exactly one dimension.

Definition at line 532 of file NddArray.hpp.

◆ copyTo() [3/4]

template<class T>
template<std::size_t N>
void duds::general::NddArray< T >::copyTo ( T(&)  a[N]) const
inline

Copies the contents of this object into a one dimensional array.

Each element is copied using the assignment operator.

Precondition
This object must have a single dimension.
Postcondition
The number of copied elements is the smaller of the length of this array and the length of the destination, N. Elements in the destination array that are not copied over are also not modified.
Template Parameters
NThe size of the array.
Parameters
aThe destination array.
Exceptions
DimensionMismatchErrorThis array does not have exactly one dimension.

Definition at line 560 of file NddArray.hpp.

◆ copyTo() [4/4]

template<class T>
template<std::size_t X, std::size_t Y>
void duds::general::NddArray< T >::copyTo ( T(&)  a[X][Y]) const
inline

Copies the contents of this object into a two dimensional array.

Each element is copied using the assignment operator.

Precondition
This object must have exactly two dimensions.
Postcondition
The copied area is the intersection of the source and destination arrays. Elements in the destination array that are not copied over are also not modified.
Template Parameters
XThe length of the destination array's first dimension.
YThe length of the destination array's second dimension.
Parameters
aThe destination array.
Exceptions
DimensionMismatchErrorThis array does not have exactly two dimensions.

Definition at line 587 of file NddArray.hpp.

◆ dim() [1/2]

template<class T>
SizeType duds::general::NddArray< T >::dim ( SizeType  n) const
inline

Returns the size of dimension n.

Parameters
nThe number of the dimension to inspect. Zero is the first dimension.
Exceptions
OutOfRangeErrorThe array has fewer than n dimensions.

Definition at line 901 of file NddArray.hpp.

◆ dim() [2/2]

template<class T>
const DimVec& duds::general::NddArray< T >::dim ( ) const
inline

Provides access to the vector containing the array dimensions.

Definition at line 910 of file NddArray.hpp.

◆ empty()

template<class T>
bool duds::general::NddArray< T >::empty ( ) const
inline

True if the array has zero dimensions.

Definition at line 923 of file NddArray.hpp.

Referenced by duds::data::QuantityNddArray::empty().

◆ end() [1/2]

template<class T>
T* duds::general::NddArray< T >::end ( )
inline

An iterator (really just a pointer) to one past the last element of the array.

If the array is empty, the pointer will be null. There is nothing in place to prevent misuse of the iterator since it is really a pointer.

The iterator is valid until the array is resized. If the array is swapped with another, the iterator will function on the same dataset; it will follow the swap.

Definition at line 820 of file NddArray.hpp.

Referenced by duds::data::QuantityNddArray::end().

◆ end() [2/2]

template<class T>
const T* duds::general::NddArray< T >::end ( ) const
inline

An iterator (really just a pointer) to one past the last element of the array.

If the array is empty, the pointer will be null. There is nothing in place to prevent misuse of the iterator since it is really a pointer.

The iterator is valid until the array is resized. If the array is swapped with another, the iterator will function on the same dataset; it will follow the swap.

Definition at line 833 of file NddArray.hpp.

◆ front() [1/2]

template<class T>
T& duds::general::NddArray< T >::front ( )
inline

The first element of the array.

Its position is zero for all dimensions.

Returns
The first element.
Exceptions
ZeroSizeErrorThis object is empty; there is no first element.

Definition at line 733 of file NddArray.hpp.

◆ front() [2/2]

template<class T>
const T& duds::general::NddArray< T >::front ( ) const
inline

The first element of the array.

Its position is zero for all dimensions.

Returns
The first element.
Exceptions
ZeroSizeErrorThis object is empty; there is no first element.

Definition at line 744 of file NddArray.hpp.

◆ indexArray()

template<class T>
template<class Dim >
const T& duds::general::NddArray< T >::indexArray ( const Dim &  pos) const
inlineprivate

Finds the location in array that holds the element for the given n-dimensional array position and returns the element.

Template Parameters
DimThe type holding the position. It must have forward iterators.
Parameters
posThe position. It's number of elements must match the number of dimensions of this array.
Returns
The element at the position.
Exceptions
ZeroSizeErrorThis object is empty and has no dimensions.
DimensionMismatchErrorThe number of items in pos does not match the number of dimensions in this object.
OutOfRangeErrorA position is beyond the range of the array.

Definition at line 202 of file NddArray.hpp.

◆ load()

template<class T>
template<class A >
void duds::general::NddArray< T >::load ( A &  a,
const unsigned  int 
)
inlineprivate

Boost serialization support.

Definition at line 1180 of file NddArray.hpp.

◆ makeArray()

template<class T>
void duds::general::NddArray< T >::makeArray ( )
inlineprivate

Computes the new total number of elements and allocates space for the elements.

Precondition
dsize is not empty and is filled with the new dimensions. array does not point to alloacted memory and may be uninitialized.
Postcondition
array and elems are set. The default constructor of T has been called for each element.
Exceptions
EmptyDimensionErrorOne of the elements in dims is zero. The array is changed to the empty state before throwing.
Todo:
Handle overflow of elems.

Definition at line 136 of file NddArray.hpp.

◆ makeWithNewSize() [1/2]

template<class T>
template<class Dim >
NddArray duds::general::NddArray< T >::makeWithNewSize ( const Dim &  dims) const
inline

Makes a new array with a new size and copies elements who's position is within bounds of the new array's dimensions.

The operation uses the copy assignment operator of T to place the existing elements. On failure, the new array is destroyed.

The cases of no dimensions (empty) for the existing array, and none for the new array, are handled as special cases so they can complete faster.

Parameters
dimsThe new dimensions.
Exceptions
EmptyDimensionErrorOne of the elements in dims is zero.
exceptionAn exception thrown from the copy assignment operator of T.

Definition at line 999 of file NddArray.hpp.

◆ makeWithNewSize() [2/2]

template<class T>
NddArray duds::general::NddArray< T >::makeWithNewSize ( const DimList dims) const
inline

Makes a new array with a new size and copies elements who's position is within bounds of the new array's dimensions.

The operation uses the copy assignment operator of T to place the existing elements. On failure, the new array is destroyed.

The cases of no dimensions (empty) for the existing array, and none for the new array, are handled as special cases so they can complete faster.

Parameters
dimsThe new dimensions.
Exceptions
EmptyDimensionErrorOne of the elements in dims is zero.
exceptionAn exception thrown from the copy assignment operator of T.

Definition at line 1086 of file NddArray.hpp.

◆ numdims()

template<class T>
SizeType duds::general::NddArray< T >::numdims ( ) const
inline

Returns the number of dimensions in the array.

Definition at line 892 of file NddArray.hpp.

Referenced by duds::general::NddArray< double >::makeWithNewSize().

◆ numelems()

template<class T>
SizeType duds::general::NddArray< T >::numelems ( ) const
inline

Returns the total number of elements within the array.

The value is already computed, so the result is quickly obtained.

Definition at line 917 of file NddArray.hpp.

◆ operator!=()

template<class T>
bool duds::general::NddArray< T >::operator!= ( const NddArray< T > &  ndda) const
inline

Inequality operator; uses the inequality operator of T.

Elements are only inspected if the array dimensions are the same.

Parameters
nddaThe array to compare.

Definition at line 874 of file NddArray.hpp.

◆ operator()() [1/4]

template<class T>
template<class Dim >
T& duds::general::NddArray< T >::operator() ( const Dim &  pos)
inline

Obtain an element from the array stored at a specific position.

Template Parameters
DimThe type holding the position. It must have forward iterators.
Parameters
posThe position. It's number of elements must match the number of dimensions of this array.
Returns
The element at the position.
Exceptions
ZeroSizeErrorThis object is empty and has no dimensions.
DimensionMismatchErrorThe number of items in pos does not match the number of dimensions in this object.
OutOfRangeErrorA position is beyond the range of the array.

Definition at line 617 of file NddArray.hpp.

◆ operator()() [2/4]

template<class T>
T& duds::general::NddArray< T >::operator() ( const DimList pos)
inline

Obtain an element from the array stored at a specific position.

Parameters
posThe position. It's number of elements must match the number of dimensions of this array.
Returns
The element at the position.
Exceptions
ZeroSizeErrorThis object is empty and has no dimensions.
DimensionMismatchErrorThe number of items in pos does not match the number of dimensions in this object.
OutOfRangeErrorA position is beyond the range of the array.

Definition at line 632 of file NddArray.hpp.

◆ operator()() [3/4]

template<class T>
template<class Dim >
const T& duds::general::NddArray< T >::operator() ( const Dim &  pos) const
inline

Obtain an element from the array stored at a specific position.

Template Parameters
DimThe type holding the position. It must have forward iterators.
Parameters
posThe position. It's number of elements must match the number of dimensions of this array.
Returns
The element at the position.
Exceptions
ZeroSizeErrorThis object is empty and has no dimensions.
DimensionMismatchErrorThe number of items in pos does not match the number of dimensions in this object.
OutOfRangeErrorA position is beyond the range of the array.

Definition at line 650 of file NddArray.hpp.

◆ operator()() [4/4]

template<class T>
const T& duds::general::NddArray< T >::operator() ( const DimList pos) const
inline

Obtain an element from the array stored at a specific position.

Parameters
posThe position. It's number of elements must match the number of dimensions of this array.
Returns
The element at the position.
Exceptions
ZeroSizeErrorThis object is empty and has no dimensions.
DimensionMismatchErrorThe number of items in pos does not match the number of dimensions in this object.
OutOfRangeErrorA position is beyond the range of the array.

Definition at line 663 of file NddArray.hpp.

◆ operator=() [1/6]

template<class T>
NddArray& duds::general::NddArray< T >::operator= ( const NddArray< T > &  ndda)
inline

Copy assignment; uses the assignment operator of T.

Postcondition
All iterators on this object are invalid and must no longer be used.
Parameters
nddaThe array to copy.
Exceptions
exceptionAn exception thrown from the copy assignment operator of T. The array is cleared before rethorwing.

Definition at line 304 of file NddArray.hpp.

◆ operator=() [2/6]

template<class T>
NddArray& duds::general::NddArray< T >::operator= ( NddArray< T > &&  ndda)
inlinenoexcept

Move assignment; the elements are not copied.

Postcondition
All iterators on this object are invalid and must no longer be used. All iterators from ndda will continue to work with this object.
Parameters
nddaThe array to copy.

Definition at line 318 of file NddArray.hpp.

◆ operator=() [3/6]

template<class T>
template<std::size_t N>
NddArray& duds::general::NddArray< T >::operator= ( const std::array< T, N > &  a)
inline

Copies from a std::array into this array.

Each element is copied using the assignment operator.

Postcondition
The dimensions of this array will match the source.
All iterators on this object are invalid and must no longer be used.
Template Parameters
NThe length of the array.
Parameters
aThe source array.

Definition at line 442 of file NddArray.hpp.

◆ operator=() [4/6]

template<class T>
NddArray& duds::general::NddArray< T >::operator= ( const std::vector< T > &  v)
inline

Copies from a std::vector into this array.

Each element is copied using the assignment operator.

Postcondition
The dimensions of this array will match the source.
All iterators on this object are invalid and must no longer be used.
Parameters
vThe source vector.

Definition at line 457 of file NddArray.hpp.

◆ operator=() [5/6]

template<class T>
template<std::size_t N>
NddArray& duds::general::NddArray< T >::operator= ( const T(&)  a[N])
inline

Copies from a one dimensional array type into this array object.

Each element is copied using the assignment operator.

Postcondition
The dimensions of this array will match the source.
All iterators on this object are invalid and must no longer be used.
Template Parameters
NThe length of the array.
Parameters
aThe source array.

Definition at line 474 of file NddArray.hpp.

◆ operator=() [6/6]

template<class T>
template<std::size_t X, std::size_t Y>
NddArray& duds::general::NddArray< T >::operator= ( const T(&)  a[X][Y])
inline

Copies from a two dimensional array type into this array object.

Each element is copied using the assignment operator.

Postcondition
The dimensions of this array will match the source.
All iterators on this object are invalid and must no longer be used.
Template Parameters
XThe length of the array's first dimension.
YThe length of the array's second dimension.
Parameters
aThe source array.

Definition at line 492 of file NddArray.hpp.

◆ operator==()

template<class T>
bool duds::general::NddArray< T >::operator== ( const NddArray< T > &  ndda) const
inline

Equality operator; uses the equality operator of T.

Elements are only inspected if the array dimensions are the same.

Parameters
nddaThe array to compare.

Definition at line 854 of file NddArray.hpp.

◆ remake() [1/2]

template<class T>
void duds::general::NddArray< T >::remake ( const DimList dims)
inline

Clears the array and allocates a new one of the given dimensions.

Postcondition
All iterators on this object are invalid and must no longer be used.
Parameters
dimsThe new dimensions for the array. If it has no elements, the array will have zero dimensions.
Exceptions
EmptyDimensionErrorOne of the elements in dims is zero.

Definition at line 948 of file NddArray.hpp.

◆ remake() [2/2]

template<class T>
void duds::general::NddArray< T >::remake ( const DimVec dims)
inline

Clears the array and allocates a new one of the given dimensions.

Postcondition
All iterators on this object are invalid and must no longer be used.
Parameters
dimsThe new dimensions for the array. If it is empty, the array will have zero dimensions.
Exceptions
EmptyDimensionErrorOne of the elements in dims is zero.

Definition at line 970 of file NddArray.hpp.

◆ resize() [1/2]

template<class T>
template<class Dim >
void duds::general::NddArray< T >::resize ( const Dim &  dims)
inline

Resizes the array and keeps elements who's position is within bounds of the new dimensions.

The operation creates a new array of the new dimensions and uses the copy assignment operator of T to place the existing elements. On failure, the array does not change.

No dimensions for the new or current size are handled as special cases so they can complete faster.

Postcondition
All iterators on this object are invalid and must no longer be used.
Parameters
dimsThe new dimensions.
Exceptions
EmptyDimensionErrorOne of the elements in dims is zero. The array will be unchanged.
exceptionAn exception thrown from the copy assignment operator of T. The array will be unchanged.
Todo:
Make another version (noexcept?) of this function that uses the move assignment operator. Failures will recover slower, but successes could be much faster.

Definition at line 1111 of file NddArray.hpp.

◆ resize() [2/2]

template<class T>
void duds::general::NddArray< T >::resize ( const DimList dims)
inline

Resizes the array and keeps elements who's position is within bounds of the new dimensions.

The operation creates a new array of the new dimensions and uses the copy assignment operator of T to place the existing elements. On failure, the array does not change.

No dimensions for the new or current size are handled as special cases so they can complete faster.

Postcondition
All iterators on this object are invalid and must no longer be used.
Parameters
dimsThe new dimensions.
Exceptions
EmptyDimensionErrorOne of the elements in dims is zero. The array will be unchanged.
exceptionAn exception thrown from the copy assignment operator of T. The array will be unchanged.
Todo:
Make another version (noexcept?) of this function that uses the move assignment operator. Failures will recover slower, but successes could be much faster.

Definition at line 1135 of file NddArray.hpp.

◆ save()

template<class T>
template<class A >
void duds::general::NddArray< T >::save ( A &  a,
const unsigned  int 
) const
inlineprivate

Boost serialization support.

Definition at line 1164 of file NddArray.hpp.

◆ size()

template<class T>
SizeType duds::general::NddArray< T >::size ( ) const
inline

Returns the number of elements stored in the array.

Definition at line 1141 of file NddArray.hpp.

◆ swap()

template<class T>
void duds::general::NddArray< T >::swap ( NddArray< T > &  other)
inline

Swaps array contents.

The elements are not copied; it should be fairly quick.

Postcondition
Iterators working on this object will continue to work on other.
Parameters
otherThe other array involved in the swap.

Definition at line 1151 of file NddArray.hpp.

Referenced by duds::general::swap().

Friends And Related Function Documentation

◆ boost::serialization::access

template<class T>
friend class boost::serialization::access
friend

Definition at line 1155 of file NddArray.hpp.

Member Data Documentation

◆ array

◆ dsize

◆ elems

template<class T>
SizeType duds::general::NddArray< T >::elems
private

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