|
PSCF v1.4.0
|
Dynamically allocatable contiguous array template. More...
#include <DArray.h>
Public Member Functions | |
| DArray () | |
| Default constructor. | |
| DArray (int capacity) | |
| Allocating constructor. | |
| DArray (DArray< Data > const &other) | |
| Copy constructor. | |
| virtual | ~DArray () |
| Destructor. | |
| DArray< Data > & | operator= (DArray< Data > const &other) |
| Assignment from a DArray<Data> container. | |
| DArray< Data > & | operator= (Array< Data > const &other) |
| Assignment from an Array<Data> container. | |
| void | allocate (int capacity) |
| Allocate the underlying C array. | |
| void | deallocate () |
| Deallocate the underlying C array. | |
| void | reallocate (int capacity) |
| Reallocate the underlying C array and copy to new location. | |
| bool | isAllocated () const |
| Return true if this DArray has been allocated, false otherwise. | |
| template<class Archive> | |
| void | serialize (Archive &ar, const unsigned int version) |
| Serialize a DArray to/from an Archive. | |
| Public Member Functions inherited from Util::Array< Data > | |
| int | capacity () const |
| Return allocated size. | |
| void | begin (ArrayIterator< Data > &iterator) |
| Set an iterator to begin this Array. | |
| void | begin (ConstArrayIterator< Data > &iterator) const |
| Set a const iterator to begin this Array. | |
| Data & | operator[] (int i) |
| Get an element by non-const reference. | |
| Data const & | operator[] (int i) const |
| Get an element by const reference. | |
| Data * | cArray () |
| Return a pointer to the underlying C array. | |
| Data const * | cArray () const |
| Return pointer to const to the underlying C array. | |
Additional Inherited Members | |
| Protected Member Functions inherited from Util::Array< Data > | |
| Array () | |
| Constructor (protected to provent direct instantiation). | |
| ~Array () | |
| Destructor (protected to prevent direct destruction). | |
| Protected Attributes inherited from Util::Array< Data > | |
| Data * | data_ |
| Pointer to an array of Data elements. | |
| int | capacity_ |
| Allocated size of the data_ array. | |
Dynamically allocatable contiguous array template.
A DArray wraps a dynamically allocated C Array, and stores the capacity 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 array index bound checking when compiled in debug mode.
| Util::DArray< Data >::DArray | ( | ) |
Default constructor.
Definition at line 160 of file DArray.h.
Referenced by Pscf::HostDArray< Data >::copySlice(), DArray(), Pscf::HostDArray< Data >::HostDArray(), Pscf::HostDArray< Data >::HostDArray(), Pscf::HostDArray< Data >::HostDArray(), Pscf::HostDArray< Data >::operator=(), operator=(), and operator=().
| Util::DArray< Data >::DArray | ( | int | capacity | ) |
Allocating constructor.
| capacity | number of elements to allocate |
Definition at line 168 of file DArray.h.
References allocate(), and Util::Array< Data >::capacity().
| 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 180 of file DArray.h.
References Util::Memory::allocate(), Util::Array< Data >::capacity_, DArray(), Util::Array< Data >::data_, and isAllocated().
|
virtual |
Destructor.
Deletes underlying C array, if allocated previously.
Definition at line 197 of file DArray.h.
References Util::Array< Data >::capacity_, Util::Array< Data >::data_, Util::Memory::deallocate(), and isAllocated().
| DArray< Data > & Util::DArray< Data >::operator= | ( | DArray< Data > const & | other | ) |
Assignment from a DArray<Data> container.
Copies all elements. The other DArrray must be allocated. If this DArray is not allocated on entry, it is allocated before elements are copied. If this and the other DArray are both allocated, the capacities must be 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 211 of file DArray.h.
References allocate(), Util::Array< Data >::capacity(), Util::Array< Data >::capacity_, DArray(), Util::Array< Data >::data_, isAllocated(), and UTIL_THROW.
| DArray< Data > & Util::DArray< Data >::operator= | ( | Array< Data > const & | other | ) |
Assignment from an Array<Data> container.
Performs a deep copy, by copying values of all elements of an Array<Data> container. If this (LHS) array is already allocated on entry, it must have the same capacity as the other (RHS) array. If this LHS array is not allocated on entry, required memory is allocated before copying values.
| Exception | if other array is not allocated |
| Exception | if arrays are allocated with unequal capacities |
| other | array container on RHS of assigment (input) |
Definition at line 243 of file DArray.h.
References allocate(), Util::Array< Data >::capacity(), Util::Array< Data >::capacity_, DArray(), Util::Array< Data >::data_, isAllocated(), and UTIL_CHECK.
| void Util::DArray< Data >::allocate | ( | int | capacity | ) |
Allocate the underlying C array.
| capacity | number of elements to allocate |
Definition at line 269 of file DArray.h.
References Util::Memory::allocate(), Util::Array< Data >::capacity(), Util::Array< Data >::capacity_, Util::Array< Data >::data_, isAllocated(), and UTIL_THROW.
Referenced by Pscf::Prdc::allocateArrays(), Pscf::Prdc::allocateFields(), Util::CardinalBSpline::CardinalBSpline(), Pscf::Rp::FieldIo< D, RFT, KFT, FFT >::checkAllocateBasis(), Pscf::Prdc::checkAllocateFields(), Pscf::Prdc::Cuda::CFieldComparison< D >::compare(), Pscf::Prdc::Cuda::CFieldComparison< D >::compare(), Pscf::Prdc::Cuda::RFieldComparison< D >::compare(), Pscf::Prdc::Cuda::RFieldDftComparison< D >::compare(), Pscf::Prdc::Cuda::RFieldDftComparison< D >::compare(), Pscf::Rpc::FilmFieldGenExt< D >::compute(), Pscf::Rpg::FilmFieldGenExt< D >::compute(), Pscf::Rp::FourthOrderParameter< D, T >::computePrefactor(), Pscf::Rpg::FieldIo< D >::convertBasisToKGrid(), Pscf::Rpg::FieldIo< D >::convertKGridToBasis(), DArray(), Util::Polynomial< T >::differentiate(), Pscf::Rp::FieldIo< D, RFT, KFT, FFT >::estimateWBasis(), Pscf::Rpg::FieldIo< D >::hasSymmetry(), Pscf::HostDArray< Data >::HostDArray(), Pscf::HostDArray< Data >::HostDArray(), Pscf::FhMixture::initialize(), Util::Polynomial< T >::integrate(), Pscf::PolymerSpecies< WT >::makePaths(), Pscf::HostDArray< Data >::operator=(), operator=(), operator=(), Pscf::Prdc::readBasisData(), Pscf::Prdc::readBasisData(), Pscf::Rp::FieldIo< D, RFT, KFT, FFT >::readFieldBasis(), Pscf::Rpg::FieldIo< D >::readFieldRGrid(), Pscf::Prdc::replicateUnitCell(), serialize(), Pscf::R1d::Block::setDiscretization(), Pscf::Rpg::WFields< D >::setRGrid(), Pscf::Correlation::Mixture< RealT >::setup(), Pscf::Rpg::FilmFieldGenExt< D >::stress(), Pscf::Prdc::writeBasisData(), Pscf::Rp::Mixture< D, T >::writeBlockCRGrid(), Pscf::Rp::FieldIo< D, RFT, KFT, FFT >::writeFieldBasis(), Pscf::Rpg::FieldIo< D >::writeFieldRGrid(), and Pscf::Rp::Mixture< D, Types< D > >::writeQTail().
| void Util::DArray< Data >::deallocate | ( | ) |
Deallocate the underlying C array.
Definition at line 285 of file DArray.h.
References Util::Array< Data >::capacity_, Util::Array< Data >::data_, Util::Memory::deallocate(), isAllocated(), and UTIL_THROW.
| void Util::DArray< Data >::reallocate | ( | int | capacity | ) |
Reallocate the underlying C array and copy to new location.
The array is reallocated and copied to a new location if the new capacity, given by the capacity parameter, is greater than the existing array capacity. Nothing is done if the new and old capacities are equal. An Exception is thrown if the new capacity is less than the old capacity.
| capacity | number of elements for which to allocate space |
Definition at line 298 of file DArray.h.
References Util::Memory::allocate(), Util::Array< Data >::capacity(), Util::Array< Data >::capacity_, Util::Array< Data >::data_, isAllocated(), Util::Memory::reallocate(), and UTIL_CHECK.
|
inline |
Return true if this DArray has been allocated, false otherwise.
Definition at line 151 of file DArray.h.
References Util::Array< Data >::data_.
Referenced by allocate(), Pscf::Prdc::allocateArrays(), Pscf::Prdc::allocateFields(), Pscf::Prdc::checkAllocateFields(), Pscf::Rpg::FieldIo< D >::convertBasisToKGrid(), Pscf::Rp::FieldIo< D, RFT, KFT, FFT >::convertBasisToRGrid(), Pscf::Rp::FieldIo< D, RFT, KFT, FFT >::convertBasisToRGrid(), Pscf::Rpg::FieldIo< D >::convertKGridToBasis(), Pscf::HostDArray< Data >::copySlice(), DArray(), deallocate(), Pscf::DeviceArray< Data >::DeviceArray(), Pscf::Prdc::inspectArrays(), Pscf::Prdc::inspectFields(), Pscf::DeviceArray< Data >::operator=(), Pscf::HostDArray< Data >::operator=(), Pscf::Prdc::Cuda::CField< D >::operator=(), Pscf::Prdc::Cuda::RField< D >::operator=(), Pscf::Prdc::Cuda::RFieldDft< D >::operator=(), operator=(), operator=(), Pscf::Prdc::readBasisData(), Pscf::Prdc::readBasisData(), Pscf::Rp::FieldIo< D, RFT, KFT, FFT >::readFieldBasis(), reallocate(), Pscf::Rp::FieldIo< D, RFT, KFT, FFT >::scaleFieldBasis(), serialize(), Pscf::Prdc::writeBasisData(), and ~DArray().
| 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 316 of file DArray.h.
References allocate(), Util::Array< Data >::capacity(), Util::Array< Data >::capacity_, Util::Array< Data >::data_, isAllocated(), and UTIL_THROW.