|
PSCF v1.5.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. | |
| 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 > | |
| Data & | operator[] (int i) |
| Get an element by non-const reference. | |
| Data const & | operator[] (int i) const |
| Get an element by const reference. | |
| 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 * | cArray () |
| Return a pointer to the underlying C array (non-const data). | |
| Data const * | cArray () const |
| Return pointer to the underlying C array (const data). | |
| bool | isAllocated () const |
| Does this array have associated data? | |
| int | size () const |
| Return logical size of array. | |
| int | capacity () const |
| Return allocated size. | |
Additional Inherited Members | |
| Protected Member Functions inherited from Util::Array< Data > | |
| Array () | |
| Constructor (protected to prevent 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, which it owns. A DArray can be allocated, deallocated or reallocated (i.e., resized and moved) by member functions.
The Array<Data> base class provides array index bound checking when compiled in debug mode.
| Util::DArray< Data >::DArray | ( | ) |
Default constructor.
Definition at line 148 of file DArray.h.
Referenced by DArray(), Pscf::HostSendArray< Data, CUT >::HostSendArray(), operator=(), and operator=().
| Util::DArray< Data >::DArray | ( | int | capacity | ) |
Allocating constructor.
| capacity | number of elements to allocate |
Definition at line 156 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 168 of file DArray.h.
References Util::Memory::allocate(), Util::Array< Data >::capacity_, DArray(), Util::Array< Data >::data_, and Util::Array< Data >::isAllocated().
|
virtual |
Destructor.
Deletes underlying C array, if allocated previously.
Definition at line 185 of file DArray.h.
References Util::Array< Data >::capacity_, Util::Array< Data >::data_, Util::Memory::deallocate(), and Util::Array< Data >::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 204 of file DArray.h.
References allocate(), Util::Array< Data >::capacity(), Util::Array< Data >::capacity_, DArray(), Util::Array< Data >::data_, Util::Array< Data >::isAllocated(), and UTIL_CHECK.
| 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 233 of file DArray.h.
References allocate(), Util::Array< Data >::capacity(), Util::Array< Data >::capacity_, DArray(), Util::Array< Data >::data_, Util::Array< 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 262 of file DArray.h.
References Util::Memory::allocate(), Util::Array< Data >::capacity(), Util::Array< Data >::capacity_, Util::Array< Data >::data_, Util::Array< Data >::isAllocated(), and UTIL_THROW.
Referenced by Pscf::allocateArrays(), Pscf::allocateFields(), Pscf::HostSendArray< Data, CUT >::associate(), Pscf::associateArrays(), Util::CardinalBSpline::CardinalBSpline(), Pscf::checkAllocateFields(), Pscf::R1::Sweep::checkAllocation(), Pscf::CFieldComparison< D, CUT >::compare(), Pscf::RFieldComparison< D, CUT >::compare(), Pscf::RFieldDftComparison< D, CUT >::compare(), Pscf::Rp::FilmFieldGenExt< D, CPT >::compute(), Pscf::Rp::FilmFieldGenExt< D, CUT >::compute(), Pscf::copyArrays(), DArray(), Util::Polynomial< T >::differentiate(), Util::Distribution::Distribution(), Pscf::Rp::FieldIo< D, T >::estimateWBasis(), Pscf::FhMixture::initialize(), Util::IntDistribution::IntDistribution(), Util::Polynomial< T >::integrate(), Pscf::PolymerSpecies< WT >::makePaths(), Pscf::HostSendArray< Data, CUT >::operator=(), operator=(), operator=(), Util::Distribution::operator=(), Util::IntDistribution::operator=(), Pscf::readBasisData(), Pscf::readBasisData(), Pscf::Rp::FieldIo< D, T >::readFieldBasis(), Util::Distribution::readParameters(), Util::IntDistribution::readParameters(), Util::RadialDistribution::readParameters(), Pscf::replicateUnitCell(), serialize(), Pscf::R1::Block::setDiscretization(), Util::Distribution::setParam(), Util::IntDistribution::setParam(), Util::RadialDistribution::setParam(), Pscf::Rp::WFields< D, T >::setRGrid(), Pscf::Rp::FilmFieldGenExt< D, CUT >::stress(), Pscf::writeBasisData(), Pscf::Rp::Mixture< D, T >::writeBlockCRGrid(), and Pscf::Rp::FieldIo< D, T >::writeFieldBasis().
| void Util::DArray< Data >::deallocate | ( | ) |
Deallocate the underlying C array.
Definition at line 278 of file DArray.h.
References Util::Array< Data >::capacity_, Util::Array< Data >::data_, Util::Memory::deallocate(), Util::Array< Data >::isAllocated(), and UTIL_THROW.
Referenced by Util::Distribution::operator=(), and Util::IntDistribution::operator=().
| 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 291 of file DArray.h.
References Util::Memory::allocate(), Util::Array< Data >::capacity(), Util::Array< Data >::capacity_, Util::Array< Data >::data_, Util::Array< Data >::isAllocated(), Util::Memory::reallocate(), and UTIL_CHECK.
| 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 309 of file DArray.h.
References allocate(), Util::Array< Data >::capacity(), Util::Array< Data >::capacity_, Util::Array< Data >::data_, Util::Array< Data >::isAllocated(), and UTIL_THROW.