11#include <util/containers/Array.h>
12#include <util/misc/Memory.h>
30 template <
typename Data>
109 template <
class Archive>
110 void serialize(Archive& ar,
const unsigned int version);
123 template <
class Data>
135 template <
class Data>
140 UTIL_THROW(
"Other DArray must be allocated.");
152 template <
class Data>
156 Memory::deallocate<Data>(data_, capacity_);
166 template <
class Data>
170 if (
this == &other)
return *
this;
174 UTIL_THROW(
"Other DArray must be allocated.");
177 if (!isAllocated()) {
179 }
else if (capacity_ != other.
capacity_) {
180 UTIL_THROW(
"Cannot assign DArrays of unequal capacity");
184 for (
int i = 0; i < capacity_; ++i) {
198 template <
class Data>
202 UTIL_THROW(
"Attempt to re-allocate a DArray");
205 UTIL_THROW(
"Attempt to allocate with capacity <= 0");
207 Memory::allocate<Data>(data_, capacity);
208 capacity_ = capacity;
216 template <
class Data>
219 if (!isAllocated()) {
222 Memory::deallocate<Data>(data_, capacity_);
229 template <
class Data>
233 if (capacity == capacity_)
return;
236 Memory::reallocate<Data>(data_, capacity_, capacity);
238 Memory::allocate<Data>(data_, capacity);
240 capacity_ = capacity;
246 template <
class Data>
248 {
return (
bool)data_; }
253 template <
class Data>
254 template <
class Archive>
258 if (Archive::is_saving()) {
259 capacity = capacity_;
262 if (Archive::is_loading()) {
263 if (!isAllocated()) {
268 if (capacity != capacity_) {
274 for (
int i = 0; i < capacity_; ++i) {
Array container class template.
Data * data_
Pointer to an array of Data elements.
int capacity() const
Return allocated size.
int capacity_
Allocated size of the data_ array.
Dynamically allocatable contiguous array template.
DArray(DArray< Data > const &other)
Copy constructor.
void allocate(int capacity)
Allocate the underlying C array.
void deallocate()
Dellocate the underlying C array.
void serialize(Archive &ar, const unsigned int version)
Serialize a DArray to/from an Archive.
DArray()
Default constructor.
bool isAllocated() const
Return true if this DArray has been allocated, false otherwise.
virtual ~DArray()
Destructor.
void reallocate(int capacity)
Reallocate the underlying C array and copy to new location.
DArray< Data > & operator=(DArray< Data > const &other)
Assignment operator.
static void allocate(Data *&ptr, size_t size)
Allocate a C++ array.
File containing preprocessor macros for error handling.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
Utility classes for scientific computation.