PSCF v1.4.0
Util::DArray< Data > Class Template Reference

Dynamically allocatable contiguous array template. More...

#include <DArray.h>

Inheritance diagram for Util::DArray< Data >:
Util::Array< Data > Pscf::HostDArray< cudaComplex > Pscf::HostDArray< T > Pscf::HostDArray< Data > Pscf::Prdc::Cuda::HostDArrayComplex

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.

Detailed Description

template<typename Data>
class Util::DArray< Data >

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.

Definition at line 31 of file DArray.h.

Constructor & Destructor Documentation

◆ DArray() [1/3]

◆ DArray() [2/3]

template<typename Data>
Util::DArray< Data >::DArray ( int capacity)

Allocating constructor.

Parameters
capacitynumber of elements to allocate

Definition at line 168 of file DArray.h.

References allocate(), and Util::Array< Data >::capacity().

◆ DArray() [3/3]

template<typename Data>
Util::DArray< Data >::DArray ( DArray< Data > const & other)

Copy constructor.

Allocates new memory and copies all elements by value.

Parameters
otherthe 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().

◆ ~DArray()

template<typename Data>
Util::DArray< Data >::~DArray ( )
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().

Member Function Documentation

◆ operator=() [1/2]

template<typename Data>
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.

Exceptions
Exceptionif other DArray is not allocated
Exceptionif DArrays are allocated with unequal capacities
Parameters
otherthe 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.

◆ operator=() [2/2]

template<typename Data>
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.

Exceptions
Exceptionif other array is not allocated
Exceptionif arrays are allocated with unequal capacities
Parameters
otherarray 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.

◆ allocate()

template<typename Data>
void Util::DArray< Data >::allocate ( int capacity)

Allocate the underlying C array.

Exceptions
Exceptionif the DArray is already allocated
Parameters
capacitynumber 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().

◆ deallocate()

template<typename Data>
void Util::DArray< Data >::deallocate ( )

Deallocate the underlying C array.

Exceptions
Exceptionif the DArray is not allocated

Definition at line 285 of file DArray.h.

References Util::Array< Data >::capacity_, Util::Array< Data >::data_, Util::Memory::deallocate(), isAllocated(), and UTIL_THROW.

◆ reallocate()

template<typename Data>
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.

Parameters
capacitynumber 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.

◆ isAllocated()

◆ serialize()

template<typename Data>
template<class Archive>
void Util::DArray< Data >::serialize ( Archive & ar,
const unsigned int version )

Serialize a DArray to/from an Archive.

Parameters
ararchive
versionarchive 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.


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