PSCF v1.5.0
FftwDRArray.h
1#ifndef PSCF_FFTW_DR_ARRAY_H
2#define PSCF_FFTW_DR_ARRAY_H
3
4/*
5* Util Package - C++ Utilities for Scientific Computation
6*
7* Copyright 2010 - 2017, David Morse (morse012@um.edu) and co-authors
8* Distributed under the terms of the GNU General Public License.
9*/
10
11#include <util/containers/Array.h> // base class
12#include <util/misc/ReferenceCounter.h> // base class
13#include <util/misc/CountedReference.h> // member
14#include <util/global.h>
15
16//#include <fftw3.h>
17
18namespace Pscf {
19
20 using namespace Util;
21
70 template <typename Data>
71 class FftwDRArray : public Array<Data>, public ReferenceCounter
72 {
73
74 public:
75
79 using ValueType = Data;
80
85
94
100 FftwDRArray(FftwDRArray<Data> const & other);
101
111 virtual ~FftwDRArray();
112
129
145 FftwDRArray<Data>& operator = (Array<Data> const & other);
146
159 void allocate(int capacity);
160
169 virtual void deallocate();
170
186 void associate(FftwDRArray<Data>& other, int beginId, int capacity);
187
205 void associate(FftwDRArray<Data>& other);
206
215 void dissociate();
216
228 template <class Archive>
229 void serialize(Archive& ar, const unsigned int version);
230
238 bool isOwner() const;
239
245 bool isAssociated() const;
246
247 /*
248 * A FftwDRArray is considered allocated if it has non-null pointer
249 * to a C array, which may either be an array that it owns or a
250 * slice of an array that is owned by another FftwDRArray object.
251 */
252 using Array<Data>::isAllocated;
253
254 protected:
255
256 using Array<Data>::data_;
257 using Array<Data>::capacity_;
258
259 private:
260
262 CountedReference ref_;
263
264 // Prohibit public access to the reference counter.
267
268 // Note: ReferenceCounter::nRef_ is declared mutable, so changes
269 // to this variable should not be visible in the public interface.
270
271 };
272
273 // Inline member function definitions
274
275 /*
276 * Does this object own data?
277 */
278 template <typename Data> inline
280 { return ((bool) data_ && !ref_.isAssociated()); }
281
282 /*
283 * Does this object reference data that it does not own?
284 */
285 template <typename Data> inline
287 { return ((bool) data_ && ref_.isAssociated()); }
288
289 /*
290 * Serialize a FftwDRArray to/from an Archive.
291 */
292 template <typename Data>
293 template <class Archive>
295 const unsigned int version)
296 {
297 int capacity;
298 if (Archive::is_saving()) {
300 if (capacity > 0) {
302 }
303 }
304 ar & capacity;
305 if (Archive::is_loading()) {
306 if (!isAllocated()) {
307 if (capacity > 0) {
309 }
310 } else {
313 }
314 }
316 if (capacity > 0) {
318 for (int i = 0; i < capacity_; ++i) {
319 ar & data_[i];
320 }
321 }
322 }
323
324} // namespace Pscf
325#include "FftwDRArray.tpp"
326#endif
virtual void deallocate()
Dellocate an underlying C array that is owned by this container.
FftwDRArray< Data > & operator=(FftwDRArray< Data > const &other)
Assignment from another FftwDRArray<Data> container.
void dissociate()
Dissociate this object from an externally owned array slice.
Data ValueType
Data type of each array element.
Definition FftwDRArray.h:79
bool isAssociated() const
Is this container associated with a C array it does not own?
FftwDRArray()
Default constructor.
void associate(FftwDRArray< Data > &other, int beginId, int capacity)
Associate this object with a slice of a different FftwDRArray.
void serialize(Archive &ar, const unsigned int version)
Serialize an FftwDRArray to/from an Archive.
void allocate(int capacity)
Allocate an underlying C array, which this container then owns.
bool isOwner() const
Does this container own a dynamically allocated C array?
Data * data_
Pointer to an array of Data elements.
Definition Array.h:141
int capacity() const
Return allocated size.
Definition Array.h:250
bool isAllocated() const
Does this array have associated data?
Definition Array.h:236
int capacity_
Allocated size of the data_ array.
Definition Array.h:144
bool hasRefs() const
Does this counter have references (is nRef > 0)?
int nRef() const
Get the number of references to a shareable resource.
File containing preprocessor macros for error handling.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
Definition global.h:68
PSCF package top-level namespace.