PSCF v1.1
Public Member Functions | List of all members
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::Field< double > Pscf::Field< fftw_complex > Pscf::Field< T > Pscf::Pspc::RField< D > Pscf::Pspc::RFieldDft< D >

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...
 
- Public Member Functions inherited from Util::Array< Data >
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

- Protected Member Functions inherited from Util::Array< Data >
 Array ()
 Default constructor. More...
 
- Protected Attributes inherited from Util::Array< Data >
Data * data_
 Pointer to an array of Data elements. More...
 
int capacity_
 Allocated size of the data_ array. More...
 

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

Definition at line 31 of file DArray.h.

Constructor & Destructor Documentation

◆ DArray() [1/2]

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

Default constructor.

Definition at line 124 of file DArray.h.

◆ DArray() [2/2]

template<class 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 136 of file DArray.h.

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

◆ ~DArray()

template<class Data >
Util::DArray< Data >::~DArray
virtual

Destructor.

Deletes underlying C array, if allocated previously.

Definition at line 153 of file DArray.h.

Member Function Documentation

◆ operator=()

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

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

◆ allocate()

template<class 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 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().

◆ deallocate()

template<class Data >
void Util::DArray< Data >::deallocate

Dellocate the underlying C array.

Exceptions
Exceptionif the DArray is not allocated

Definition at line 217 of file DArray.h.

References UTIL_THROW.

Referenced by Pscf::Pspg::FieldIo< D >::convertBasisToRGrid(), and Pscf::Pspg::FieldIo< D >::convertRGridToBasis().

◆ reallocate()

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

Parameters
capacity

Definition at line 230 of file DArray.h.

References UTIL_CHECK.

◆ isAllocated()

template<class Data >
bool Util::DArray< Data >::isAllocated
inline

◆ serialize()

template<class 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 255 of file DArray.h.

References UTIL_THROW.


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