1#ifndef UTIL_D_P_ARRAY_H
2#define UTIL_D_P_ARRAY_H
11#include <util/containers/PArray.h>
12#include <util/misc/Memory.h>
23 template <
typename Data>
100 template <
typename Data>
110 template <
typename Data>
122 for (
int i = 0; i < other.
size_; ++i) {
138 template <
typename Data>
143 if (
this == &other)
return *
this;
147 UTIL_THROW(
"LHS DPArray in assignment is not allocated");
149 if (other.
ptrs_ == 0) {
150 UTIL_THROW(
"RHS DPArray in assignment is not allocated");
152 if (capacity_ < other.
size_) {
158 for (i = 0; i < other.
size_; ++i) {
164 if (capacity_ > size_) {
165 for (i = size_; i < capacity_; ++i) {
176 template <
typename Data>
181 assert(capacity_ > 0);
182 Memory::deallocate<Data*>(ptrs_, capacity_);
190 template <
typename Data>
198 UTIL_THROW(
"Cannot allocate a DPArray with capacity <=0");
200 Memory::allocate<Data*>(ptrs_, capacity);
201 capacity_ = capacity;
207 template <
typename Data>
210 if (!isAllocated()) {
211 UTIL_THROW(
"Error: Attempt to append to unallocated DPArray");
213 if (size_ == capacity_) {
214 UTIL_THROW(
"Error: Attempt to append data to a full DPArray");
216 ptrs_[size_] = &data;
223 template <
typename Data>
226 assert(isAllocated());
233 template <
typename Data>
236 {
return (
bool)ptrs_; }
A dynamic array that only holds pointers to its elements.
bool isAllocated() const
Is this DPArray allocated?
virtual ~DPArray()
Destructor.
void allocate(int capacity)
Allocate an array of pointers to Data.
void clear()
Reset to empty state.
DPArray< Data > & operator=(DPArray< Data > const &other)
Assignment, element by element.
void append(Data &data)
Append an element to the end of the sequence.
An array that only holds pointers to its elements.
int capacity_
Allocated size of ptrs_ array.
int capacity() const
Return allocated size.
int size_
Logical size (number of elements with initialized data).
Data ** ptrs_
PArray of of pointers to Data objects.
File containing preprocessor macros for error handling.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
Utility classes for scientific computation.