PSCF v1.1
|
Dynamically allocatable contiguous array template. More...
#include <DArray.h>
Public Member Functions | |
DArray () | |
Default constructor. More... | |
DArray (DArray< Data > const &other) | |
Copy constructor. More... | |
virtual | ~DArray () |
Destructor. More... | |
DArray< Data > & | operator= (DArray< Data > const &other) |
Assignment operator. More... | |
void | allocate (int capacity) |
Allocate the underlying C array. More... | |
void | deallocate () |
Dellocate the underlying C array. More... | |
void | reallocate (int capacity) |
Reallocate the underlying C array and copy to new location. More... | |
bool | isAllocated () const |
Return true if this DArray has been allocated, false otherwise. More... | |
template<class Archive > | |
void | serialize (Archive &ar, const unsigned int version) |
Serialize a DArray to/from an Archive. More... | |
![]() | |
virtual | ~Array () |
Destructor. More... | |
int | capacity () const |
Return allocated size. More... | |
void | begin (ArrayIterator< Data > &iterator) |
Set an iterator to begin this Array. More... | |
void | begin (ConstArrayIterator< Data > &iterator) const |
Set a const iterator to begin this Array. More... | |
Data & | operator[] (int i) |
Get an element by non-const reference. More... | |
Data const & | operator[] (int i) const |
Get an element by const reference. More... | |
Data * | cArray () |
Return a pointer to the underlying C array. More... | |
Data const * | cArray () const |
Return pointer to const to the underlying C array. More... | |
Additional Inherited Members | |
![]() | |
Array () | |
Default constructor. More... | |
![]() | |
Data * | data_ |
Pointer to an array of Data elements. More... | |
int | capacity_ |
Allocated size of the data_ array. More... | |
Dynamically allocatable contiguous array template.
A DArray wraps a dynamically allocated C Array, and stores the size of the array. A DArray can be allocated, deallocated or reallocated (i.e., resized and moved) by member functions.j
The Array<Data> base class provides bounds checking when compiled in debug mode.
Util::DArray< Data >::DArray |
Util::DArray< Data >::DArray | ( | DArray< Data > const & | other | ) |
Copy constructor.
Allocates new memory and copies all elements by value.
other | the DArray to be copied |
Definition at line 136 of file DArray.h.
References Util::Memory::allocate(), Util::Array< Data >::capacity_, Util::Array< Data >::data_, Util::DArray< Data >::isAllocated(), and UTIL_THROW.
|
virtual |
DArray< Data > & Util::DArray< Data >::operator= | ( | DArray< Data > const & | other | ) |
Assignment operator.
Copies all elements. The other DArrray must be allocated. If this DArray is not allocated, the function allocates it before copying all elements. If this and the other DArray are both allocated, the capacities must be exactly equal on entry.
Exception | if other DArray is not allocated |
Exception | if DArrays are allocated with unequal capacities |
other | the other (RHS) DArray |
Definition at line 167 of file DArray.h.
References Util::Array< Data >::capacity(), Util::Array< Data >::capacity_, Util::DArray< Data >::isAllocated(), and UTIL_THROW.
void Util::DArray< Data >::allocate | ( | int | capacity | ) |
Allocate the underlying C array.
capacity | number of elements to allocate |
Definition at line 199 of file DArray.h.
References UTIL_THROW.
Referenced by Pscf::TridiagonalSolver::allocate(), Util::CardinalBSpline::CardinalBSpline(), Pscf::Fd1d::Sweep::checkAllocation(), Pscf::Pspg::KFieldComparison< D >::compare(), Pscf::Pspg::RFieldComparison< D >::compare(), Pscf::Fd1d::HomogeneousComparison::compute(), Pscf::Fd1d::System::computeFreeEnergy(), Pscf::Homogeneous::Mixture::computePhi(), Pscf::Pspg::FieldIo< D >::convertBasisToRGrid(), Pscf::Pspg::FieldIo< D >::convertRGridToBasis(), Util::Polynomial< T >::differentiate(), Util::Distribution::Distribution(), Pscf::Pspc::System< D >::estimateWfromC(), Pscf::Pspg::System< D >::estimateWfromC(), Pscf::Pspc::FilmIteratorBase< D, IteratorType >::generateExternalFields(), Pscf::Fd1d::Domain::innerProduct(), Util::IntDistribution::IntDistribution(), Util::Polynomial< T >::integrate(), Util::Distribution::operator=(), Util::IntDistribution::operator=(), Pscf::Pspc::FieldIo< D >::readFieldBasis(), Pscf::Pspc::FieldIo< D >::readFieldsBasis(), Pscf::Pspg::FieldIo< D >::readFieldsBasis(), Pscf::Pspg::FieldIo< D >::readFieldsKGrid(), Pscf::Pspg::FieldIo< D >::readFieldsRGrid(), Pscf::Pspc::FieldIo< D >::readFieldsRGrid(), Pscf::Homogeneous::Mixture::readParameters(), Util::Distribution::readParameters(), Util::IntDistribution::readParameters(), Util::RadialDistribution::readParameters(), Pscf::Fd1d::Solvent::setDiscretization(), Pscf::Fd1d::Block::setDiscretization(), Pscf::Homogeneous::Mixture::setNMolecule(), Pscf::Homogeneous::Mixture::setNMonomer(), Util::RadialDistribution::setParam(), Util::Distribution::setParam(), Util::IntDistribution::setParam(), Pscf::Pspc::System< D >::writeBlockCRGrid(), Pscf::Pspg::System< D >::writeBlockCRGrid(), Pscf::Pspc::FieldIo< D >::writeFieldBasis(), Pscf::Pspg::FieldIo< D >::writeFieldsKGrid(), Pscf::Pspg::FieldIo< D >::writeFieldsRGrid(), and Pscf::Pspc::FieldIo< D >::writeFieldsRGrid().
void Util::DArray< Data >::deallocate |
Dellocate the underlying C array.
Definition at line 217 of file DArray.h.
References UTIL_THROW.
Referenced by Pscf::Pspg::FieldIo< D >::convertBasisToRGrid(), and Pscf::Pspg::FieldIo< D >::convertRGridToBasis().
void Util::DArray< Data >::reallocate | ( | int | capacity | ) |
Reallocate the underlying C array and copy to new location.
The new capacity, given by the capacity parameter, must be greater than the existing array capacity.
capacity |
Definition at line 230 of file DArray.h.
References UTIL_CHECK.
|
inline |
Return true if this DArray has been allocated, false otherwise.
Definition at line 247 of file DArray.h.
Referenced by Util::bcast(), Pscf::Fd1d::Sweep::checkAllocation(), Pscf::Fd1d::HomogeneousComparison::compute(), Pscf::Fd1d::Solvent::compute(), Pscf::Fd1d::System::computeFreeEnergy(), Util::DArray< Data >::DArray(), Pscf::Field< T >::Field(), Pscf::Fd1d::Domain::innerProduct(), Pscf::Field< T >::operator*=(), Pscf::Field< T >::operator+=(), Pscf::Field< T >::operator-=(), Pscf::Pspc::RField< D >::operator=(), Util::DArray< Data >::operator=(), Pscf::Field< T >::operator=(), Pscf::Pspc::RFieldDft< D >::operator=(), Pscf::Pspc::FieldIo< D >::readFieldBasis(), Pscf::Pspc::FieldIo< D >::readFieldRGrid(), Util::recv(), Pscf::Pspc::RField< D >::RField(), Pscf::Pspc::RFieldDft< D >::RFieldDft(), Util::send(), and Pscf::Pspc::Block< D >::step().
void Util::DArray< Data >::serialize | ( | Archive & | ar, |
const unsigned int | version | ||
) |
Serialize a DArray to/from an Archive.
ar | archive |
version | archive version id |
Definition at line 255 of file DArray.h.
References UTIL_THROW.