11#include <util/containers/ArrayIterator.h>
12#include <util/containers/ConstArrayIterator.h>
13#include <util/misc/Memory.h>
29 template <
typename Data>
76 void append(Data
const & data);
103 template <
class Archive>
104 void serialize(Archive& ar,
const unsigned int version);
169 template <
class Data>
179 template <
class Data>
187 UTIL_THROW(
"Other DSArray must be allocated.");
193 for (
int i = 0; i <
size_; ++i) {
203 template <
class Data>
207 if (
this == &other)
return *
this;
211 UTIL_THROW(
"Other DSArray must be allocated.");
214 if (!isAllocated()) {
216 }
else if (capacity_ != other.
capacity_) {
217 UTIL_THROW(
"Cannot assign DSArrays of unequal capacity");
221 for (
int i = 0; i < other.
size_; ++i) {
232 template <
class Data>
238 Memory::deallocate<Data>(data_, capacity_);
246 template <
class Data>
253 UTIL_THROW(
"Cannot allocate a DSArray with capacity <= 0");
255 Memory::allocate<Data>(data_, capacity);
256 capacity_ = capacity;
263 template <
class Data>
264 template <
class Archive>
268 if (Archive::is_saving()) {
269 if (!isAllocated()) {
270 UTIL_THROW(
"Cannot save unallocated DSArray");
272 capacity = capacity_;
276 if (Archive::is_loading()) {
278 UTIL_THROW(
"Invalid DSArray input capacity on load, capacity <= 0");
281 UTIL_THROW(
"Invalid DSArray input size on load, size < 0");
283 if (!isAllocated()) {
286 if (size_ > capacity_) {
287 UTIL_THROW(
"Inconsistent DSArray size and capacity on load");
290 for (
int i = 0; i < size_; ++i) {
300 template <
class Data>
305 iterator.
setEnd(data_ + size_);
311 template <
class Data>
316 iterator.
setEnd(data_ + size_);
322 template <
class Data>
333 template <
class Data>
344 template <
class Data>
347 if (size_ == capacity_) {
364 template <
class Data>
371 template <
class Data>
378 template <
class Data>
380 {
return capacity_; }
385 template <
class Data>
392 template <
class Data>
394 {
return (
bool)data_; }
Forward iterator for an Array or a C array.
void setEnd(Data *ptr)
Set the value of the end pointer.
void setCurrent(Data *ptr)
Set the current pointer value.
Forward const iterator for an Array or a C array.
void setEnd(Data *ptr)
Set the value of the end pointer.
void setCurrent(Data *ptr)
Set the current pointer value.
Dynamically allocated array with variable logical size.
virtual ~DSArray()
Destructor.
void serialize(Archive &ar, const unsigned int version)
Serialize a DSArray to/from an Archive.
bool isAllocated() const
Return true if the DSArray has been allocated, false otherwise.
void begin(ArrayIterator< Data > &iterator)
Set an ArrayIterator to the beginning of this Array.
Data * data_
C array of Data elements.
void clear()
Set logical size to zero.
void resize(int size)
Modify logical size without modifying data.
Data & operator[](int i)
Mimic C array subscripting.
void append(Data const &data)
Append data to the end of the array.
int size() const
Return logical size of this array (i.e., number of elements).
int capacity() const
Return physical capacity of array.
DSArray< Data > & operator=(DSArray< Data > const &other)
Assignment, element by element.
int size_
Logical size of array (number of elements used).
void allocate(int capacity)
Allocates the underlying C array.
int capacity_
Capacity (physical size) of underlying C array.
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.